solution
stringlengths
52
181k
difficulty
int64
0
6
#include <iostream> #include <vector> #include <cstring> using namespace std; struct Edge{ int src,dst,cost; bool isl; Edge(int s,int d,int c) : src(s), dst(d), cost(c) {isl = false;} }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; int dist[21]; bool visited[21],isleaf[21],ispar[21]; bool dfs...
0
#include <bits/stdc++.h> using namespace std; int n, d, k, START; int main() { cin >> n >> d >> k; if (n == 3 && d == 1 && k == 1) { cout << "-1"; return 0; } if (n == 2 && d == 1) { cout << "1 2\n"; return 0; } if (d == k && d == 1) { cout << "-1"; return 0; } if (d == k) ST...
3
#include<bits/stdc++.h> #define M_PIl 3.141592653589793238462643383279502884L /* pi */ #define lld long long int #define ld long double #define mod 1000000007 #define modd 998244353 #define all(v) v.begin(),v.end() #define rep(i,a,b) for(lld i=a;i<=b;i++) #define repr(i,a,b) for(lld i=a;i>=b;i--) #define ar array #defi...
1
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long N = 1e5 + 5; long long powm(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } long long pow(long long a, long...
3
#include<bits/stdc++.h> using namespace std; const int MOD = 1e9+7; string s; int d; int memo[10005][105][3]; int dp(int idx, int tot, int stat){ if(idx>=s.size()){ if(tot == 0) return 1; else return 0; } int &ret = memo[idx][tot][stat]; if(ret!=-1) return ret; ret = 0; for(int i=0;i<1...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 10000 + 10; int N; int a[MAX]; int main() { while (cin >> a[++N]) ; --N; int d1 = a[2] - a[1]; int d2 = a[3] - a[2]; int d3 = a[4] - a[3]; if (d1 == d2 && d2 == d3) { cout << a[4] + d1 << endl; return 0; } if (a[1] == 0 || a[2] ==...
1
#include <iostream> #include <algorithm> using namespace std; int n; int main() { cin >> n; int ans = 0; while (n) { ans += n % 10; n /= 10; } if (ans == 1) ans *= 10; cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ttl = 0; int c = 0; while (ttl < n) { for (int i = 1; i <= 3 && ttl < n; i++) { ttl++; printf("%d %d\n", c, (i / 3) * 3); if (i != 2) c++; } } return 0; }
3
#include <bits/stdc++.h> using namespace std; int t, n, m; int ans; vector<vector<int> > p; bool check(int x) { vector<bool> flag(n); bool pair = false; for (int i = 0; i < m; i++) { int cnt = 0; for (int j = 0; j < n; j++) { if (p[i][j] >= x) { flag[j] = true; cnt++; } } ...
4
#include <iostream> #include <algorithm> typedef long long ll; using namespace std; ll dp[3010][3010][4]={}, item[3010][3010]={}; int main() { int R, C, K; cin >> R >> C >> K; for(int i=0; i<K; ++i){ int r, s; ll v; cin >> r >> s >> v; item[r][s]=v; } for(int i=1; i<=R; ++i){ for(int j=1; j<=C; ++j){ ...
0
#include <bits/stdc++.h> using namespace std; bool isvowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; return false; } long long int isprime(long long int n) { for (long long int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } long long int powe...
4
#include <bits/stdc++.h> using namespace std; inline void file() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (0) { freopen(".in", "r", stdin); freopen(".out", "w", stdout); } } const clock_t MAXT = (100 * CLOCKS_PER_SEC) / 1000; const int PX[5] = {0, 0, 1, -1}, PY[5] = {-1, 1...
1
#include <iostream> #include <cstdio> using namespace std; class list { struct node { int val; node* prev; node* next; node(int n) : val(n), prev(NULL), next(NULL) {} node(int n, node* prev_p, node* next_p) : val(n), prev(prev_p), next(next_p) {} }; node* nil; node* cur; public: list...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") const int maxn = 100010; int n, m, a[maxn]; void print(int x) { if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007ll; long long n, q, t, ma, a[301], to[301], f[100001]; bool m[301], in[301], vis[301]; void dfs(long long u, long long d, long long s) { ma = d, vis[u] = true; if (to[u]) dfs(to[u], d + 1, s + a[u]); t -= (ma - d) * a[u], a[u] += s; } i...
5
#include<bits/stdc++.h> using namespace std; double n,d; int main(){ cin>>n>>d; cout<<ceil(n/(d*2+1)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, x[110], y[110], vis[110], c = -1; void dfs(int p) { vis[p] = 1; for (int i = 1; i <= n; i++) { if ((x[i] == x[p] || y[i] == y[p]) && vis[i] == 0) dfs(i); } } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; for (int i = 1; i <=...
1
#include <bits/stdc++.h> using namespace std; int x[100001]; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> x[i]; } sort(x, x + n, greater<int>()); int num = 1; int ans = 0; for (int i = 0; i < n; i++) { if (x[i...
3
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int h = 0; for (int i = n; i > 0; i /= 10) h += i % 10; cout << (n % h == 0 ? "Yes" : "No") << endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000 + 10; vector<int> G[MAX_N], ans; int l[MAX_N], goal[MAX_N], n, x, y, dep[MAX_N], mark[MAX_N]; void dfs(int u, int a, int b) { mark[u] = 1; int aa, bbb; aa = a; bbb = b; if (dep[u] % 2 == 1) { if (b == 1) { l[u] = 1 - l[u]; } ...
3
//#pragma GCC target ("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimization ("unroll-loops") //#pragma GCC optimize("Ofast") #include <bits/stdc++.h> //#include <ext/rope> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_cxx; //usi...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, vector<int>> v; int x; for (int i = 0; i < n; i++) { cin >> x; v[x].push_back(i + 1); } int cnt = 0; vector<pair<int, int>> ans; for (auto itr : v) { vector<int> a = itr.second; sort(a.begin(), a.end()...
2
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0; int mini = 101; for (int i = 0; i < 4; ++i) { int s; cin >> s; sum += s; mini = min(s, mini); } int s1, s2; cin >> s1 >> s2; cout << sum - mini + max(s1, s2) << '\n'; }
0
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int par[maxn],sz[maxn],x[maxn],y[maxn],n,m; long long now,ans[maxn]; int find(int x) { if(par[x]==x)return x; else return par[x]=find(par[x]); } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { par[i]=i; sz[i]=1; } for(int i=1;i<=m...
0
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; long long mul_inv(long long a, long long b = 1000000007) { long long b0 = b, t, q; long long x0 = 0, x1 = 1; if (b == 1) return 1; while (a > 1) { q = a / b; t = b, b = a % b, a = t; t = x0, x0 = x1 - q * x0, x1 = t; } ...
5
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const long long N = 400007; const long long mod = 1e9 + 7; const double eps = 1e-6; const double pi = acos(-1.0); inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 500010; int lft[maxn << 2], rht[maxn << 2], M1[maxn << 2], M2[maxn << 2]; void build(int n, int l, int r) { lft[n] = l, rht[n] = r; if (l == r) return; int mid = (l + r) / 2; build(n << 1, l, mid); build((n << 1) + 1, mid + 1, r); } void upd1(int ...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long md = 1e9 + 7; const long double eps = 1e-9; const int maxn = 1e3 + 10; mt19937 rnd(100500); int n, ans; string s[600]; int main() { ios_base::sync_with_stdio(false); ; cin.tie(NULL); ; cin >> n; for (int i = 0; i < n; i...
1
#include <bits/stdc++.h> using namespace std; int n, answer; bool p1[2005], p2[2005], used[2005]; int x1[2005], x2[2005]; vector<vector<int>> g(1005); void dfs(int v) { if (p1[v]) { answer = v; return; } used[v] = 1; for (int i = 0; i < g[v].size(); i++) if (!used[g[v][i]]) dfs(g[v][i]); return; }...
4
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } struct compare { bool operator()(const pair<long long, ...
1
#include <bits/stdc++.h> using namespace std; long long n, m, p, N; int a[200005], b[200005]; int cnt[200005]; int ori[200005]; vector<int> v; map<int, int> id; int main() { cin >> n >> m >> p; for (int i = 0; i < n; ++i) scanf("%d", a + i); for (int i = 0; i < m; ++i) scanf("%d", b + i), v.push_back(b[i]); sor...
2
#include<iostream> #include<string> using namespace std; string rev(string str){ for(int i=0;i<str.length();i++){ if(str[i]=='['){ int j; int co=1; for(j=i+1;j<str.length();j++){ if(str[j]=='[')co++; if(str[j]==']')co--; if...
0
#include<bits/stdc++.h> using namespace std; using LL = long long; int main() { LL N; cin >> N; vector<LL> A(N); for(auto& i: A) cin >> i; auto a = max_element(begin(A), end(A)) - begin(A); if(A[a] <= 0) { cout << A[a] << endl; cout << N-1 << endl; for(auto i=N; a+1<i; --i) cout << i << endl; ...
0
#include "bits/stdc++.h" #define ALL(g) (g).begin(),(g).end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define RREP(i, x, n) for(int i = x; i >= n; i--) #define rrep(i, n) RREP(i,n,0) #define pb push_back using namespace std; using ll = long long; using P = pair<int,int>; using Pl ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cin.exceptions(cin.failbit); int T; cin >> T; while...
2
/* In the name of Allah */ #include<bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, m, q, a[N][N], dp[N][N][3]; int get(int b, int xl, int xr, int yl, int yr) { return dp[xr][yr][b] - dp[xl][yr][b] - dp[xr][yl][b] + dp[xl][yl][b]; } void read_input() { cin >> n >> m >> q; for (int i = 1; i <= n;...
0
#include<bits/stdc++.h> using namespace std; #define maxn 100100 int a[maxn]; int n,c,k; int main() { ios::sync_with_stdio(false); cin>>n>>c>>k; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n); int ans=0; for(int i=1;i<=n;i++) { int j=i; while (j+1<=n && j+1<=i+c-1 && a[j+1]<=a[i]+k) j++; ans++;...
0
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18; void print_vector(vector<long long> &a) { for (auto &i : a) { cout << i << " "; } cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long n, l = 1, r = 1; n = (long l...
2
#include <bits/stdc++.h> using namespace std; set<long long> s[201]; void insertion(long long num, vector<long long> v) { for (long long i = 0; i < v.size(); i++) { if (v[i] != num) { s[num].insert(v[i]); } } } void checkandremove(long long num, vector<long long> v) { set<long long> ss; for (long ...
2
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long int sum[s.length()]; for (long long int i = 0; i < s.length(); i++) { if (s[i] == 'Q') { if (i == 0) sum[i] = 1; else sum[i] = 1 + sum[i - 1]; } else { if (i == 0) sum[i] = ...
1
#include<iostream> #include<vector> #include<algorithm> #include<iomanip> using namespace std; typedef pair<int,int> p; typedef long long ll; int main(){ int n, w; cin >> n >> w; vector<p> v(n); for(int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; sort(v.rbegin(), v.rend(), [](p a, p b){r...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int s = 0; for (int i = 1;; i++) { s += i * (i + 1) / 2; if (s + (i + 1) * (i + 2) / 2 > n) { cout << i; return 0; } } }
1
#include <bits/stdc++.h> using namespace std; const long long Min = -1e4; int main() { long long t; cin >> t; while (t--) { long long X, Y; cin >> X >> Y; if (X >= 4) cout << "YES" << endl; else if (X == 2 || X == 3) cout << (Y <= 3 ? "YES" : "NO") << endl; else if (X == 1) c...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b != 0) { long long c = a % b; a = b; b = c; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { int n, a[105], i; long long ans = 1, cnt; bool visit[105]; ...
1
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(0); string s; cin >> s; int k; cin >> k; int ans = 0; s += '&'; while (k--) { string c; cin >> c; int t1 = 0, t2 = 0; for (int i = 0; i < s.length(); i++) { if (c[0] == s[i]) t1++;...
1
#include<bits/stdc++.h> using namespace std; int a[200050],n,k; bool check(int mid) { int ans=0; for(int i=1;i<=n;i++) { if(a[i]>mid) ans+=a[i]/mid; } if(ans>k) return 0; return 1; } int main() { cin>>n>>k; int l=1,r=-1; for(int i=1;i<=n;i++) { cin>>a[i]; r=max(a[i],r); } int ans=0; whi...
0
#include <bits/stdc++.h> using namespace std; int N; int P[5050]; int B[5050]; int BX[5050]; int PX[5050]; int TN; int TP[5050] = {1, 0, 3, 2}; int TB[5050]; int ask(int p, int b) { int ret; if (TN) { cout << p << " " << b << " " << (TP[p] ^ TB[b]) << endl; return TP[p] ^ TB[b]; } cout << "? " << p << "...
4
#include<bits/stdc++.h> using namespace std; int lth,vis[30]; char s[30]; int main() { scanf("%s",s+1),lth=strlen(s+1); for(int i=1;i<=lth;i++)vis[s[i]-'a']=i; if(lth<26) { for(int i=0;i<26;i++)if(!vis[i]) return printf("%s%c",s+1,'a'+i),0; } else for(int i=26;i;i--) ...
0
#include <bits/stdc++.h> using namespace std; int arr[100005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) cin >> arr[i]; int mx = 0; for (int i = 1; i <= n; i++) { if (arr[i] > mx) { cout << i << endl; return 0; } mx = max(mx, arr[i] + 1); } cout << "-1" << e...
2
#include <bits/stdc++.h> using namespace std; int cutLen(vector<pair<int, int> > v) { pair<int, int> p(0, 0); int len = 0; for (unsigned i = 0; i < v.size(); ++i) { if (v[i].first <= p.second) { p.second = max(v[i].second, p.second); } else { len += p.second - p.first; p = v[i]; } ...
3
#include <bits/stdc++.h> using namespace std; char s[1000005]; int num[1000005]; char f[8][5] = {"1869", "1968", "1689", "6198", "1698", "1986", "1896"}; int main() { int len, i, ant, flag, sum; int a[20]; while (~scanf("%s", s)) { ant = 0; len = strlen(s); for (i = 0; i < len; i++) { num[i] = s...
1
#include <bits/stdc++.h> using namespace std; int main() { long n, k; cin >> n >> k; long arrt[n], arrm[n]; for (int i = 0; i < n; i++) { int temp; cin >> temp; arrt[i] = temp; } for (int i = 0; i < n; i++) { int temp; cin >> temp; arrm[i] = temp; } int dp = 0; for (int i = 0; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, n; cin >> a >> b >> c >> n; int r = max(max(a, b), c); r = r * 3 - a - b - c; if (r <= n && (n - r) % 3 == 0) cout << "YES" << endl; else cout << "NO" << endl; } return 0;...
1
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f const int maxn = 10000+5; int N,M,dis[maxn],vis[maxn],cost[maxn]; struct edge { int v,d,c; edge(int A,int B,int C):v(A),d(B),c(C) {} }; vector<edge> G[maxn]; queue<int> que; void spfa() { memset(dis,inf,sizeof(dis)); memset(vis,0,size...
0
//In His Name #include<bits/stdc++.h> using namespace std; vector<pair<int,int> >e; vector<int>adj[100100]; int n,m,minlvl[100100],lvl[100100]; bool mark[100100]; void dfs(int x,int par){ mark[x]=true; minlvl[x]=lvl[x]; for(int i=0;i<adj[x].size();i++){ int v=adj[x][i]; if(!mark[v]){ lvl[v]=lvl[x]+1; dfs(v...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s[110000], r[110000], i, j, k, c, m, w = 0, x = 0, y = 0, z = 0, o, p; cin >> a >> b; for (i = 1; i <= a; i++) { cin >> s[i]; } for (j = 1; j <= b; j++) { cin >> r[j]; } for (k = 1...
1
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; int t; int n; cin >> t; while (t--) { cin >> n; set<int> used; for (int i = 2; i * i <= n; i++) { if (n % i == 0 && !used.count(i)) { used.i...
3
#include <bits/stdc++.h> using i64 = long long; struct node { int ans; i64 adv; node(int ans = 0, i64 adv = 0) : ans(ans), adv(adv) {} node operator+(const node b) const { return node(ans + b.ans, adv + b.adv); } node operator+() const { return node(ans + (adv > 0)); } bool operator<(const node b) const { ...
4
#include <bits/stdc++.h> using namespace std; struct pnt { int x, y; pnt(){}; pnt(int x, int y) : x(x), y(y){}; }; struct vect { int x, y; vect(){}; vect(int x, int y) : x(x), y(y){}; vect(pnt a, pnt b) : x(b.x - a.x), y(b.y - a.y){}; }; bool left(vect a, vect b) { return (a.x * b.y - a.y * b.x) > 0; } in...
4
#include <bits/stdc++.h> using namespace std; map<long long, long long> cache[10]; long long go(int d, long long n) { if (cache[d].find(n) != cache[d].end()) return cache[d][n]; long long p = 1; while (n / p >= 10) p *= 10; int x = n / p; long long y = n % p; long long res = 0; for (; x >= 0; x--) { i...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; const int inf = 50000000; const int maxn = 300010; const int sqrtn = 1000; long long add(long long a, long long b) { long long ret = (a + b) % mod; return ret; } long long fib[maxn], arr[maxn], pref[maxn], fibarr[maxn]; vector<pair<int, int> ...
3
#include <bits/stdc++.h> using namespace std; vector<int> adj(19, 0); long long int dp[1 << 19][19] = {}, ans = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i, j, n, m; cin >> n >> m; while (m--) { cin >> i >> j; i--; j--; adj[i] |= (1 << j); adj[j] |= (1 <<...
4
#include <bits/stdc++.h> using namespace std; void gn(int &x) { int sg = 1; char c; while (((c = getchar()) < '0' || c > '9') && c != '-') ; if (c == '-') sg = -1, x = 0; else x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0'; x *= sg; } const int mo = 1000000007; in...
5
#include <bits/stdc++.h> using namespace std; int h[10000]; map<int, int> b; map<int, int>::iterator it; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> h[i], ++b[h[i] - i * k]; int maxi = 0, bb = 0; for (it = b.begin(); it != b.end(); ++it) if (k + it->first > 0 && maxi < it->se...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> s(n); for (int i = 0; i < n; i++) cin >> s[i]; vector<int> cntn(n), cntm(m); int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i][j] == '*') { cntn[i]++; ...
2
#include<cstdio> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int N=100005; int n,K,i,p[N],q[N],invp[N],invq[N],a[N],b[N],c[N],x[10][N],ans[N],m; void Mult(int a[N],int b[N],int rtn[N]) { for(int i=1;i<=n;++i) rtn[i]=a[b[i]]; } void Inv(int a[N],int rtn[N]) { for...
0
#include <bits/stdc++.h> using namespace std; int n; vector<int> magulang; vector<vector<int>> anak; vector<int> preorder; void getPreorder(int v) { preorder.push_back(v); for (int nxt : anak[v]) getPreorder(nxt); } int main() { scanf("%d", &n); magulang = vector<int>(n, -1); anak = vector<vector<int>>(n); ...
6
#include <bits/stdc++.h> int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; using namespace std; void file() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { file(); int x, y, z; cin >> x >> y >> z; if (min(x, y) + z < max(x, y) && max(x, y) == y) cout <<...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("-ffloat-store") using namespace std; clock_t time_p = clock(); void aryanc403() { time_...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int sizz = 1e6 + 4; const long long int MIN = numeric_limits<long long int>::min(); bool compare(const pair<int, pair<int, int> > &a, const pair<int, pair<int, int> > &b) { return a.first < b.first; } int main() { long long int ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int max = 1e5 + 5; while (t--) { int n; cin >> n; vector<int> count(max, 0); vector<int> a(n); int maxm = 0; int ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; count[a[i]]++; if (count[...
3
#include <bits/stdc++.h> using namespace std; int a[10005]; int n, z; int t, sum; int ans; int main() { cin >> t; while (t--) { z = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int y = 10000; for (int i = 1; i < n; i++) { z = a[i] - a[i - 1]; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a, b; long long int c = 0, d = 0; bool f = true; for (long long int i = 0; i < n; i++) { cin >> a >> b; if (a < c || b < d || a - c < b -...
1
#include<bits/stdc++.h> using namespace std; int main(){ string x,y; cin>>x>>y; y.pop_back(); if(x==y){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
0
#include <bits/stdc++.h> using namespace std; int a[100010][4], n, m, k; int main() { long long res; scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= m; i++) scanf("%d %d %d", &a[i][1], &a[i][2], &a[i][3]); int cell; res = 0; while (k) { k--; scanf("%d", &cell); for (int i = 1; i <= m; i++) ...
2
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool f = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f = (ch == '-'); for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return f ? -x : x; } const int maxn = 4e5 + 7; int n, m, c[maxn], fa[ma...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T parse(const string &s) { T x; stringstream ss(s); ss >> x; return x; } cons...
4
#include <iostream> using namespace std; int main() { int a, b, n; while (cin >> a >> b >> n){ int sum = 0; for (int i = 0; i < n; i++){ a *= 10; sum += (a / b) % 10; a %= b; } cout << sum << endl; } return (0); }
0
#include <bits/stdc++.h> using namespace std; int b[100010] = {0}, c[11][100010] = {0}; int main() { int n, k, w; string a; cin >> n >> k >> w; cin >> a; for (int i = 0; i < n; i++) { if (a[i] == '1') b[i + 1] = 1; } for (int i = 0; i < k; i++) { for (int j = i + 1; j <= n; j++) { c[i][j] = ...
3
#include<bits/stdc++.h> using namespace std; using LL=long long; LL get(int level,LL h){ if(level==0)return 1; LL s=pow(LL(2),level+2)-3; if(h==1)return 0; if(h==s)return pow(LL(2),level+1)-1; if(h<=(s-1)/2)return get(level-1,h-1); if(h==(s+1)/2)return get(level-1,(s-1)/2-1)+1; return get(level-1,(s-1)/2-...
0
#include <bits/stdc++.h> using namespace std; bool dd[5000005]; long long n, a[5000005], b[5000005], avail[5000005], pos[5000005]; vector<long long> v, ans, pri, vec; multiset<long long> s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); dd[1] = true; for (long long i = 2; i < 5000000; i++)...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 100; int Z[MAX], F[MAX], SZ; string Str; void ZArray() { int L, R, K; L = 0, R = 0, K = 0; for (int i = 1; i < SZ; i++) { if (i > R) { L = R = i; while (Str[R] == Str[R - L]) R++; Z[i] = R - L; R--; } else { ...
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(const strin...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int dy[] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; int dx[] = {0, 1, 2, 0, 1, 2, 0, 1, 2}; void solve() { int a[9][9], wa[9][9] = {}; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { cin >> a[i][j]; } ...
0
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000000 + 7; const long long int N = 10000000 + 6; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; cin >> q; for (int i = 0; i < q; ++i) { long long n; cin >> n; vector<int> vals; int pos2 = ...
3
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } const long long maxn = 1e3 + 10; const long long inf = 1e18 + 10; const long long mod = 1e9 + 7; long long res = 1; bool changed ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; while (cin >> n) { int t[100011]; for (int i = 1; i <= n; ++i) cin >> t[i]; int suma = 0, sumb = 0; int l = 1, r = n; int alice = 0, bob = 0; while (l <= r) { if (suma...
3
#include <bits/stdc++.h> using namespace std; int main() { int k, i, n, l, count = 0, count1 = 0, j; string s, fin = ""; cin >> s; cin >> k; char ans[k]; l = s.size(); int f = 0; for (i = 0; i < l; i++) { if (s[i] == '?') count++; if (s[i] == '*') { count1++; } } int rl = l - count...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 1800010; const int INF = 2147483600; int N; int Next[MAX...
6
#include <bits/stdc++.h> using namespace std; char d[1010]; int main() { int n; scanf("%d", &n); scanf("%s", d); int pierwszeR = -1, ostatnieR = -1; int pierwszeW, ostatnieW; for (int i = 1; i <= n; i++) { if (i != 1 && d[i - 1] != '.' && d[i - 2] == '.') pierwszeW = i; if (i != n && d[i - 1] != '.'...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { char ch = getchar(); int f = 1; while ((ch != '-') && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') f = 0, x = 0; else x = ch - 48; ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48...
4
#include<iostream> #include<cctype> #include<cstdio> #include<cstring> #include<climits> using namespace std; long long len(const char *str){ long long ret = 0; str++; while(*str!=')'){ //printf(" %s : ret=%d\n",str,ret); if(isdigit(*str)||*str=='('){ long long num; if(*str=='('){ nu...
0
#include <bits/stdc++.h> using namespace std; const int sigma_size = 26; const int N = 20; const int MAXN = 100000 + 50; const int inf = 0x3fffffff; const double eps = 1e-8; const int HASH = 100007; const int mod = 1000000000 + 7; template <class T> inline bool RD(T& res) { char c; int sgn; if (c = getchar(), c =...
2
#include <bits/stdc++.h> using namespace std; long long MxV = 3000001; struct dst { long long r, x, y; }; int main() { long long n, k; long long i, j; long long a[10][55]; long long cnt = 0; cin >> n >> k; for (i = 0; i < 4; ++i) { for (j = 0; j < n; ++j) { cin >> a[i][j]; } } for (i = 1...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2003; int ans = 0; int xx; int dp[maxn][maxn]; char a[maxn], b[maxn]; int main() { a[0] = b[0] = 1; scanf("%s%s", &a[1], &b[1]); int lena = strlen(a); int lenb = strlen(b); lena--; lenb--; for (int i = 1; i <= lena; i++) { for (int j = 1; ...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 105; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long m, b; cin >> m >> b; long long ans = 0; for (long long y = b; y >= 0; --y) { long long x = m * (b - y); long long cnty = y * (y + 1) / 2; long long cntx = x * (...
2
#include <bits/stdc++.h> const int maxn = 2000010; long long val[maxn], n, sum, veryleft[maxn], cnt[maxn]; std::deque<long long> q; long long query(int k) { if (sum <= k) return 1; long long inseq = sum, ans = maxn; for (int i = 1; i <= n; i++) q.push_back(val[i + 1]); for (int i = n + 1; i <= (n << 1); i++) { ...
5
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:36777216") using namespace std; const long double EPS = 1e-9; const int INF = 1e9 + 7; long double dp[4][2002][2002]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(7); int n, h;...
4
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, sum, cnt, ans, a[85], f[85][85]; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) f[n][i] = INT_MAX; for (int i = n - 1; i >= 0; i--) { for (int j = 1; j <= n; j++) { ...
1
#include <bits/stdc++.h> using namespace std; const long long md = (long long)1e9 + 7, inf = (long long)1e18; vector<vector<int>> g; vector<int> mark, us, wh, bl; int sz = 1; void add(long long x, int k, int c) { int v = 0; for (int i = 0; i < k; i++) { int whr = 31 - i; int to = (x >> whr) & 1; if (g[v...
2