solution
stringlengths
52
181k
difficulty
int64
0
6
#include<bits/stdc++.h> #define For(a,b,c) for(int a=b;a<=c;++a) #define Dor(a,b,c) for(int a=b;a>=c;--a) #define CC(_...) fprintf(stderr,_) using namespace std; typedef long long LL; enum{N=307,E=607,P=998244353}; int n,k,hd[N],nt[E],to[E],F[N][N],G[N][N],tF[N][N],tG[N][N],sF[N][N],sG[N][N],H[N]; void fly(int u,int f=...
6
#include <bits/stdc++.h> const long long MaxN = 205; const long long lim = 1e18 + 5; template <class t> inline void read(t &s) { s = 0; register long long f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) s = (s << 3) + (s << 1) + (c ...
3
#include <iostream> using namespace std; int main(){ int N; cin >>N; cout << (double)((N+1)/2)/N; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 0, n, i, k, p, q; { cin >> n >> k; while (n--) { long long int arr[7] = {0}; cin >> p >> q; arr[p]++; arr[q]++; arr[7 - p]++; arr[7 - q]++; ...
1
#include <iostream> #include <vector> using namespace std; int N; bool Find; vector<int> res,sign; void dfs(int ind) { if (Find) { return; } if (ind == N-1) { if ((res[0] == res[ind]*sign[ind]*res[ind-1]) && (res[1] == res[0]*sign[0]*res[ind])) { for (int i = 0; i < N; ++i) { if (res[i] > 0) { cou...
0
#include <bits/stdc++.h> using namespace std; long long n, m, t, a[25][25], b[25], c[1 << 22]; char s[200005]; long long sum[1 << 22]; inline void go(int x1, int y1010101010101, int x2, int v) { sum[x1] += v; sum[y1010101010101] -= v; sum[x2] -= v; sum[y1010101010101 & x2] += v; } bool used[25]; int to = 0; set...
3
#include <bits/stdc++.h> using namespace std; int main(){ int n; scanf("%d", &n); vector<int> a(n); for(int i = 0; i < n; i++) a[i] = i + 1; do { for(int i = 0; i < n - 1; i++) printf("%d ", a[i]); printf("%d\n", a[n-1]); } while(next_permutation(a.begin(), a.end())); }
0
#include <bits/stdc++.h> long long dx[4] = {0, -1, 0, 1}; long long dy[4] = {1, 0, -1, 0}; using namespace std; class pa3 { public: long long x, y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p...
5
#include <bits/stdc++.h> const int d4x[4] = {-1, 0, 1, 0}, d4y[4] = {0, 1, 0, -1}; const int d8x[8] = {-1, -1, -1, 0, 1, 1, 1, 0}, d8y[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; using namespace std; int main() { int n; string s{}; cin >> n >> s; vector<int> v{}; for (int i{}; i < n; i++) { int a; cin...
1
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int MOD = 1e9 + 7; int n; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; cin >> n; int dp[] = {1, 0}; for (int i = 1; i < n; i++) dp[i % 2] = (dp[i % 2] + dp[1 - i % 2] + 1) % MOD; cout << (dp[0] + dp[1]...
1
#include <bits/stdc++.h> using namespace std; int main() { cout << "YES\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nY" "ES\nNO\nYES\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nNO" "\nYES\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES" "\n...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { int n, m; cin >> n >> m; int p[n]; for (int i = 0; i <= n - 1; i++) cin >> p[i]; set<int> st[n + 1]; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; st[a].insert(b); } set<int> s; vector<bool> fla...
4
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } int p[2][100001]; int get(int i, int l, int r) { if (r < 0) return 0; l = max(l, 0); return add(p[i][r], mod - (l == 0 ? 0 : p[i][l - 1])); } void solution() { int n...
5
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int INF=1e9; int ans=INF; int n; int a[20][2],p[20],t[20],b[20][2]; void jud(int s){ for(int i=0;i<n;++i){ if(s&(1<<i)) p[i]=1; else p[i]=0; t[i]=a[i][p[i]]; b[i][0]=a[i][0]; b[i][1]=a[i][1]; } sort(t,t+n);...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n, n) { vector<int> p(n); for (auto& i : p) cin >> i; sort(p.begin(), p.end()); int ans = 1<<28; for (int i = 0; i < n-1; i++) { ans = min(ans, p[i+1]-p[i]); } c...
0
#include <bits/stdc++.h> using namespace std; bool blocks[1000008]; bool ans[1000008]; const int N = 1000001; int n; void readInput() { scanf("%d", &n); fill(blocks, blocks + N + 2, false); for (int _17 = 0; _17 < ((int)n); _17++) { int x; scanf("%d", &x); blocks[x] = true; } } vector<int> misses; i...
2
// warm heart, wagging tail,and a smile just for you! // // β–’β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–’β–’ // β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–’ // β–’β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–’ // β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ // β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–’ // β–’β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 61; const int M = 1e6 + 500; const long long int ths = 1LL << 40; const int NN = 5e3 + 6; void solve() { long long int n, m; cin >> n >> m; long long...
3
#include <bits/stdc++.h> using namespace std; struct edge { int y; edge* next; }; edge* new_edge() { static edge a[600005]; static int top = 0; return &a[top++]; } edge* li[300005]; void inserts(int x, int y) { edge* t = new_edge(); t->y = y; t->next = li[x]; li[x] = t; } void insert_edge(int x, int y...
3
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; const ld eps=1e-9; //// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Downloa...
0
#include <bits/stdc++.h> typedef struct point { double x; double y; } point; typedef struct segment { point a; point b; } segment; const double eps = 0.000000001; const double inf = 10e25; int eq(double a, double b) { return (fabs(a - b) < eps); } double min(double a, double b) { return (a < b) ? a : b; } doubl...
1
#include <bits/stdc++.h> const int N = 200005; using namespace std; int n, a, b, c; int P[N][18], L[N]; int LCA(int x, int y) { if (L[x] < L[y]) swap(x, y); for (int j = 17; j >= 0; j--) if (L[x] - (1 << j) >= L[y]) x = P[x][j]; if (x == y) return x; for (int j = 17; j >= 0; j--) if (P[x][j] != P[y][j])...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; int N, M, root; int cyc[105], sz[105], h[105], up[105], cmb[105][105], dp[105][105], dpall[105], dpp[105]; int F, f[105]; vector<int> roots, nodes, edg[105]; int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } int mul(int x...
4
#include <bits/stdc++.h> using namespace std; struct cells { int x, y, turns; }; vector<cells> start[15]; int n, m, p; int a[15]; string s[1005]; int dx[5] = {1, 0, -1, 0}; int dy[5] = {0, -1, 0, 1}; int ans[15] = {0}; queue<cells> q[15]; bool check = true; inline bool isval(int x, int y) { if (x >= 0 and x < n and...
4
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int len1 = s1.length(), len2 = s2.length(), x = 0, y = 0; for (int i = 0; i < len1; i++) if (s1[i] == '1') x++; for (int i = 0; i < len2; i++) if (s2[i] == '1') y++; cout << ((x >= y || (x + 1 == y && x % 2)) ...
3
// F - Intervals on Tree #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int64_t E = 0, V = 1LL*n*(n+1)*(n+2)/6; for(int i=0; i<n-1; ++i){ int u, v; cin>>u>>v; if(u > v) swap(u, v); E += 1LL*u*(n-v+1); } cout<< V-E <<endl; }
0
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define mod ((ll)(1e9)+7) vector<ll> v(2*(ll)(1e5+1),0); vector<ll> v_inv(2*(ll)(1e5+1),0); ll pmod(ll n, ll p){ ll m=n%mod; if(p==0) return 1; ll ans=pmod((m*m)%mod, p/2)%mod; if(p%2==1) ans=ans*m%mod; return ...
0
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; cout<<((n*(n+1))/2)<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (long long int)pow(n - 2, 2); return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m, k, fa[400005], ans; int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = (int)(1); i <= (int)(n + m); i++) fa[i] = i; int ans = n + m - 1; for (int i = (int)(1); i <= (int)(k); i++) { int...
2
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-5; long long dp[3001][3001]; long long mi[3001]; int main(void) { int n; cin >> n; vector<pair<long long, long long> > input; for (int i = (0); i < (int)(n); ++i) { long long a, b; cin >> a >> b; input.push_back(pair<long lon...
5
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; #define fi first #define se second #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep(i,n) repl(i,0,n) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #defi...
0
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; cout << (tc * 3) / 2; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; int main() { priority_queue<pll> pq; ll N, K, tmp; cin >> N >> K; vector<ll> times(N + 1); ll cost = 0; for (ll i = 1; i <= K; i++) { cin >> tmp; pll cost_place = make_pair(tmp, i); pq.push(cost_place);...
3
#include <bits/stdc++.h> using namespace std; int n, k, pre = -1; priority_queue<pair<int, int> > q; const int M = 6666666; int mx[M], ls[M], rs[M], tg[M], sz; void pushup(int k) { mx[k] = max(mx[ls[k]], mx[rs[k]]) + tg[k]; } void upd(int &k, int l, int r, int x, int v) { if (!k) k = ++sz; if (l == r) { tg[k] =...
2
#include <bits/stdc++.h> using namespace std; using int64 = long long; template< typename Monoid, typename OperatorMonoid = Monoid > struct LazySegmentTree { using F = function< Monoid(Monoid, Monoid) >; using G = function< Monoid(Monoid, OperatorMonoid, int) >; using H = function< OperatorMonoid(OperatorMonoi...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) { return b; } if (b == 0) { return a; } return gcd(b % a, a); } int main() { long long ra, la, ta, rb, lb, tb; cin >> la >> ra >> ta; cin >> lb >> rb >> tb; long long g = gcd(ta, tb); if (ta >...
3
#include<bits/stdc++.h> using namespace std; int main(){ string s,t; cin>>s>>t; int cnt=0; for(int i=0;i<3;i++){ if(s[i]==t[i]) cnt++; } cout<<cnt; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; for (int i = 1; i <= n; i++) { int b; cin >> b; a.push_back(b); } sort(a.begin(), a.end()); int ans = 0; for (int i = 0; i < a.size() - 1; i += 2) { int dif = a[i + 1] - a[i]; ans += dif; } ...
2
#include <bits/stdc++.h> char a[4000]; int n, q, k; char b[10] = {' ', 'R', 'G', 'B'}; char c[10] = {' ', 'G', 'B', 'R'}; char d[10] = {' ', 'B', 'R', 'G'}; int main(void) { scanf("%d", &q); while (q--) { scanf("%d%d", &n, &k); scanf("%s", a + 1); int Minsum = 1e8; for (register int i = 1; i + k - 1...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 5050, inf = 1 << 29; int n, t[maxn][3], will[3][7], solved[3], points[3], num_hack[3], score[maxn], sol = maxn, dp[2][100][100][100], can[maxn][3]; vector<int> v; inline int calc(int i, int j) { if (j == 0) return 0; return points[i] * (250 - j) / 2...
5
#include <bits/stdc++.h> int main() { int x, y, a, b; scanf("%d%d%d%d", &x, &y, &a, &b); int min = 1; int temp; if (x <= y) { temp = x; x = y; y = temp; } for (int i = 2; i <= x;) { if (x % i == 0 && y % i == 0) { x = x / i; y = y / i; min = min * i; continue; }...
1
#include <bits/stdc++.h> using namespace std; void ASS(bool bb) { if (!bb) { ++*(int*)0; } } #pragma comment(linker, "/STACK:106777216") vector<long long> u; const int N = 1 << 17; struct RSQ { int a[N * 2]; void Add(int pos) { for (int i = pos + N; i; i >>= 1) a[i]++; } int Sum(int L, int R) { ...
5
#include <bits/stdc++.h> using namespace std; typedef pair<double,int> P; int main() { int n; while(cin >> n && n) { vector<P> a; for(int i=0; i<n; i++) { int x,y,z; cin >> x >> y >> z; a.push_back(P(y,x)); a.push_back(P((double)z-0.1,-x)); } sort(a.begin(),a.end()); in...
0
#include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <complex> using namespace std; #define FOR(i,k,n) for(i...
0
#include <bits/stdc++.h> int main() { int h, m, hh, mm; scanf("%d:%d", &h, &m); scanf("%d:%d", &hh, &mm); int x, y; if (mm > m) { h--, m += 60; } y = m - mm; x = (h + 24 - hh) % 24; printf("%02d:%02d\n", x, y); return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<vector<int>> dept(150007); int parent[150007]; int size[200007]; int nexti[200007]; void make_set(int v) { parent[v] = v; size[v] = 1; nexti[v] = v + 1; } int find_set(int v) { if (v == parent[v]) { return v; } return parent[v] = find_set(parent[v]); ...
6
#include<stdio.h> int main(){ int N,Y,b,sum; scanf("%d %d",&N,&Y); for(int i = 0;i<Y;i++){ scanf("%d",&b); } sum = 0; for(;;){ N = N / 2; sum = sum + N; if(N==1) break; } printf("%d\n",sum-Y); }
0
#include <bits/stdc++.h> using namespace std; long long n, m, r, k; struct node { long long x, y, z; bool operator<(const node &rhs) const { return rhs.z > z; } }; priority_queue<node> Q; map<pair<long long, long long>, long long> mp; long long disx[4] = {1, 0, -1, 0}, disy[4] = {0, 1, 0, -1}; signed main() { sca...
4
#include <iostream> #include <vector> using namespace std; const int MAXN = 1e5 + 10, MAXM = 2e5 + 10; vector<pair<int, int> > vc[MAXN]; vector<pair<int, pair<int, int> > > e; long long d[MAXN], n, m; bool se[MAXN]; void dfs(int v, long long dis) { d[v] = dis; se[v] = 1; for (int i = 0; i < vc[v].size(); i++) if...
0
#include "bits/stdc++.h" using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) using ll = long long; using Pll = pair<ll, ll>; const ll inf = 1ll << 60; template<class T, class E> struct SegTree{ typedef function<T(T,T)> F; typedef function<T(T,E)> G; typede...
0
#include <bits/stdc++.h> using namespace std; char a[1005][1005]; bool vis[1005][1005]; int n, m; int check(string s) { int i; for (i = 0; i < s.size(); i++) { if (i + 1 < s.size() && s[i] == '#' && s[i + 1] == '.') { break; } } i++; for (; i < s.size(); i++) { if (s[i] == '#') { cout ...
4
#include <bits/stdc++.h> using namespace std; int main() { int m, n, *p; cin >> m >> n; p = new int[m]; for (int i = 0; i < m; i++) cin >> p[i]; sort(p, p + m); cout << p[m - n] << endl; }
2
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int ans = 9999999; string s; cin>>s; for(char c = 'a'; c <= 'z'; c++){ int mx = 0; int a = 0; for(char i : s){ if(c != i){ a++; } e...
0
#include <bits/stdc++.h> using namespace std; long long int ans = 0; vector<int> vx[200005]; bool vu[200005]; int n, k; int dfs(int v, int p) { int aa = 0, aa2 = 0; for (int i = 0; i < vx[v].size(); i++) { if (vx[v][i] == p) continue; int pr = dfs(vx[v][i], v); aa += pr; aa2 += min(pr, 2 * k - pr); ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << n - 1 - n / 2 << endl; } }
1
#include<iostream> using namespace std; int n, m; bool isIn(int w, int* width){ int sum = 0, step = 1; for (int i = 0; i < n; i++) { if(sum + width[i] > w){ sum = 0; step++; } sum += width[i]; } if(step > m) return false; return true; } int bs(int* width){ int begin = 0, end =...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int v[1024]; int vv[1024]; int N; int try_it(int last) { for (int i = (0); i < (N); i++) vv[i] = v[i]; for (int i = (last); i < (N); i++) vv[i] = max(0, vv[i] - 1); vv[N] = 0; int NN = N; while (NN > 0 && vv[NN - 1] == 0) --NN; int moves...
5
#include <bits/stdc++.h> using namespace std; template <class T, class U> inline void chkmax(T& x, U y) { if (x < y) x = y; } template <class T, class U> inline void chkmin(T& x, U y) { if (y < x) x = y; } const int N = 1e5 + 5; int st[N], en[N], id[N], n, tp[N]; bool cmp(const int i, const int j) { return (n - s...
3
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int p[300000], q[300000], use[300000], last[300000]; pair<int, int> g[100000][3]; pair<int, int> w[100000]; int main() { scanf("%d", &n); for (int i = 0; i < 3 * n; i++) { scanf("%d", &p[i]); ...
4
#include <iostream> using namespace std; int N[40]; int main(){ while(1){ int n; cin >> n; if(n==0) break; N[0]=1; N[1]=1; N[2]=2; for(int i=3;i<n+1;++i){ N[i]=N[i-1]+N[i-2]+N[i-3]; } cout <<1 + ( N[n] / 3650 ) << endl; } }
0
#include <bits/stdc++.h> using namespace std; int N, M; int st, dr, res; string s[1010]; int viz[1010][1010]; int dy[] = {-1, 0, 1}; int isBad(int x, int y) { if (y >= s[1].size()) return 0; if (s[x][y] == '.' || s[x][y] == 's') { return 0; } return 1; } int valid(int x, int xz, int y) { if (x <= 0 || x >...
4
#include <bits/stdc++.h> using namespace std; bool can[35][75 * 31][75]; int num[75]; int nnum[75]; int w[75][75]; int nx[35][75 * 31][75]; int ncnt[75]; struct th { int id, nnum; bool operator<(const th &a) const { return nnum < a.nnum; } } p[75]; int main() { int m; scanf("%d", &m); for (int i = 1; i <= m; ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 2e9; vector<string> v; int n, m; int diff(string a, string b) { int i, cc = 0; for (i = 0; i < m; ++i) cc += (a[i] != b[i]); return cc; } string solve(int mi) { string s = v[mi], t; int i, j, cc; char c; bool f; for (i =...
6
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int INF = 1001001001; struct edge{ int t; int w; }; vector<edge> to[100007]; vector<int> visit(100007); vector<int> dist(100007); void dfs(int u, int b=-1){ visit[u] = 1; rep(i, t...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int a[2005]; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int i = n - 1; int t = 0; while (i >= 0) { t += (a[i] - 1) * 2; i -= m; } cout << t; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n; int x[33333]; int C[33333]; int BB[33333]; int seen[33333]; int seena[33333]; int main() { scanf("%d", &n); int cc = 0; for (int i = 0; i < 2 * n; i++) { scanf("%d", &x[i]); C[x[i]]++; BB[x[i]]++; } int ca = 0, cb = 0; vector<int> res(2 * n, 0...
2
#include <iostream> #include <queue> #include <map> #include <string> #define f first #define s second using namespace std; int main(){ string x; int y; int n,q,i,cnt=0; queue<pair <string,int> > a; cin>>n>>q; for(i=0;i<n;i++){ cin>>x>>y; a.push(make_pair(x,y)); } while(!a.empty()){ cnt+=q; ...
0
#include <bits/stdc++.h> using namespace std; const int maxN = 2 * 100000 + 10; int h, m, n; int a[maxN]; map<int, int> at; long long res = 0; int main() { ios::sync_with_stdio(false); cin >> h >> m >> n; memset(a, -1, sizeof a); for (int i = 0; i < n; i++) { char ch; cin >> ch; if (ch == '+') { ...
3
#include <bits/stdc++.h> using namespace std; const int NR = 2005; const double eps = 1e-12; void Min(int& x, int y) { x = min(x, y); } void Max(int& x, int y) { x = max(x, y); } int n; long long ans = 0; double x[NR], y[NR]; double p[NR]; bool jd(double a, double b) { return fabs(a - b) <= eps; } int read() { int x ...
4
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264338; struct hehe { long long x, y; } p[100005]; int n; double maxr, minr, ans; long long cross(hehe p1, hehe p2, hehe p3) { return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y); } long long dc(hehe p1, hehe p2, ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2010; long long ans, nbr; int n, k, a[N][N]; vector<int> v; int main() { ios::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { a[i][i] = -1; for (int j = i + 1; j <= n; ++j) { cin >> a[i][j]; a[j][i] = a[i][j]; } ...
4
#include<bits/stdc++.h> using namespace std; typedef double D; const D EPS= (1e-10); #define X real() #define Y imag() #define SZ size() #define PB(x) push_back(b) #define PREV(x,i) (x[(i+x.SZ-1)%x.SZ]) #define NEXT(x,i) (x[(i+1)%x.SZ]) template<class T> using CR=const T&; using P=complex<D>; using G=vector<P>; i...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000009; #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") #pragma GCC optimize "-O3" void solve() { long long a, b; ci...
1
#include <bits/stdc++.h> using namespace std; const int N = 2050; struct Number { bitset<N> bits; Number() {} void init(vector<int> s) { int c = 0; while (s.size()) { bits[c] = s[0] & 1; c++; s[0] >>= 1; for (int i = 1; i < s.size(); i++) s[i - 1] += (s[i] & 1) * 5, s[i] /= 2; ...
4
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; cout<<(1000-n%1000)%1000; return 0; }
0
#include<bits/stdc++.h> #define MAXN 100005 #define INF 1000000009 using namespace std; typedef long long ll; ll n,m,a[MAXN],res; priority_queue<ll, vector<ll>, greater<ll> > pque; vector<ll> G[MAXN]; bool used[MAXN]; void dfs(ll v,ll p) { used[v]=true; if(a[v]<res) { if(res!=INF) pque.push(res); res=a[v]; } e...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); int a[n + 2][3]; for (int i = 0; i < n + 1; i++) for (int j = 0; j < 3; j++) a[i][j] = 0; for (int k = 0; k < s.length(); k++) { if (s[k] == '.') continue; else if (s[k] == 'A') { a[k][...
1
#include<bits/stdc++.h> #define ll long long #define mo 1000000007 using namespace std; int n,k; int main(){ scanf("%d%d",&n,&k); ll ans=0; for (int i=1;i<=n;i++){ int times=n/i; ans+=n; ans-=times*min(i,k); ans-=min(k,n%i+1); ans+=(k!=0); } printf("%lld\n",ans); }
0
#include <bits/stdc++.h> using namespace std; int a[1001], b[1001], ans[1001]; int temp[10]; bool used[1001]; int main() { int n, diff = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; used[i] = false; } for (int i = 1; i <= n; i++) { cin >> b[i]; if (a[i] == b[i]) { ans[i] = a[...
2
#include <bits/stdc++.h> using namespace std; int main() { string s; long long sz; cin >> sz; cin >> s; long long ans = sz; for (long long i = 0; i < sz; i++) if (s[i] != '#' && i + 1 < sz && s[i] != s[i + 1]) ans--, s[i + 1] = '#'; cout << ans << endl; return 0; }
1
#include <cstdio> using namespace std; int main(){ while(1){ int n,a=0; scanf("%d",&n); if(!n)break; while(n!=1){ if(n&1)n=n*3+1; else n/=2; a++; } printf("%d\n",a); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m, second; vector<int> g[200005]; vector<int> r[200005]; vector<int> cyc[200005]; int visit[200005]; int SCC[200005]; void dfs(int u) { visit[u] = 1; for (int v : g[u]) { if (visit[v]) continue; dfs(v); } } bool color[200005], vis[200005]; stack<int> st...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; char A[100100]; int len; int O[13], T1[13], T2[13]; char S1[100100], S2[100100]; int main() { int cur, resd, add, res = -1000000000, resz; cin.getline(A, 100100, '\n'); len = strlen(A); for (int i = 0; i < len; i++) O[(int)...
2
#include <bits/stdc++.h> using namespace std; bool check(int a, int b) { return a == b; } int main() { int hh, mm; cin >> hh >> mm; int h, d, c, n; cin >> h >> d >> c >> n; if (hh >= 20) { if (h % n == 0) printf("%.4f\n", (h / n) * ((float)4 * c) / 5); else printf("%.4f\n", (h / n + 1) * (...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k, p, i, j, max = 0; cin >> n >> k >> p; long long a[n + 1]; long long b[k + 1]; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= k; i++) cin >> b[i]; sort(a...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, s; cin >> n >> s; long long a[n], ans = 0; for (long long i = 0; i < n; i++) cin >>...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long max, min, i, j, a[105], q, k, n; cin >> q; while (q--) { max = 0; min = 0x3f3f3f3f; memset(a, 0, sizeof(a)); cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] <= min) mi...
2
#include <bits/stdc++.h> using namespace std; int n, q; int l, r; int v[100005], k[100005]; pair<int, int> p[100005]; vector<int> st; int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) scanf("%d", &v[i]); while (q--) { scanf("%d%d", &l, &r); int sz = 0; for (int i = l; i < r; i++) k[sz++]...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++){ int x, y, b, p; scanf("%d %d %d %d", &x, &y, &b, &p); int A = x * b + y * p; int B = (x * max(b, 5) + y * max(p, 2)) * 4 / 5; printf("%d\n", min(A, B)); } }
0
#include<cstdio> #include<cstring> #include<algorithm> #define MN 300005 using namespace std; inline int in(){ int x=0;bool f=0; char c; for (;(c=getchar())<'0'||c>'9';f=c=='-'); for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0'); return f?-x:x; } int k,n,a[MN],cur,cnt; int main() { k=in();...
0
#include<bits/stdc++.h> using namespace std; int sum; int main() { for(int i=1; i<=6; i++) { char x; cin>>x; if(x=='1') sum++; } printf("%d\n",sum);return 0; }
0
#include<bits/stdc++.h> using namespace std; const int maxn=1e6+5; const int inf=0x3f3f3f3f; int a[maxn],b[maxn]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen(".in","r",stdin); //freopen(".out","w",stdout); int n,k,c; string s; cin>>n>>k>>c>>s; int num=0; for(int i=0;i<n;i++) ...
0
#include <bits/stdc++.h> using namespace std; const long double PI = atan(1.0) * 4.0; const long long int MOD = 1e9 + 7; const long long int INF = 1e8; bool comp(pair<int, vector<int> > p1, pair<int, vector<int> > p2) { return (p1.first > p2.first); } int n, m, x, y, color[300010], vis[300010] = {0}, p[300010]; vecto...
3
#include <bits/stdc++.h> using namespace std; const unsigned long long B = 31; const int maxn = 50005; int n, ban, s[maxn], tag[maxn]; char _s[maxn]; unsigned long long h[maxn], pw[maxn]; unsigned long long calc_hash(int l, int r) { return h[r] - h[l - 1] * pw[r - l + 1]; } void init_hash() { for (int i = 1; i <= n...
4
#include <bits/stdc++.h> using namespace std; deque<vector<int> > v; int main() { int(n), (k); scanf("%d %d", &(n), &(k)); string s; cin >> s; int mn = 0, mx = 0; while (1) { mn++; v.push_back(vector<int>()); for (int i = 1; i < n; i++) if (s[i] == 'L' && s[i - 1] == 'R') v.back().push_bac...
4
#include<iostream> #include<algorithm> using namespace std; int main(void){ int x,y,z; while(cin >> x >> y){ if(x<y) swap(x,y); while((z=x%y)!=0){ x=y; y=z; } cout << y << endl; } }
0
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); ; long long a, b, c; cin >> a >> b >> c; long long x, y, z; x = a + b + c; y = a * b * c; z = (a + b) * c; long long d = a * (b + c); cout << max(max(x, y), max(z, d)); }
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, B = 350; int n, pos[N], Lef[N], Rig[N], a[N]; struct block { int sta[B], top, cnt; } b[B]; void updata(int p) { int l = Lef[p], r = Rig[p]; int top = 0, cnt = 0; for (register int i = (l); i <= (r); ++i) { if (a[i] == 0) continue; if ...
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long double pi = acos(-1.0); const long double log23 = 1.58496250072115618145373894394781; const long double eps = 1e-8; const long long INF = 1e18 + 239; const long long prost = 239; const int two = 2; const int th = 3; const long long MOD ...
1