solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; vector<int> prefix[30]; int main() { ios_base::sync_with_stdio(false); int test; cin >> test; while (test--) { int n, m; string s; cin >> n >> m >> s; for (char c = 'a'; c <= 'z'; c++) { prefix[c - 'a'] = vector<int>(n + 1); for (int i = ...
3
#include <iostream> using namespace std;int main(void){int A, B, C;cin>>A>>B>>C;cout<<(A+B<C?"No":"Yes")<<endl;}
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; #define ll long long #define ull unsigned long long #define rep(i,n,N) for(ll i=n;i<=N;++i) #define rap(i,n,N) for(int i=n;i>=N;--i) #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #defi...
0
#include <bits/stdc++.h> using namespace std; const int mxn = 1005; const int mxm = 3005; int n, m; char str[mxn]; bool valid[mxn][mxm]; inline void print(int p) { stack<char> ans; for (int i = n; i; --i) switch (str[i - 1]) { case 'L': ans.push('L'); p = p + 1; break; case 'W': ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long x1, x2, y1, y2; long long a, b, c; cin >> x1 >> y1 >> x2 >> y2; int n; cin >> n; int ans = 0; while (n--) { scanf("%lld%lld%lld", &a, &b, &c); if (((a * x1 + b * y1 + c) / abs(a * x1 + b * y1 + c)) * ((a * x2 + b * y2...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); string s; char c[6] = {'a', 'e', 'i', 'o', 'u', 'y'}; long long int i, n, x, y, j; cin >> n >> s; for (i = 0; i < s.length() - 1; i++) { x = 0; y = 0; for (j = 0; j < 6; j++) { if (s[i] == c[j]) { x...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000005; long long modd = 998244353; vector<bool> isprime(N); vector<int> primes; void seive() { isprime[0] = false; isprime[1] = false; for (int i = 2; i <= 1e6; i++) { isprime[i] = true; } for (int i = 2; i * i <= 1e6; i++) { if (isprime[i]...
1
#include <bits/stdc++.h> using namespace std; long long int m, n, k, p1, p2, p3, p, f, a[120][120], b[120][120], mi[120]; string s, s1, s2; vector<int> r, c, r1, c1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < 120; i++) { mi[i] = 1200; } for (...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, k; cin >> n >> m >> k; if (m >= n && k >= n) { cout << "YES"; } else { cout << "NO"; } cout << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int num; cin >> num; vector<int> answers; answers.emplace_back(1); for (int power = 1; power <= 9; power++) { int start = (int)(pow(10, power) + 1e-9); if (num < start) { cout << answers.size() << "\n"...
3
#include <bits/stdc++.h> using namespace std; int n; int a[2007], b[2007], p[2007], h[2007]; vector<int> ch[2007]; // 0 - white // 1 - red // 2 - blue int type[2007]; int cntred = 0; bool active[2007]; vector<int> res; void rotate(int w) { res.push_back(w); memcpy(b, a, sizeof a); b[w] = a[0]; while(w) { b[p...
0
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const int si[4] = {-1, 0, +1, 0}; const int sj[4] = {0, +1, 0, -1}; const int MOD = 5000011; int main() { string s; cin >> s; vector<pair<string, int> > a; int i = 0; int j = 0; while (i < s.size()) { string t = ""; while (s[j] !...
5
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; ll h,w; int main(int argc, char const *argv[]) { int T; scanf("%d", &T); for(int unko=0;unko<T;unko++){ string s; cin >> s; stack<int> po; int num = 0; for(int i=0;i<s.size();i++){ if(s[i] == '['...
0
#include <bits/stdc++.h> using namespace std; vector<int> v; void dfs(deque<long long int> q, int m) { if (m == 1) { v.push_back(max(q.back(), q.front())); return; } deque<long long int> p, r; r = q; p = q; r.pop_front(); p.pop_back(); dfs(r, m - 1); dfs(p, m - 1); return; } int main() { s...
1
#include <bits/stdc++.h> int prime = 100003; long long N, M; int main() { std::cin >> N >> M; std::cout << prime << " " << prime << "\n"; for (int i = 1; i <= N - 2; ++i) std::cout << i << " " << i + 1 << " " << 1 << "\n"; std::cout << N - 1 << " " << N << " " << prime - N + 2 << "\n"; M -= N - 1; for (...
3
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int n, t, a, b, x; string s; vector<int> v; int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &a, &b); int ans = 0; while (a != 0 && b != 0) { if (a >= b) { ans += a / b; a %= b; } else { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b; scanf("%d%d", &n, &m); if (n <= 6) printf("%d", m); else { vector<vector<int>> d(8, vector<int>(8, 0)); for (int i = 0; i < m; i++) scanf("%d%d", &a, &b), d[a][b] = 1, d[b][a] = 1; int mn = 21; for (int i = 1; i <= 7;...
1
#include <bits/stdc++.h> using namespace std; long long dp[100001] = {0}, mod = (long long int)1000000007; long long extgcd(long long a, long long b, long long &x, long long &y) { long long g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; } long long invMod(long long a,...
3
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> p) { os << "{ "; for (auto i : p) { o...
6
#include <bits/stdc++.h> using namespace std; double PI = (acos(-1)); long long md = 1000000007; long long pw(long long a, long long b) { long long c = 1, m = a; while (b) { if (b & 1) c = (c * m); m = (m * m); b /= 2; } return c; } long long pwmd(long long a, long long b) { long long c = 1, m = a...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i, j = 0, n, k = 0, l = 0; string s; cin >> s; for (i = 0; i < s.length(); i++) { if (isupper(s[i])) { j++; } else { k++; } } if (j > k) { transfo...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } long long int k; long long int b[n]; for (int i = 1; i < (n - 1); i++) { k = ((a[0][i + 1]) * (a[...
2
#include <bits/stdc++.h> int main() { int n; std::cin >> n; long long int sum[100010] = {0}, v[100010], t[100010]; for (int i = 0; i < n; ++i) std::cin >> v[i]; for (int i = 0; i < n; ++i) std::cin >> t[i]; sum[0] = t[0]; for (int i = 1; i < n; ++i) { sum[i] += sum[i - 1] + t[i]; } long long int a...
2
#include <bits/stdc++.h> using namespace std; int main(){ string s; for(int i=0;i<3;i++){ cin>>s; cout<<s[i]; } return 0; }
0
//0066 #include<stdio.h> int main(void) { const int N = 9; char str[N+1]; while(scanf("%s", str) == 1) { const char ca[] = "ox"; char findC = 'd'; for(int i = 0; i <= 1; i++) { const char c = ca[i]; if( (c == str[0] && c == str[1] && c == str[2]) || (c == str[3] && c == str[4] && c == str[5])...
0
#include <bits/stdc++.h> using namespace std; long long dp[19][2][1 << 8][2520]; bool okey[1 << 8][2520]; int mul[20]; int dig[20]; int n; long long dfs(int pos, int U, int st, int sum) { if (pos == -1) { return okey[st][sum]; } long long &ret = dp[pos][U][st][sum]; if (ret != -1) return ret; int end = 9;...
4
#include <bits/stdc++.h> using namespace std; int a[100]; int main() { long long n, l, r; cin >> n >> l >> r; if (n == 0) return 0 * printf("0\n"); int i = 0; while (n) { a[i++] = n % 2; n >>= 1; } i--; int len = i; int sum = (r - l + 1) / 2; if (((r - l + 1) & 1) && r & 1) sum++; long lon...
2
#include <bits/stdc++.h> using namespace std; int n; vector<int> adj[1100000]; int arr[1100000][2], ans[1100000]; bool vis[1100000]; void DFS(int p, int b) { vis[p] = 1; ans[p] = b + 1; for (int i = 0; i < adj[p].size(); i++) { int nx = adj[p][i]; if (vis[nx]) continue; DFS(nx, b ^ 1); } } int main(...
5
#include <bits/stdc++.h> using namespace std; inline double get_y(double xx, double yy, double mi) { return yy - xx / tan(mi); } int main() { double y1, y2, yw, xb, yb, r; cin >> y1 >> y2 >> yw >> xb >> yb >> r; double lo = 0, hi = atan2(xb, yw - r - yb), mi; for (int it = 0; it < 10000; it++) { mi = (lo ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<long long> fib(200); fib[0] = 1; fib[1] = 1; for (int i(2); i < (103); ++i) fib[i] = (fib[i - 1] + fib[i - 2]) % (int(1e9)); cin >> n >> m; vector<int> d(n); for (int i = 0; i < (n); ++i) cin >> d[i]; for (int q = 0; q < (...
5
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...); } int32_t m...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; set<int> s; int n; cin >> n; int temp; for (int i = 0; i < n; i++) { cin >> temp; s.insert(temp); } vector<int> v; set<int>::iterator it; if (s.size() == 1) { ...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; vector <P> e; ll p,q; int main(){ int w,h; cin>>w>>h; for(int i=0;i<w;i++){ cin>>p; e.push_back(P(p,0)); } for(int i=0;i<h;i++){ cin>>q; e.push_back(P(q,1)); } sort(e.begin(),e.end()); int hc=-...
0
#include "iostream" #include <algorithm> using namespace std; int partition(int A[],int p,int r){ int x = A[r]; int i = p - 1; for(int j = p ; j < r ; j++){ if(A[j] <= x){ i=i +1; swap(A[i],A[j]); } } swap(A[i+1],A[r]); return i + 1; } int main(){ int n,m; int A[1000000]; cin >>...
0
#include <iostream> #include <string> #include <cctype> using namespace std; int dx[] = {-1, 0}; int dy[] = {0, -1}; string getMax(string a, string b) { if(a.size() != b.size()) return (a.size() < b.size() ? b : a); for(int i=0; i<a.size(); i++) if(a[i] != b[i]) return (a[i] < b[i] ? b : a); return a; } strin...
0
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a0, a1, b0, b1; int ct[200010], ct2[200010]; char a[200010], b[200010]; scanf("%s", a); scanf("%s", b); int sa = strlen(a), sb = strlen(b); for (int i = 0; i < sa; ++i) { if (a[i] == '0') a0.push_back(i); else a1.pu...
2
#include <bits/stdc++.h> using namespace std; string s, ans; int n, k, lo, hi; bool sat(int x) { int occ[26], ret = 0; memset(occ, 0, sizeof(occ)); int len = s.length(); for (int i = 0; i < len; i++) occ[s[i] - 'a']++; for (int i = 0; i < 26; i++) ret += ((occ[i] + x - 1) / x); return ret <= n; } int main()...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int arr[maxn]; string ans; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); while (cin >> n) { for (int i = 1; i <= n; ++i) { cin >> arr[i]; } ans = ""; int l = 1, r = n; int last = 0; w...
3
#include <bits/stdc++.h> using namespace std; int z[1000010]; void vector_mul(int *x, int *y, int n) { for (int i = 0; i < n; i++) z[i] = x[y[i]]; for (int i = 0; i < n; i++) x[i] = z[i]; } int t[1000010]; void vector_pow(int *x, int n, int k) { for (int i = 0; i < n; i++) t[i] = i; while (k) { if (k & 1) v...
3
#include<bits/stdc++.h> #define IL inline #define _ 200005 #define ll long long using namespace std; IL int gi(){ int data=0,fu=1; char ch=0; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')fu=-1,ch=getchar(); while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar(); return data*fu; } #define m...
0
#include <bits/stdc++.h> using namespace std; map<pair<long long, long long>, pair<long long, long long> > f; long long n; pair<long long, long long> solve(long long n, long long Mlc) { if (n <= 9) { if (n == 0 && Mlc == 0) return {0LL, 0LL}; if (Mlc == 0) return {1LL, 0LL}; if (Mlc >= n) return {1LL, n -...
3
#include <bits/stdc++.h> const int maxn = 100100; using namespace std; struct node { int ls, rs, mx; node() { ls = rs = mx = 0; } } tree[maxn * 40]; int cnt = 0, n, m, root[maxn]; void insert(int &x, int l, int r, int pos, int v) { if (!x) x = ++cnt; tree[x].mx = max(tree[x].mx, v); if (l == r) return; int ...
6
#include <bits/stdc++.h> using namespace std; int ans[1005]; struct node { int pp, ppp; } a[1005]; bool cmp(struct node aa, struct node b) { return aa.pp < b.pp; } int main() { int n, sum; cin >> n; long long summ = 0; cin >> sum; for (int i = 1; i < n; i++) { cin >> a[i].pp; summ += a[i].pp; a[...
1
#include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; int main() { string s, ans="NO"; cin >> s; reverse(s.begin(),s.end()); while(true){ if(s==""){ ans = "YES"; break; }else if(s.find("maerd")==0 || s.find("esare")==0){ s.erase(0,5); }else...
0
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int size[100005]; int main() { int k, b, n, a; int assign, mod = 0, mods = 0; long long ans = 0; size[0] = 1; mp[0] = 0; mods++; cin >> k >> b >> n; long long zero = 0, cost = 0; for (int i = 0; i < n; i++) { cin >> a; zero = (a) ...
5
#include <bits/stdc++.h> using namespace std; vector<int> words[1000009]; int n, c; class FenwickTree { private: vector<int> ft1, ft2; int rsq(vector<int>& ft, int i) { int sum = 0; while (i > 0) { sum += ft[i]; i -= (i & -i); } return sum; } void update(vector<int>& ft, int i, int ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4; char buf[maxn]; int pos[maxn], cnt; long long s[maxn], p[maxn]; long long S[maxn], top; long long calc(int L, int R, long long s[]) { top = 0; for (int i = L; i <= R; i++) { if (s[i] >= 0) S[top++] = s[i]; if (s[i] == -2) { S[top - 1]...
5
#include<bits/stdc++.h> using namespace std; int a[100010],n; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a,a+n+1); cout<<a[n/2+1]-a[n/2]; return 0; }
0
#include<iostream> #include<vector> #include<algorithm> using namespace std; vector<int> V; void solve(){ sort(V.begin(),V.end()); int pos = 0; while(pos < V.size()){ int start = pos; while(V[pos]+1 == V[pos+1] && pos < V.size()-1) pos++; if(start != 0) cout << " "; if(pos-start == 0) cout << ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; long long int min = 100000; int A, B, C; for (int i = 1; i <= 10000; i++) { int temp = a - i; if (temp < 0) temp = temp * (-1); for (int j = i; j <= 2000...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 200005; const double PI = 4 * atan(1); const double eps = 1e-7; const long long oo = 1e10; const int K = 205; long long dp[N][5]; long long num[N][5]; long long n, k; vector<long long> adj[N]; long long ans = 0; void dfs(long long sr...
3
#include <bits/stdc++.h> using namespace std; const int maxi = 1e6 + 10; long long a[maxi]; int n, q; string s; vector<int> v[maxi]; long long sum[maxi]; map<long long, long long> mp; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) s...
2
#include <bits/stdc++.h> using namespace std; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } unordered_map<int, int> mp; int n, p; vector<int> v1; bool valid0(int x) { int cnt = 1, curVal = x - 1; f...
5
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; long long inf = 1e18; queue<int> q1, q2; int dis_1[1001], dis_2[1001]; int vis1[1001], vis2[1001]; vector<int> v[1001]; int main() { int n, m, s, t, k; cin >> n >> m >> s >> t; int x, y; k = m; while (m--) { cin >> x >> y; v[x]...
4
#include <bits/stdc++.h> using namespace std; const int N = 20; const int M = 30; char s[N][M]; int a[N][M], t[N][M], c[N][M]; int dp[(1 << N) + 5]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%s", s + i); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) scanf("%d...
5
#include <bits/stdc++.h> using namespace std; map<long long, long long> ma; map<long long, long long>::iterator it; long long arr[100005], pre[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; pre[0] = 0; for (int i = 1; i <...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, d[maxn]; map<pair<int, int>, set<int> > H; map<pair<int, int>, set<int> > H2; vector<int> E[maxn]; vector<int> ans; void dfs(int x, int y, int id) { int a = min(x, y); int b = max(x, y); ans.push_back(x); for (auto xx : H2[make_pair(...
5
# include<bits/stdc++.h> using namespace std; const int MAX=2e5+5; int n,ans; int a[MAX]; map<int,int> ma; bool use[MAX]; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]),++ma[a[i]]; sort(a+1,a+1+n); for(int i=31;i>=1;--i) { for(int j=1;j<=n;++j) if(ma[a[j]]) { int x=(...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1048576 + 50; const int mod = 1e9 + 7; int n, f[MAXN], pw[MAXN]; void fwt(int *a, int len, int flg) { for (int i = 2; i <= len; i <<= 1) for (int j = 0; j < len; j += i) for (int k = j; k < j + i / 2; ++k) a[k] = (a[k] + 1ll * (flg == 1 ...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long expo_pow(long long x, long long y) { if (y == 0) return 1; y = y % (mod - 1); x %= mod; if (y == 0) y = mod - 1; long long res = 1; while (y) { if (y & 1) res = (res * x) % mod; x = (x * x) % mod; y >>= 1; }...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, N = 1e5 + 10; int n, K, top; int a[N], sta[N], vis[N], las[N], pre[N], f[N]; vector<int> vec[N]; int read() { int ret = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 0; c = getchar(); } while (isdigit(c))...
5
#include <bits/stdc++.h> using namespace std; const int maxd = 18; const int maxn = 500005; int lat[maxn][maxd]; int rmq[maxn][maxd]; int rad[maxn], best[maxn]; int n, N; long long ret; inline int getint() { int ret = 0; char ch; while ((ch = getchar()) && (ch < '0' || ch > '9')) ; ret = ch - '0'; while (...
2
#include<bits/stdc++.h> using namespace std; const int MAXN = 305; const int MAXLOG = 64; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } template <typename T> void chkmin(T &x, T y) {x = min(x, y); } template <typename T> voi...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5050; int n, m, cur, t; double p, dp[2][maxn], ans; int main() { scanf("%d%d", &n, &m); dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { cur ^= 1; memset(dp[cur], 0, sizeof(dp[cur])); scanf("%lf%d", &p, &t); p /= 100; double tmp = 0;...
2
#include <bits/stdc++.h> using namespace std; set<int> factors(long long n) { set<int> fs; for (int i = sqrt(n) + 1 - 1; i >= 1; i--) if (n % i == 0) { fs.insert(-i); fs.insert(-n / i); } return fs; } int main() { ios::sync_with_stdio(false); long long a, b; cin >> a >> b; set<int> fa ...
6
#include <bits/stdc++.h> using namespace std; long long pow_mod(long long x, int k) { long long ans = 1; while (k) { if (k & 1) ans = ans * x % 998244353; x = x * x % 998244353; k >>= 1; } return ans; } long long facd[100005], facv[100005]; void pre(int n) { facd[0] = 1; for (int i = 1; i <= n; ...
6
#include <bits/stdc++.h> using namespace std; struct node { long long l, r; mutable long long v; node() {} node(long long _l, long long _r, long long _v) : l(_l), r(_r), v(_v) {} const bool operator<(const node& x) const { return l < x.l; } }; set<node> s; long long n, m, seed, vmax, op, l, r, x, y; long long...
5
#include <bits/stdc++.h> using namespace std; long long int dx[4] = {-1, 0, 0, +1}; long long int dy[4] = {0, -1, +1, 0}; const long long int LINF = 1e18; const long long int INF = 1e9; const long long int mod = 1e9 + 7; long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; ...
3
#include <bits/stdc++.h> using namespace std; struct triple { int a, b, c; triple() : a(0), b(0), c(0) {} triple(int a, int b, int c) : a(a), b(b), c(c) {} }; template <typename Comparer> bool gen(const vector<triple>& v, Comparer comp, int pos, vector<string>& ans, triple& val) { if (pos == v.size()) ...
4
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int MAX = 100; const int64 INF = numeric_limits<int64>::max(); int64 grid[MAX][MAX]; int64 dp[MAX][MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tc; cin >> tc; for (int _ = 0; _ < tc; _++) { int n, m;...
6
#include <bits/stdc++.h> using namespace std; int kmpS[53], kmpT[53], nextS[53][26], nextT[53][26], dp[1003][53][53], n, m, k; char c[1003], s[53], t[53]; void BuildKMP(char s[], int lengthh, int kmp[], int nextt[][26]) { kmp[1] = 0; int cur; for (int i = 2; i <= lengthh; ++i) { cur = kmp[i - 1]; while (c...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0;i<n;++i) #define REP1(i,n) for(int i=1;i<=n;++i) #define SZ(i) int(i.size()) #ifdef tmd #define IOS() #define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__); template<typename T> void _do(T &...
0
/***************************** ??????????????????????????????dp(?????£????????????) ?????£?????????????¬??????\???????£????????????????????????????????????????????????????????????¨??????1??\????????¬?????§???????????????????????? ????????????3?????§?????°???????????¨????????£????????????n,d???10??\????????£????????§???...
0
#include <bits/stdc++.h> using namespace std; int x[2014], n, k, ans = 0; vector<int> a[2014]; int main() { cin >> n >> k; if (k == 1) { cout << n; return 0; } for (int i = 1; i <= n; i++) { x[i] = 1; for (int j = i * 2; j <= n; j += i) { a[j].push_back(i); } } for (int i = 2; i <=...
4
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { return a < b ? a : b; } struct ball { long long x; long long c; bool operator<(const ball& other) const { return x < other.x; } }; const long long infinity = 2000000000; int n; vector<ball> balls; vector<long long> penalties; ...
5
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 1e6 + 10, mod = 1e9 + 7, mod2 = 2e9 + 7; long long qsm(long long a, long long b, long long mod) { long long ans = 1; for (; b; b >>= 1) { if (b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } int n, p; long...
5
#include <bits/stdc++.h> using namespace std; const int maxs = 500000, key = 1000003; char dat[maxs + 1]; int calcleft(int n, int m) { int i, j, p; int now, temp; int ans = 1; for (i = 0; i < n; i++) { now = 2; for (p = i * m, j = 0; j < m; j++, p++) if (dat[p] == '1' || dat[p] == '2') { i...
3
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> #include<stack> using name...
0
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int N = 100; char str[N]; int n; char a[4]; int Ch(char c) { if ('a' <= c && c <= 'z') return c - 'a' + 1; if ('A' <= c && c <= 'Z') return c - 'A' + 1; return 0; } int main() { a[0] = '@', a[1] = '[', a[2] = '`', a[3] = '{'; scanf("%s...
3
#include <bits/stdc++.h> using namespace std; bool is_upper(long long int x0, long long int y0, long long int x1, long long int y1, long long int X, long long int Y) { return (y1 - y0) * X + (x1 - x0) * y0 - (y1 - y0) * x0 < (x1 - x0) * Y; } bool is_lower(long long int x0, long long int y0, long long in...
5
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; int c1 = 0, c0 = 0; bool f = 0; for (int i = 0; i < x.size(); i++) { if (x[i] == '0') { c0++; } else if (x[i] == '1') { c1++; } if (c0 < 7 && x[i] == '1') { c0 = 0; } if (c1 < 7 && x[i] == ...
1
#include <bits/stdc++.h> using pii = std::pair<long long, long long>; using namespace std; const long long maxm = 20; long long n, m, cnt[maxm][maxm], dp[(1 << maxm) + 5] = {0}; string s; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> s; for (long long i = 0; i < n - 1; i++) { ...
5
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i) #define debug(...) fprintf(stderr, __VA_ARGS__) #define mp make_pair #define x first #define y second #define pb push_back #define SZ(x) (int((x).size())) #define ALL(x) (x).begin(), (x).end() temp...
0
#include <bits/stdc++.h> #include <cstdlib> using namespace std; typedef long long ll; bool isPrime(long long int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if ...
1
#include <bits/stdc++.h> using namespace std; long long dp[55][55][55][55]; long long ara[55]; double f[55]; long long cnt(long long i, long long k, long long sum, long long zawad) { if (i == 0) return (k == 0 && sum == 0); if (k > i || sum < 0) return 0; if (dp[i][k][sum][zawad] != -1) return dp[i][k][sum][zawad...
4
#include <bits/stdc++.h> int main() { int n, count = 0, i; scanf("%d\n", &n); char str[n]; gets(str); for (i = 0; i < n - 10; i++) { if (str[i] == '8') { count++; } } if (count > ((n - 11) / 2)) { printf("YES"); } else { printf("NO"); } }
2
#include <bits/stdc++.h> using namespace std; int main() { bool f[3]; for (int i = 0; i < 3; ++i) cin >> f[i]; f[2] = !f[2]; cout << (f[0] == f[1] && f[1] == f[2] ? "Open" : "Close") << endl; }
0
#include <iostream> #include <algorithm> using namespace std; bool comp(const int& v1, const int& v2) { return v1 > v2; } int main() { bool pr[1000001]; int s, t, a[1001], b[1001], p, q; fill(pr, pr+1000001, true); pr[0] = pr[1] = false; for(int i = 2; i <= 1000000; i++){ if(pr[i]){ for(int j ...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; #define x first #define y second #define bg begin() #define ed end() #define pb push_back #define mp make_pair #define sz(a) int((a).size()) #define R(i,n) for(int i(0);i<(n);++i) #define L(i,n) for(int i((n)-1);i>=0;--i) const int i...
6
#include <iostream> using namespace std; int main(){ string s; cin>>s; int K; cin>>K; for(int i=0;i<s.size();i++){ if(s[i] != 'a' && 'z' - s[i] + 1 <= K){ K -= 'z' - s[i] + 1; s[i] = 'a'; } } K = K % 26; while(K > 0){ s[s.size() - 1] = (s[s.size() - 1] - 'a' + 1) % 26 + 'a'; K--; } cout<<s<<...
0
#include <bits/stdc++.h> using namespace std; int m, n; bool vis[401][401]; bool v[401]; struct xx { int num; int cnt; }; queue<xx> q; struct node { int b[401]; int num; } a[401], c[401]; int bfstrain(int n1) { v[1] = 1; xx x1; x1.cnt = 0; x1.num = n1; q.push(x1); xx xxxx, x2; while (!q.empty()) {...
1
#include <stdio.h> #include <vector> #include <algorithm> #include <queue> using namespace std; namespace MCF{ const int MAXN=120; const int MAXM=2100; int to[MAXM]; int next[MAXM]; int first[MAXN]; int c[MAXM]; long long w[MAXM]; long long pot[MAXN]; int rev[MAXM]; long long ijk[MAXN]; int v[MAXN]; long lo...
0
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } int n; int temp; map<int, int> m; pair<int, int> arr[3]; priority_queue<pair<int, int> > pq; vector<vector<int> > res; int main() { while (cin >> n) { res.clear(); m.clear(); for (int i = 0; i < n; ++i) { cin >> ...
3
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int lcm(long long int a, long long int b) { return (max(a, b) / gcd(a, b)) * min(a, b); } void build() {} long long int modexp(long long int base, long long i...
4
#include <bits/stdc++.h> using namespace std; template <typename T> inline void pv(vector<T> v) { for (T x : v) cout << x << " "; cout << "\n"; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && c...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 998244353; int n, k, l[10], r[10], a[200001], b[200002] = { 0, 1, -1 }; int main() { cin >> n >> k; for (int i = 0; i < k; ++i) { cin >> l[i] >> r[i]; } for (int i = 1; i < n; ++i) { a[i] = (a[i - 1] + b[i]) % mod; for (int...
0
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } int main() { long long n, m, r; cin >> n; long long one = 0, two = 0; vector<long long> a(n); for (auto &i : a) { cin >>...
1
#include <bits/stdc++.h> using namespace std; static struct FastInput { static constexpr int BUF_SIZE = 1 << 20; char buf[BUF_SIZE]; size_t chars_read = 0; size_t buf_pos = 0; FILE *in = stdin; char cur = 0; inline char get_char() { if (buf_pos >= chars_read) { chars_read = fread(buf, 1, BUF...
3
#include <bits/stdc++.h> using namespace std; int main() { int a[200][200] = {{1}, {0, 1}}, n; cin >> n; for (int i = 2, j; i <= n; ++i) { a[i][0] = a[i - 2][0]; for (j = 1; j <= i; ++j) a[i][j] = (a[i - 1][j - 1] + a[i - 2][j]) % 2; } cout << n << '\n'; for (int i = 0; i <= n; cout << a[n][i++] << ...
2
#include <bits/stdc++.h> using namespace std; const int MAXNUM = 500000; const int SM = 300; class Solution { public: Solution() : m(MAXNUM + 1, 0), sm(SM) { for (int i = 0; i < SM; ++i) sm[i].resize(i + 1, 0); } void add(int x, int y) { m[x] += y; for (int i = 1; i <= SM; ++i) sm[i - 1][x % i] += y;...
6