solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int M = 525000; const int mo = 1000000000; int tg[M], s1[M], s2[M]; int f[N], sum[N], n, q; void chg(int k, int l, int r, int v) { tg[k] = (tg[k] + v) % mo; s1[k] = (s1[k] + 1ll * v * sum[r - l]) % mo; s2[k] = (s2[k] + 1ll * v * (sum[r - l ...
5
#include <bits/stdc++.h> using namespace std; const int LG = 18, N = 1 << LG, Mod = 998244353, Rn = 3; int rev[N + 5]; inline int Power(int a, int b) { int ret = 1; for (; b; b >>= 1, a = 1ll * a * a % Mod) if (b & 1) ret = 1ll * ret * a % Mod; return (ret); } inline void NTT(int* F, int n, bool inv) { int ...
5
#include <bits/stdc++.h> using namespace std; long long sum[400500]; int a[100500]; int b[100500]; int c[100500]; void build(int v, int l, int r) { int m; if (l == r) { sum[v] = a[l]; return; } m = (r + l) / 2; build(2 * v, l, m); build(2 * v + 1, m + 1, r); sum[v] = sum[2 * v] + sum[2 * v + 1]; }...
1
#include <bits/stdc++.h> using namespace std; long long at[100005], a[100005]; int bmap[64]; vector<int> adj[100005]; int d[100005]; int bestans; queue<int> bq; int bfs(int f, int dst) { while (!bq.empty()) bq.pop(); bq.push(f); d[f] = 1; while (!bq.empty()) { int bf = bq.front(); bq.pop(); for (aut...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; const int oo = 1000000000; const int N = 0; string GetCode(char ch) { switch (ch) { case '>': return "1000"; case '<': return "1001"; case '+': return "1010"; case '-': return "1011"; case '.': ret...
2
#include <bits/stdc++.h> const int inf = 1e9 + 7; const int maxn = 2005; using namespace std; char ma[maxn], mb[maxn]; int main() { int n, k; scanf("%d%d", &n, &k); string s, p; cin >> s; p = s; int q = s.size() / 2; for (int i = 1; i < s.size(); i++) { string t = s.substr(i); string k = s.substr(...
1
#include <bits/stdc++.h> using namespace std; using namespace std; pair<long long int, long long int> p1, p2; long long int n; long long int A[300][3]; long long int solve(long long int i, pair<long long int, long long int> p) { long long int ret = A[i][0] * p.first + A[i][1] * p.second + A[i][2]; return ret; } int...
1
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; int main() { int N, M, X; cin >> N >> M >> X; vector<int> C(N); vector<vector<int>> A(N, vector<int>(M)); rep(i, N) { cin >> C[i]; rep(j, M) cin >> A[i][j]; } int ans = 1e9; rep(bit, 1 << N) { int amount = 0; ...
0
#include <bits/stdc++.h> using namespace std; int mod = 1000000000 + 7; int addm(int& a, int b) { return (a += b) < mod ? (a < 0 ? a += mod : a) : a -= mod; } template <class T, class U> bool smin(T& a, U b) { return a > b ? (a = b, 1) : 0; } template <class T, class U> bool smax(T& a, U b) { return a < b ? (a = ...
6
#include <iostream> #include <string> using namespace std; int main () { int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; int dx = tx - sx; int dy = ty - sy; cout << string(dx, 'R') << string(dy, 'U') << string(dx, 'L') << string(dy, 'D') << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') ...
0
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int l = s.size(); string s1 = "",s2 = ""; int cnt = 0; for(int i = 0;i < l;i++){ s1 += s[i]; if(s1 != s2){ cnt++; s2 = s1; s1 = ""; } } cout << cnt << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s[6] % 2 == 0) cout << 0; else cout << 1; return 0; }
4
#include <iostream> int main() { std::string p, s; std::cin >> p >> s; p = p + p; if(p.find(s) != std::string::npos){ std::cout << "Yes" << std::endl; } else{ std::cout << "No" << std::endl; } }
0
#include<iostream> using namespace std; int main() { int ans=0; int n,k; cin>>n>>k; while(n) { ans++; n=n/k; } cout<<ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; mt19937 mt_rand( chrono::high_resolution_clock::now().time_since_epoch().count()); const long long hashSize = 3; long long mod[hashSize]; const long long N = 2e5 + 50; long long ans = 0; struct hash_number { long long a[hashSize]; hash_number() { fill(a, a + hashSiz...
5
#include <bits/stdc++.h> using namespace std; const int P = 998244353; int power(int a, int b) { int f = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) f = 1ll * f * a % P; return f; } const int N = 550000 * 2; int w1[N], w2[N], rev[N]; void initfft(int n) { int k = 0, nn = n >> 1; while (nn) { ...
6
#include <bits/stdc++.h> using namespace std; int hmt() { int x = 0; int c = getchar(), n = 0; for (; !isdigit(c); c = getchar()) n = (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; if (n) x = -x; return x; } const int N = 300010; int n, m, dd[N], pre[N]; set<int> ke[N]; unsigned long lo...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int money, b1 = 0, b2 = 0; cin >> money; b1 = b2 = money / 3; b1 += (money % 3 == 1) ? 1 : 0; b2 += (money % 3 == 2) ? 1 : 0; cout << b1 << ' ' << b2 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 2002, mod = 1e9 + 7; long long dp1[N][N], dp2[N][N], ans[N], n, k, anss; string s; long long up(char s) { return 'z' - s; } long long down(char s) { return s - 'a'; } int main() { cin >> n >> k; cin >> s; s = ' ' + s; n++, k++; dp1[0][0] = 1; ans[0...
5
#include <bits/stdc++.h> using namespace std; int main() { int cnt2, cnt4, cnt1, n, k, x, l, r, m; scanf("%d %d", &n, &k); cnt1 = cnt2 = cnt4 = 0; l = 2 * n; r = n; m = 0; for (int i = 0; i < k; i++) { scanf("%d", &x); cnt4 += x / 4; x %= 4; cnt2 += x / 2; x %= 2; cnt1 += x; } ...
2
#include <iostream> #define reep(i,n,m) for(int i=(n);i<(m);i++) #define rep(i,n) reep(i,0,n) using namespace std; int main(){ int n; while(cin>>n,n){ int a[101]={0}; rep(i,n){ cin >> a[i]; } int ans=0; rep(i,n){ rep(i,n-1){ if(...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } long long n, m; vector<long long> e[1...
5
#include<bits/stdc++.h> using namespace std; int n; int main(){ cin >> n; cout << n/2+n%2 << endl; }
0
#include <bits/stdc++.h> using namespace std; const int N = 100005, M = 200005; struct Tree { int tot, lnk[N], son[M], nxt[M]; int n, len, q[N], sz[N], fa[N]; long long sum, mxs, s[N], f[N], g[N]; Tree() { len = tot = sum = mxs = 0; memset(lnk, 0, sizeof(lnk)); } int read() { int x = 0; char...
5
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 1; int main() { int n; cin >> n; vector<int> a(n); map<int, int> mp; long long Ans = 0; for (int &x : a) { scanf("%d", &x); if (mp.find(-x) != mp.end()) { Ans += mp[-x]; } mp[x]++; } cout << Ans; }
2
#include <bits/stdc++.h> #define MOD 1000000007 #define ll long long #define cy cout << "YES" << endl #define cn cout << "NO" << endl #define all(v) v.begin(), v.end() #define fo(i, n) for (int i = 0; i < n; i++) #define fok(i, k, n) for (int i = k; i < n; i++) #define pb push_back #define FLASH ios_base::sync_with_std...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; char a[MAXN]; int sum[MAXN][3]; int main() { int n; cin >> a; n = strlen(a); for (int i = 1; i <= n; i++) { sum[i][0] = sum[i - 1][0]; sum[i][1] = sum[i - 1][1]; sum[i][2] = sum[i - 1][2]; sum[i][a[i - 1] - 'x']++; } int ...
1
#include <bits/stdc++.h> #define r(i,n) for(long long i = 0; i<n; i++) typedef long long ll; using namespace std; int main() { int n,ans; cin >> n; ans=n; r(i,n+1){ int t=i,count=0; while(t){ count+=t%6; t/=6; } t=n-i; while(t){ count+=t%9; t/=9; } ans=min(ans...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i, j, k, l, m, n; cin >> n; vector<int> arr(n + 1); int t = (1 << 22); vector<int> dp(t, -1); for (i = 0; i < t; i++) dp[i] = -1; for (i = 1; i <= n; i++) { cin >> arr[i]; dp[arr[i]]...
5
#include <bits/stdc++.h> int l, d, v, g, r, cnt; int main() { scanf("%d%d%d%d%d", &l, &d, &v, &g, &r); double pre = 1. * d / v; for (; pre > g + r; cnt++) pre -= g + r; printf("%.12lf\n", pre < g ? 1. * l / v : 1. * (l - d) / v + (cnt + 1.) * (g + r)); }
2
#include <iostream> using namespace std; int n, a, mx, md, fl=1, c[105]; int main() { int i; cin>>n; for(i=0; i<n; i++) { cin>>a; c[a]++; mx = max(mx, a); } md = (mx+1)/2; if(c[md] != mx%2+1) fl = 0; for(i=md+1; i<=mx; i++) if(c[i]<2) fl = 0; cout<<(fl ? "P":"Imp")<<"ossible"; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=200010; ll a[N],k; int n; map<ll,ll> mp; int main() { cin >> n >> k; for(int i=1;i<=n;i++) { cin >> a[i]; a[i]+=a[i-1]; } ll ans=0; for(int i=0;i<=n;i++) { if(i>=k) mp[(a[i-k]-i+k)%k]--; ...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const int MAX = 1e6 + 5; const long long MOD = 1e9 + 7; const long double eps = 1e-9; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename T> inline T abs(T a) {...
6
#include <bits/stdc++.h> using namespace std; namespace IO { const int MAXIOSIZE = 1 << 24 | 1; unsigned char buf[MAXIOSIZE], *p1, *p2; template <typename T> void read(T& x) { x = 0; char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++); bool...
2
#include <bits/stdc++.h> using namespace std; const int N = 2010; int e[N][N], mn, n; bool vis[N]; long long dis[N]; int main() { scanf("%d", &n); mn = 1e9; for (int i = (0); i <= (n); ++i) dis[i] = 1e18; for (int i = (1); i <= (n); ++i) for (int j = (i + 1); j <= (n); ++j) scanf("%d", &e[i][j]), e[j]...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000100; int n, k, a[MAXN]; int main() { cin >> n >> k; if (k * 3 <= n && k != 1) { for (int i = 1; i <= n; i++) { a[i] = ceil(i / 2); if (i % 2 == 0) { a[i] = i / 2; } } for (int i = k * 2 + 1; i <= n + 1; i++) { ...
3
#include <cstdio> #include <cstdlib> #include <algorithm> typedef long long i64; const int N = 500000 + 10; int n, m, d[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &d[i]); static int a[N], b[N]; a[0] = m; for (int i = 1; i <= n; ++i) a[i] = std::min(a[i - 1], abs(a[i -...
0
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; struct edge { ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int zero, one; char s[maxn]; vector<string> ans; int main() { scanf("%s", s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; i++) { if (s[i] == '0') zero++; if (s[i] == '1') one++; } if (n & 1) { if (one <= n / 2) ans.push_...
3
#include <bits/stdc++.h> using namespace std; const int N = 305; const int dir[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}}; int dp[N * 2][N][N], adj[N][N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &adj[i][j]); for (int i = 0; i < 2 * n; i++) f...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p, n, t, i, a[101], maxd = 1; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); cin >> t; for (i = 0; i < n; i++) { if (a[i] + t >= a[n - 1]) { if (n - i > m...
2
#include <bits/stdc++.h> using namespace std; int c[21][100010]; int cn[21], d; int p[100010]; bool a[21][1 << 20]; vector<int> e[1 << 20]; int dp[1 << 21]; bool find(int ci, int x) { int l = -1, r = cn[ci] - 1, z; if (r < 0 || c[ci][r] <= x) return false; while (l + 1 < r) { z = (l + r) >> 1; if (c[ci][z...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100001; int n,m,s,t,d[MAX_N],a[MAX_N],b[MAX_N],dist[MAX_N]; vector<int> e[MAX_N]; typedef pair<int,int> P; int cal(){ priority_queue<P,vector<P>,greater<P> > Q; for(int i=0;i<n;i++)dist[i]=1e9; Q.push(P(0,s)); dist[s]=0; int head=0; ...
0
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } int h, w, q; char buf[505][505]; int ans[1000005]; struct query_ { int y1, x1, y2, x2; int id; }; bitset<505> able[2][505][505]; void r...
5
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int a[n]; long long int flag = 0; long long i...
1
#include<iostream> #include<vector> #include<algorithm> #include<iomanip> #include<cstdio> #define DIF 5000 #define all(n) n.begin(),n.end() using namespace std; void draw(vector<vector<bool> >& graph,int sx,int sy,int ex,int ey) { for(int i=sy;i<ey;i++) for(int j=sx;j<ex;j++) graph[i][j] = true; } int ma...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; // sando: 0+N // katsu: 100000+N // karee: 200000+N // katsusan: 300000+N // katsukare: 400000+N int x, y, z, n, m, s, t; vector<int> G[500005]; int dist[500005]; void addedge(int u, int v) { G[u].push_back(v), G[v].push_back(u);...
0
#include <bits/stdc++.h> using namespace std; int node = 0; int t[100005][30]; bool win[100005], lose[100005]; void Insert(string a) { int len = a.size(); int k = 0; for (int i = 0; i < len; i++) { int c = a[i] - 'a'; if (t[k][c] == 0) { t[k][c] = ++node; } k = t[k][c]; } } void dfs(int v)...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define REP(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--) #define MOD 1000000007 int n; char s[2521]; ll dp[2521][2521]; ...
0
#include<bits/stdc++.h> using namespace std; int a[100]; int main() { int b; while (cin >> b, b) { for (int c = 0; c<b; c++)scanf("%d", &a[c]); int sum = 0; for (int d = 0; d < b - 1; d++) { for (int e = d + 1; e < b; e++) { if (a[d] > a[e])sum++; } } cout << sum << endl; } }
0
#include <bits/stdc++.h> using namespace std; vector<int> zero; int main() { int n, k; int rl[100005][2]; char s[100005]; scanf("%d %d", &n, &k); scanf("%s", &s); for (int i = 0; i < n; i++) { if (s[i] == '0') zero.push_back(i); } int l = 0, m = l, r = l; int res = 199999; r = 0 + k; while (r ...
3
#include <bits/stdc++.h> using namespace std; int n; int legs[100005]; vector<int> E[100005]; vector<int> leafs; bool vis[100005]; bool deleted[100005]; int deg(int u) { return E[u].size(); } void findL(int u) { vis[u] = true; if (E[u].size() == 1) leafs.push_back(u); for (int i = 0, v; i < E[u].size(); i++) { ...
5
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[555][555]; long long b[555][555]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= m; j++) { cin >> a[i][j]; } } for (long long i = 1; i...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long n, len, a[N], K, pre[N]; long long ans; multiset<long long> s1, s2; void solve() { long long sum = 0; multiset<long long>::iterator it; for (int i = 1; i <= n; i++) { if (a[i] >= 0) sum += a[i]; else { if (s1.size(...
3
#include <bits/stdc++.h> using namespace std; signed main(){ int n; cin >> n; int xo[n]; int allxor = 0; for(int i = 0; i < n; i++){ cin >> xo[i]; allxor ^= xo[i]; } for(int i = 0; i < n; i++){ xo[i] ^= allxor; cout << xo[i] << " "; } return 0; }
0
#include <bits/stdc++.h> using namespace std; char s[10]; int main() { map<int, int> A; map<int, char> B; int n, m; scanf("%d%d", &n, &m); while (m--) { int x, y, z = 0; scanf("%d%d%s", &x, &y, s); if (A.find(x) != A.end()) { puts("0"); continue; } if (s[0] == 'L') { auto...
3
#include <bits/stdc++.h> using namespace std; int l[100005], r[100005], t[100005]; int main() { int n, m, s, f; scanf("%d%d%d%d", &n, &m, &s, &f); for (int i = 0; i < m; ++i) { scanf("%d%d%d", t + i, l + i, r + i); } int ind = 0, pos = s, j, dir, c; if (f > s) { dir = 1; c = 1; } else { di...
2
#include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; vector<int> v(n); for (auto& x : v) cin >> x; vector<vector<int>> dp(n, vector<int>(n, n)); for (int i{0}; i < n; ++i) dp[0][i] = 0; for (int i{1}; i < n; ++i) { int cnt{0}; for (int j{i - 1}; j >= 0; --j) if (j ...
6
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int N = 100005, E = 262144; int n, m, i, u, v, p, t, vis[55][55], j, k; vector<int> g[55][55]; int q[N], l, r; vector<int> ansr, ansl; long long dp[105][55][2]; bool flag1 = true; int main() { scanf("%d %d", &n, &m); for (i = 1; i <= m; +...
5
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { int n; cin >> n; int arr[n + 10]; for (int i = 0; i < n; i++) cin >> arr[i]; int ons = 0; for (int i = 0; i < n; i++) ons += arr[i]; if (ons == n) { cout << n - 1 << endl; continue; } ...
1
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const int MAXSZ = 50; const int MAXN = MAXSZ; const int MAXMOVE = 10800; struct Move { int sx, sy, ex, ey; Move() {} Move(int sx, int sy, int ex, int ey) : sx(sx), sy(sy), ex(ex), ey(ey) {} }; int sz, n; int...
5
#include <bits/stdc++.h> #define pb push_back using namespace std; const int MAX_N = 2e5 + 5; vector< int > g[MAX_N]; int main() { int n, m; scanf(" %d %d", &n, &m); for(int i = 0; i < m; i++) { int u, v; scanf(" %d %d", &u, &v); g[u].pb(v); g[v].pb(u); } for(int nb1 : g[1]) { for(int nb2 : g[nb1])...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, dienos = 0; cin >> n >> m; while (n > 0) { dienos++; n--; if (dienos % m == 0) n++; } cout << dienos << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[100010]; int n; long long dp[100010]; int main() { cin.tie(nullptr); cin.sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { int b; cin >> b; a[b]++; } dp[0] = a[0]; dp[1] = max(a[0], a[1]); for (long long i = 2; i < 100010; i++...
1
#include <bits/stdc++.h> using namespace std; int n, cnt; pair<int, int> valp[150010]; struct node { int p, t, pp; } a[150010]; long long T, tl[150010], tr[150010]; double l, r, mid, t[150010]; const double inf = (1e18); void add(int x, double v) { for (; x; x -= (x & -x)) t[x] = min(t[x], v); } double query(int x)...
5
#include <bits/stdc++.h> using namespace std; int N; vector<int> fo[5010]; bool used[5010]; int dfs(int vr) { used[vr] = true; int SZ = 1; for (int i = 0; i < ((int)(fo[vr]).size()); ++i) if (!used[fo[vr][i]]) SZ += dfs(fo[vr][i]); return SZ; } int ANS[5010], cur[5010]; int main() { scanf("%d", &N); for...
5
#include<iostream> #include<vector> using namespace std; #define repeat(i,n) for(int i=0;i<(n);i++) int main(){ int theta; cin>>theta; cout<<theta/30<<' '<<theta%30*2<<endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef pair<P,P> P1; int G[4][4],sum,ans=6; int X[6][4][4]; int dy[4]={-1,0,1,0}; int dx[4]={0,1,0,-1}; int tim[4][4]; void dfs(int dep,int s){ if(dep==6)return; for(int i=0;i<4;i++) for(int j=0;j<4;j++){ int cnt=0; if(!G[i][j])...
0
#include <bits/stdc++.h> using namespace std; int SortedData[100]; int main() { int n, k, cnt, left, right, mid; while (cin >> n, n) { for (int i = 0; i < n; i++) { cin >> SortedData[i]; } cin >> k; left = 0; right = n - 1; cnt = 0; while (1) { ++cnt; mid = (left + right) / 2; if (Sorte...
0
#include <bits/stdc++.h> using namespace std; int ara[1000006], val[1000006], b[1000006]; bool chck(int n, int mid) { vector<int> v1, v2; for (int i = 0; i < n; i++) b[i] = ara[i]; for (int i = mid - 1; i >= 0; i--) { int x = val[i], cnt = 0; while (i >= 0 && val[i] == x) cnt++, i--; i++; v1.empla...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e7 + 7; const int MXN = 1e6 + 1; const int N = 1e3 + 1; int a, b, second; int main() { cin >> a >> b >> second; int ans = abs(a) + abs(b); if (ans <= second) { if (second % 2 == ans % 2) cout << "Yes"; else cout << "No"; } else ...
1
#include<bits/stdc++.h> using namespace std; const int N = 100005; int n, m; bool vis[N]; vector<int> adj[N], p1, p2; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { int A, B; scanf("%d%d",&A,&B); adj[A].push_back(B); adj[B].push_back(A); } p1.push_back(1); vis[1] = true; for(int i=1;;) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int X = 1e7 + 5; int F[X]; vector<int> adj[N]; int A[N]; int leaf; int dep[N]; void dfs(int v, int p, int d) { dep[v] = (d & 1); int c = 0; for (auto u : adj[v]) { if (u == p) continue; dfs(u, v, d + 1); c++; } if (c == 0) ...
5
#include <iostream> #include <vector> #include <string> using namespace std; typedef pair<string, int> P; void solve() { int n; bool flag = false; while(cin >> n, n) { if(flag) { cout << endl; } flag = true; vector<P> data(n); int temp[3]; for(int i = 0; i < n; ++i) { cin >> data[i].first >> ...
0
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, Q; int mn[N * 4], mx[N * 4], fl[N * 4]; set<int> SL[N], SR[N]; map<pair<int, int>, int> mp; void pushup(int k) { mn[k] = max(mn[k * 2], mn[k * 2 + 1]); mx[k] = min(mx[k * 2], mx[k * 2 + 1]); fl[k] = fl[k * 2] | fl[k * 2 + 1] | (mn[k * 2...
6
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn=1e4; const int mod=998244353; int n,m,len,ans; char S1[maxn+8],S2[maxn+8]; int fac[maxn+8],fact[maxn+8],f[maxn+8][maxn+8]; int read() { int x=0,f=1;char ch=getchar(); for (;ch<'0'||ch>'...
0
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int n,l,r,t; long long s,dis[1000005],ans; struct node { long long len,num; }q[1000005]; bool cmp(node t1,node t2) { return t1.len<t2.len; } int main() { scanf("%d%lld",&n,&s); for (int i=1;i<=n; i++) sc...
0
#include<bits//stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; cout<<min(a+b,min(b+c,a+c)); }
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } const ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; if ((m >= n) && (k >= n)) { cout << "Yes"; } else { cout << "No"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; struct edge { int u, v, next; } edge[maxn * 2]; int head[maxn], cnt; int n, m, q; vector<int> person[maxn][20]; vector<int> city[maxn]; void addedge(int u, int v) { edge[cnt].u = u; edge[cnt].v = v; edge[cnt].next = head[u]; head[u] = cnt+...
3
#include <algorithm> #include <bitset> #include <iostream> #include <numeric> #include <vector> using namespace std; int main() { const auto primes = [] { bitset<1000000 + 1> b; auto t = b; t.set(); t[0] = false; t[1] = false; int i = 0; while (true) { ...
0
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const long long INF = (long long)(inf)*inf; const long long mod = 1000000000 + 7; const int maxn = 100000 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); int t, n; string s; cin >> t; while (t--) { cin >> n; cin >> s; ...
1
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (!y) return x; return gcd(y, x % y); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool sortbysecinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.second > b.second);...
2
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7; const long long mod = 1e9 + 7; long long cnt[N]; long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) { res = res * a % mod; } a = a * a % mod; b >>= 1; } return res; } long lon...
5
#include <bits/stdc++.h> using namespace std; const int mod = 998244853; const int N = 2001; int n, m, f[N][N][2], res; int main() { ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); cin >> n >> m; f[0][0][0] = f[0][0][1] = 1; for (int k = 1; k <= n + m; k++) for (int i = max(0, k - m); i <= min(n, ...
5
#include <bits/stdc++.h> using namespace std; const long long m = 1000 * 1000 * 1000 + 7; int main() { string s; cin >> s; cout << s; reverse(s.begin(), s.end()); cout << s; }
2
#include <bits/stdc++.h> using namespace std; const int S = 13; const int Full = (1 << S) - 1; int prime[50] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}, tot = 25; char block[800][1 << S][25]; int mm[10010][26], to[100000]; unsigned long lo...
5
#include <bits/stdc++.h> using namespace std; long long int T, n; int main() { ios::sync_with_stdio(false); cin >> T; while (T--) { cin >> n; if (n == 1) cout << "FastestFinger\n"; else if (n == 2) cout << "Ashishgup\n"; else if (n % 2) cout << "Ashishgup\n"; else { lon...
3
#include <bits/stdc++.h> using namespace std; vector<int> E[555555], W[555555]; vector<long long> G[555555]; int T, N, K, A[555555]; long long F[555555][2]; void dfs(int x, int f) { F[x][1] = 0; F[x][0] = 0; int cnt = E[x].size(); for (int i = 0; i < cnt; i++) { int nx = E[x][i]; if (nx != f) { df...
3
#include<iostream> #include<sstream> using namespace std; template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();} int main() { int m; cin>>m; for(;m--;) { long long int money; cin>>money; int year; cin>>year; int n; cin>>n; long l...
0
#include <bits/stdc++.h> using namespace std; int *compute_lps(vector<int> &pat); int search_kmp(vector<int> &txt, vector<int> &pat, int *lps); int main() { int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; vector<int> txt, pat; if (...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[100000]; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n - 1; i++) cout << arr[i] + arr[i + 1] << " "; cout << arr[n - 1] << endl; }
1
#include <bits/stdc++.h> using namespace std; int n, m; string ans, sr; multiset<string> s; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { getchar(); string str, rstr; for (int j = 0; j < m; j++) { char c = getchar(); str.push_back(c); rstr.push_back(c); } r...
2
#include <iostream> #include <vector> using namespace std; int N, K, tmp; void solve() { vector<int> bloods(K), family(K); for (int i = 0; i < K; i += 1) cin>>bloods[i]; for (int i = 0; i < N; i += 1) { for (int j = 0; j < K; j += 1) { cin>>tmp; family[j]+=tmp; } } // calc for (int i =...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int main() { string s; cin >> s; int k; int n = s.size(); cin >> k; int res = 0; for (int i = 0; i < n; i++) { for (int j = 1; i + 2 * j - 1 < n + k; j++) { bool flag = 1; for (int u = 0; u < j && i + j + u < n; u++) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> v(m); for (int i = 0; i < m; i++) { cin >> v[i]; } int aq = 1; long long ans = 0; for (int i = 0; i < m; i++) { if (v[i] == aq) continue; if (v...
2
#include <bits/stdc++.h> using namespace std; enum { MAXN = 550, INF = 2000000000 }; int sum[MAXN][MAXN]; int sumSpiral[MAXN][MAXN]; int field[MAXN][MAXN]; int ans = -INF; int getSum(int x1, int y1, int x2, int y2) { int val = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1]; return val; ...
3
#include <bits/stdc++.h> using namespace std; int n = 3000; bool arr[3002]; int ar[3002]; void prime() { for (int i = 2; i < n; i += 2) { arr[i] = 1; } arr[2] = 0; for (int j = 3; j * j < n; j++) { if (!arr[j]) for (int i = j * j; i < n; i += j) arr[i] = 1; } } void getall(int x) { ar[6] = 1; ...
2