solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int lst[26], res[26]; int sum; void upd(int id, int now) { lst[id] = now; int prv = res[id]; res[id] = (1 + sum) % MOD; sum = ((sum - prv + MOD) % MOD + res[id]) % MOD; } int main() { int n, k; string s; cin >> n >> k >> s; memset(ls...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; string second; int n, t, hc = 0, sc = 0, res = -1; bool first(int m) { int ccnt = hc, tt = 0, bal = m, ot, num = hc, ans = INF, mo = m; queue<int> q; for (int i = 0; i < n; ++i) { if (second[i] == 'S') bal++; if (second[i] == 'H') num--; ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int maxm = 1e6 + 50; const double eps = 1e-10; const int max_index = 62; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; inline int read() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { ...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxn = 2e5 + 5; long long ans[maxn]; void finish() { cout << "NO" << '\n'; ; exit(0); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long a[n + 1], b[n + 1...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct Setup { Setup() { cin.tie(0); ios::sync_w...
2
#include <bits/stdc++.h> using namespace std; bool isGood(int x, vector<int> &v) { if (x == (int)v.size() - 1) return true; if (x % 2 == 0 && v[x] >= v[x + 1]) return false; if (x % 2 == 1 && v[x] <= v[x + 1]) return false; return true; } int main() { ios_base ::sync_with_stdio(false); int n; cin >> n; ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 50010; char s[maxn]; int main() { scanf("%s", s + 1); int len, i, j, k; len = strlen(s + 1); int ll = 0; for (i = 1; i * 2 <= len; i++) { ll = 0; int cnt = 0; for (j = 1; j + i <= len; j++) { s[++ll] = s[j]; if (s[j] == s[j...
4
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; map<pair<int, int>, bool> mp, mp2; int n, m, a[maxn]; int main() { cin >> n >> m; for (int i = 1, a, b; i <=...
1
#include <bits/stdc++.h> using namespace std; void exgcd(int a, int b, int& x, int& y) { if (!b) { x = 1, y = 0; } else { exgcd(b, a % b, y, x); y -= (a / b) * x; } } int inv(int a, int n) { int x, y; exgcd(a, n, x, y); return (x < 0) ? (x + n) : (x); } const int Mod = 998244353; template <const...
5
#include <bits/stdc++.h> using namespace std; int n, r1, r2; vector<vector<int> > g; vector<bool> used; vector<int> anc; void dfs(int from) { used[from] = true; for (int i = 0; i < g[from].size(); i++) if (!used[g[from][i]]) { anc[g[from][i]] = from; dfs(g[from][i]); } } int main() { cin >> n ...
4
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a, b; int main() { scanf("%d%d", &n, &m); for (int i = (1); i < n + 1; i++) { int x; scanf("%d", &x); a.push_back(x); } for (int i = (1); i < m + 1; i++) { int x; scanf("%d", &x); b.push_back(x); } reverse(a.begin(),...
5
#include <bits/stdc++.h> using namespace std; vector<vector<char> > A; vector<vector<pair<bool, pair<int, int> > > > B; int n, m; bool dfs(int x, int y) { int x1 = x - 1; int x2 = x + 1; int y1 = y - 1; int y2 = y + 1; if (A[x1 % n][y % m] != '#') { if (!B[x1 % n][y % m].first) { B[x1 % n][y % m].se...
4
#include <bits/stdc++.h> using namespace std; set<int> one; set<int> two; map<pair<int, int>, int> present; int a, b; int main() { for (int i = 0; i < 8; ++i) { cin >> a >> b; present[make_pair(a, b)] = 1; one.insert(a); two.insert(b); } if (one.size() != 3 or two.size() != 3) { cout << "ugly"...
2
#include<bits/stdc++.h> using namespace std; const int N=2e5+10; struct E{ int x,y,nxt,flag; }mm[N<<2]; int h[N],len,p[N],n,ans[N],cur[N]; bool v[N]; inline int rd(){ int x=0;int f=1;char s=getchar(); while(!isdigit(s)) f=(s=='-'?-1:f),s=getchar(); while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar(); return x*f; }...
0
#include <bits/stdc++.h> using namespace std; using namespace std; int q[500005]; bool cmp(int x, int y) { return x < y; } int main() { int n; scanf("%d", &n); int top = 0; long long ans = 0; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); while (top > 1 && q[top - 2] >= q[top - 1] && q[top ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 212345; int n, c[maxn], par[maxn]; long long dp[maxn][2], s[maxn]; bool vis[maxn][2], sel[maxn]; vector<int> G[maxn]; void dfs(int u) { if (par[u] && G[u].size() == 1) { dp[u][0] = c[u]; dp[u][1] = 0; return; } for (int v : G[u]) if (v...
4
#include<bits/stdc++.h> using namespace std; #define int long long int n,m,val[200100],res; signed main(){ scanf("%lld%lld",&n,&m); for(int i=1;i<=n;i++)scanf("%lld",&val[i]); res+=accumulate(val+1,val+n+1,0ll); for(int i=2;i<=n;i++)val[i]=min(val[i],val[i-1]+m); for(int i=n-1;i;i--)val[i]=min(val[i],val[i+1]+m); ...
0
#include <bits/stdc++.h> using namespace std; string same() { int a; int b; cin >> a; cin >> b; if (a <= b) { if ((a * 2 >= b) && (a + b) % 3 == 0) return "YES"; else return "NO"; } else { if ((b * 2 >= a) && (a + b) % 3 == 0) return "YES"; else return "NO"; } } int...
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; int ans = 1; for (int i = 1; i <= min(a, b); i++) ans *= i; cout << ans; }
1
#include <iostream> using namespace std; int main() { long n,a,b; cin>>n; cin>>a; cin>>b; long s=a+b,p=n/s,r=n-p*s; cout<<(p*a+(r<a?r:a))<<endl; return 0; }
0
#include <iostream> using namespace std; int main(){ int n,s,k; while(cin>>n>>k>>s && n){ int ans=0; for(int mask=0;mask<(1<<n);mask++){ int c=0; for(int i=0;i<n;i++)c+=(mask>>i&1); if(c!=k) continue; int ts=0; for(int i=0;i<n;i++)ts+=...
0
#include <stdio.h> #include <algorithm> #include <utility> using namespace std; typedef long long ll; int main(void) { ll i, j, k, n, d, ans = 0, a; scanf("%lld%lld%lld", &n, &d, &a); d *= 2; pair<ll, ll> m[n], p; ll sum[n + 1], now = 0; for(i = 0; i < n; ++i) scanf("%lld%lld", &m[i].first, &m[i].second), ...
0
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; inline void readchar(char &ch) { while ((ch = getchar()) == ' ' || ch == '\n') ; } inline void read(int &x) { char ch; while ((ch = getchar()) < '0' || ch > '9') ; x = ch - '0'; while ((ch = getchar()) <= '9' && ch >= '0') x = x * ...
3
#include <bits/stdc++.h> using namespace std; int n, m, tt, fa[500005][20]; pair<int, int> a[500005], b[500005]; bool cmp(pair<int, int> i, pair<int, int> j) { return i.first == j.first ? i.second > j.second : i.first < j.first; } int main() { ios::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; i++)...
5
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const long long maxval = 2 * 1000000000LL * 2 * 1000000000LL; long long mul(long long a, long long b) { if (a == 0) return 0; if (b <= maxval / a) return a * b; else return maxval; } lo...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b; int k = 0, flag = 1; scanf("%I64d", &n); while (n % 2 != 1 && k < 2) { n /= 2; k++; } if (n == 1 && (k == 0 || k == 1)) { flag = 0; } else if (k == 2) { a = 3 * n; b = 5 * n; } else { int temp; if (...
3
#include <bits/stdc++.h> int m, n; double h, w, x, y, z, a, b, c, ans; void swap(double *p, double *q) { double s = *p; *p = *q; *q = s; } int main() { int i, j, k; scanf("%lf%lf%lf", &w, &h, &a); if (a > 90) a = 180 - a; if (h > w) swap(&w, &h); a = a * 2 * acos(-1) / 360; if (2 * atan(h / w) > a) { ...
3
#include <bits/stdc++.h> using namespace std; const int MaxX = 100 + 5, LogN = 32 + 5, MaxN = 100 + 5, MaxM = 300 + 5, INF = 0x3fffffff; int n, m, MaxFlow, Ans, S, T, Tot, a, b; int A[MaxX], d[MaxN], Num[MaxN], B[MaxN][3]; inline int gmin(int a, int b) { return a < b ? a : b; } inline int gmax(int a, int b) {...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int INF = 2e9 + 10; const long double EPS = 1e-9; const int M = 1e2 + 12; const int N = 4e5 + 10; vector<int> v[N]; int a[N], cur[N]; int nxt(int col) { if (cur[col] >= v[col].size()) return INF; else return v[col][cur[col]];...
1
#include <bits/stdc++.h> using namespace std; int n, m, x, y, tot, a, b, f[4][10000000], dx, dy; char ch[5]; long long ans; int solve(int x, int y) { if (x == 1) a = 0, b = y; else if (x == n) a = 1, b = y; else if (y == 1) a = 2, b = x; else if (y == m) a = 3, b = x; if (!f[a][b]) f[a][b] = 1...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { ...
0
#include <bits/stdc++.h> using namespace std; bool cmp(pair<string, int>& a, pair<string, int>& b) { return a.second < b.second; } long long gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(int a, int b) { return (a / gcd(a, b)) * b; } bool isprime(long long a) { for (int i = 2; i...
2
#include <bits/stdc++.h> using namespace std; inline long long rd() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x; } const int MOD = 998244353; inline void add(int &a, int b) { a += ...
5
#include <bits/stdc++.h> using namespace std; int b[101][101]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; while (t--) { int n, m, x, y, p = 0; cin >> n >> m >> x >> y; cout << x << " " << y << endl; b[x][y] = 1; for (int i = y; i <= m; i++...
2
#include<cstdio> using namespace std; int main(){ int n,s; while(true){ scanf("%d%d",&n,&s); if (n==0)break; int r[101]={0}; for(int i=0;i<n;i++){ int tmp;scanf("%d",&tmp);r[tmp]++; } int ans = 0; for(int i=0;i<101;i++){ if (i+i > s && r[i])ans += (r[i]*(r[i]-1))/2; fo...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
4
#include <bits/stdc++.h> using namespace std; const int maxK = 20; long long D, answer; long long power[maxK]; long long count_n(int l, int r, long long d) { if (l < r) { return !d; } long long cnt = 0; for (int i = (d / power[r] % 10 + 10) % 10; i > -10; i -= 10) { if (!r && i > 0) ...
0
#include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; long long dp[100005][13]; int main() { string s; cin>>s; int n=s.size(); dp[0][0]=1; for(int i=0;i<n;i++){ for(int j=0;j<13;j++){ if(s[i]=='?'){ for(int k=0;k<10;k++){ (dp[i+1][(j*10+k)%13]+=dp[i][j])%=MOD; ...
0
#include <bits/stdc++.h> int n, m, d[50][8][5100]; int dp(int x, int y, int st) { int nex = x, ney = y + 1; if (d[x][y][st] != -1) return d[x][y][st]; if (x == n) return d[x][y][st] = 0; if (ney == m) { ney = 0; nex++; } int idx, i, j, s[8]; for (i = 0; i < m; ++i) s[i] = (st >> (2 * i)) & 3; if...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char count = 'a'; for (int i = 0; i < s.size(); ++i) { if (s[i] > count) { cout << "NO\n"; return 0; } else if (s[i] == count) { count++; } } cout << "YES\n"; return 0; }
2
#include <bits/stdc++.h> std::vector<bool> V; std::vector<std::vector<std::pair<int, int>>> G; std::vector<long long> A; std::vector<long long> D; std::vector<int> R; long long C = 0; void dfs(int v, long long md, bool c = false) { if (V[v]) return; if (c) ++C; V[v] = true; if (md > A[v]) { R.push_back(v); ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const long long inf = 1e9; long long b[4 * maxn], lazy[4 * maxn], n, m, x, y, z, tree[maxn * 4]; char second[5]; void push_up(long long p) { b[p] = b[p * 2] + b[p * 2 + 1]; tree[p] = ((tree[p * 2] && tree[p * 2 + 1]) && (tree[p * 2] == t...
3
#include <iostream> using namespace std; int main() { int A, B, K; cin >> A >> B >> K; for (int i = A; i <= B; i++) { if (i <= A + K - 1 || i >= B - K + 1) cout << i << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long a; cin >> a; long long L = 1, P = 1000000000000000000; long long r = (100000000000000000 * 18) % a; r = (r * 5) % a; r = (r * 9) % a; r = (r + 1) % a; if (r != 0) { L += a - r; P += a - r; } ...
5
// D - Islands War #include <bits/stdc++.h> using namespace std; int V[100000+1]; int in(){int x;scanf("%d",&x);return x;} int main(){ int N=in(), M=in(); while(M--){ int l=in(), r=in(); V[r] = max(V[r], l); } int ans = 0, R = 1; for(int r=1; r<=N; ++r) if(V[r]>=R) R=r, ans++; cout<< ans <<endl; }
0
#include <bits/stdc++.h> using namespace std; constexpr long long int TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int N = 3e5 + 8; const l...
2
#include <bits/stdc++.h> using namespace std; int p[10003] = {}, arr[10003] = {}; void prime() { p[0] = p[1] = 1; for (int i = 2; i < 10000; i++) { if (p[i] == 0) { for (int j = i * i; j < 10000; j += i) { if (p[j] == 0) p[j] = 1; } } } int m = 0; for (int i = 2; i < 10000; i++) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n,k,r,s,p; int64_t ans=0; string t; cin >> n >> k >> r >> s >> p >> t; vector<bool> flg(n,false); for(int i=0;i<n;i++){ if (i>=k && t[i] == t[i-k] && flg[i-k]){ flg[i] = false; continue; } if (t[i] == 'r') ans += p; ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t,n,k,i,ans,j,m; cin>>t; while(t--) { cin>>n>>m;ans=0; char ch[n][m]; long long num[n][m]; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cin>>ch[i][j]; ...
2
#include <bits/stdc++.h> #define N (long long)(998244353) #define MAX 500000 using namespace std; long long factorial[MAX] = {0}, finverse[MAX] = {0}, inverse[MAX] = {0}; void smodfact() { factorial[0] = factorial[1] = 1; finverse[0] = finverse[1] = 1; inverse[1] = 1; for(int i = 2; i < MAX; ++i) { ...
0
#include <bits/stdc++.h> using namespace std; int n; int cnt[66]; long long int a[500005]; int builtin_ctzll(long long int x) { if (x == 0) return 0; return __builtin_ctzll(x); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ...
4
#include <bits/stdc++.h> using namespace std; const int Nmax = 1000005; int n, v[Nmax], degree[Nmax], solved[Nmax]; vector<int> L[Nmax], Depend[Nmax], Sol; void deleteNode(int node) { solved[node] = 1; Sol.push_back(node); for (auto it : L[node]) --degree[it]; } void clearNode(int node) { deleteNode(node); fo...
2
#include <bits/stdc++.h> using namespace std; long long bin_pow(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long t = bin_pow(a, b / 2); return t * t % 100000000; } else return a * bin_pow(a, b - 1) % 100000000; } vector<long long> graph[200000], d(200000), cl(200000); vect...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int LEN = 5e5 + 5; long long h[LEN]; long long h2[LEN]; long long power[LEN]; long long SEED = 10; const long long mod = 1e9 + 7; void pre() { power[0] = 1; for (int i = 1; i < LEN; ++i) { power[i] = power[i - 1] * SEED; power[i] %= ...
4
#include<bits/stdc++.h> using namespace std; int MyXOR(int a,int b, int k){ int ans = 0; stack<int> ss; while(a>0||b>0){ ss.push((a%k-b%k + k)%k); a/=k; b/=k; } while(!ss.empty()) { ans = ans*k + ss.top(); ss.pop(); } return ans; } int main(){ ...
4
#include <bits/stdc++.h> using namespace std; const long long N = 200005; long long n; vector<long long> g[N]; long long cost[N]; long long type[N]; long long ans; bool vis[N]; pair<long long, long long> dfs(long long node, long long val) { vis[node] = true; val = min(val, cost[node]); pair<long long, long long> ...
5
#include <bits/stdc++.h> int n; long long ans; std::priority_queue<int> q1, q2; int read() { int x; scanf("%d", &x); return x; } int main() { n = read(); for (int i = 1; i <= n; ++i) q1.push(read()); for (int i = 1; i <= n; ++i) q2.push(read()); for (int i = 1; i <= n; ++i) { if (q1.empty()) q2....
3
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); printf("%d\n", (n + 1) / 2); }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, l; cin >> n; multiset<pair<int, int> > s; int arr[n + 1][2]; for (i = 1; i <= n; i++) { cin >> arr[i][0] >> arr[i][1]; s.insert(make_pair(arr[i][0], -i)); s.insert(make_pair(arr[i][1], i)); } int flag = 0; int kl = 0;...
3
#include <bits/stdc++.h> using namespace std; int main(){ int n,m,c=0; cin>>n>>m;n=m; while(m--){ int a; cin>>a; if(a>n)c++; } cout<<c<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; cin >> t; while (t--) { int n; scanf("%d", &n); cout << 2 << '\n'; if (n > 2) { cout << n << ' ' << n - 2 << '\n'; cout << n - 1 << ' ' << n - 1 << '\n'; for (int i = 3; i < n; i++) { cout << n - i + 2 ...
3
#include <iostream> #include <algorithm> #define long long long using namespace std; long f(long x) { if (x <= 0) return 0; return min(x, 2 + f((x - 2) / 3) + (x - 2) % 3); } int main() { long x; cin >> x; cout << f(x + 1) - 1 << '\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e+9; int main() { int n, k, a[101]; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); cout << a[n - k]; return 0; }
2
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n, 0); for (int i = 0; i < n; i++) cin >> a[i]; int up = 0, down = 0, i = n - 2, flag = 0; for (i = n - 2; i >= 0; i--) { if (a[i] > a[i + 1]) { if (down == 1) { i += 1; break; } ...
3
#include<cstdio> #include<algorithm> #include<cstring> #define LL long long using namespace std; const int N=105; const int inf=0x3f3f3f3f; int n,m,S,T,cnt=1,ans,tmp; int first[N*2],cur[N*2]; int dis[N*2],q[N*2]; char mp[N][N]; struct edge{int to,next,flow;}e[N*N*2]; int read() { int x=0,f=1;char c=getchar(); while(...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; int dblcmp(double d) { if (fabs(d) < eps) return 0; return (d > 0) ? 1 : -1; } int n, m, k; double a, b; const int N = 10000; double p1[N], p2[N], r1[N]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> r1[i]; cin >> m; for (in...
2
// D - Friend Suggestions #include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; #define rp(i,s,e) for(int i=(s);i<(e);++i) #define MAX 100000+1 int N,M,K; vvi F(MAX),B(MAX);//friend,block vi gid(MAX); int bfs(int root){ queue<int> q; q.push(root); while(!q.empty()){ int p ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long d = 0; long long a = 1; for (int i = 2; i <= n; i++) { long long old_d = d; d = (3 * a) % int(pow(10, 9) + 7); a = (old_d + 2 * a) % int(pow(10, 9) + 7); } cout << d << endl; }
5
#include <bits/stdc++.h> const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10; const long long LINF = 1e18; using namespace std; long long n, cnt, ans, a[ohara], b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k; long double doua; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; string alph("abcdefghijklmnopqrstuvwxyz"...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; char S[MAXN][MAXN]; int matchl[MAXN], use[MAXN]; int n, m; void check() { memset(use, 0, sizeof(use)); int cnt = 0; for (int i = 1; i <= m; i++) { if (use[i]) continue; for (int j = i + 1; j <= m; j++) { bool ch = 1; for (int k ...
0
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 50; const int INF = 0x3f3f3f3f; int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int main() { int n, m; cin >> n >> m; if (n > m) swap(n, m); cout << gcd(n - 1, m - 1) + 1 << endl; return 0; }
3
#include<bits/stdc++.h> #define N 1005 using namespace std; typedef pair<int,int> P; int n,w,d,x,y,ans; vector<P> v; char f; void add_point(){ int s,t; if(f=='N'){ s=(x+y<d?x+y+w*2+d:x+y-d); t=(w+y-x<d?d-(w+y-x)+w:d-(y-x)); } if(f=='E'){ s=(d-(y-x)<w?d-(y-x):d-(w+(y-x))+w); t=(y+x<w?w-(y+x)+w+d...
0
#include <bits/stdc++.h> using namespace std; long long N, H, A[1100]; bool bisa(long long n) { long long tmpH = H; for (long long i = n - 1; i > 0; i -= 2) { tmpH -= max(A[i], A[i - 1]); if (tmpH < 0) { return false; } } if (n % 2 == 0) return true; return tmpH >= A[0]; } int main() { ios...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = (1LL << 62); const int inf = (1 << 30); const int nmax = 1e5 + 50; const long long mod = 1e9 + 7; using namespace std; int n, i, q, a[nmax], tp, l, r, x, y, nx[4 * n...
6
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int N; long long ans=0; cin>>N; vector<int> A(N); vector<int> B(N); vector<int> C(N); for(int j=0;j<N;j++){cin>>A[j];} for(int j=0;j<N;j++){cin>>B[j];} for(int j=0;j<N;j++){cin>>C[j];} sor...
0
#include<bits/stdc++.h> using namespace std; #define lli long long int #define mod 1000000007 int main(){ lli t; cin >> t; while(t--){ lli i,k,l,j,m,n; cin >> n; j=1 ; while(j<=n){ j=j*2; } j=j/2; cout << j-1 <<'\n'; } return 0;}
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int T = 1e5 + 10; const long long MOD = 1000000007; long long n; vector<int> primes; bitset<T> crivo; long long f[T]; map<int, int> vezes; void gen() { for (int i = 2; i < T; i++) { if (!crivo[i]) { primes.push_back(i); fo...
3
#include <bits/stdc++.h> using namespace std; struct MinMax { int min, max; MinMax() : min(INT_MAX), max(INT_MIN){}; MinMax(int min, int max) : min(min), max(max){}; }; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; MinMax a[n]; for (int i = 0; i < m;...
1
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::vector<int> seq(n + 1, 0); for (int index = 2; index <= n; index++) { std::cin >> seq[index]; } std::vector<int> pathR(1, n); int k = n; while (k > 1) { pathR.push_back(seq[k...
1
#include <bits/stdc++.h> using namespace std; const int MIN = 1e3 + 2; const int MXN = 2e6 + 3; const int INF = 1e9 + 7; const int base = 1e9; const long long LINF = 1e18 + 15; const double EPS = 1e-9; int n; long long a[MXN], pref[MXN], mx = -1, id; int mn = INF; int s, f; int main() { ios_base::sync_with_stdio(0); ...
3
#include <bits/stdc++.h> using namespace std; const int M = 400 * 1000 + 4, Inf = 1e9 + 10; pair<int, int> a[M]; int b[M]; int main() { ios::sync_with_stdio(false); int n, j = 0; cin >> n; for (int i = 0, x; i < n; i++) { cin >> x; a[i] = make_pair(x, i); } sort(a, a + n); for (int i = 0; i < n; i...
3
#include <bits/stdc++.h> using namespace std; #define range(i, m, n) for(int i = m; i < n; i++) #define husk(i, m, n) for(int i = m; i > n; i--) struct ft { int l; int r; int val; ft(int _l, int _r, int _val) : l(_l), r(_r), val(_val){}; }; template <typename T> void debug_out(T t) { cerr << t; } templat...
0
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; const int N = 3e2 + 7, L = 1e5 + 7; long double fac[L], res; int n, m, k; long double chs(int a, int b) { return fac[b] - fac[a] - fac[b - a]; } void solve(int stn, int str, int sz) { long double tmp = chs(stn, n); tmp += chs(str, n); tmp += chs...
4
#include <bits/stdc++.h> using namespace std; int a[2005], G[105][105]; int ans[2005], n, m; bool dfs(int u, int d, int c) { if (d >= m) return true; int v; if (c) v = 1; else v = a[d + 1] + 1; for (; v <= n; v++) { if (G[u][v]) { G[u][v] = G[v][u] = 0; if (dfs(v, d + 1, 1)) { ...
4
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<iostream> #include<queue> #include<cmath> using namespace std; typedef long long ll; const int maxn = 1005; const int maxl = 105; const ll inf = 1ll<<55; const double eps = 1e-8; struct edge { int to,val,mag; edge(int a,int b,int c):...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int MAXN = 20010; const int INF = 0x3f3f3f3f; const double eps = 0.0000001; const long long mod = 998244353; int n, m, x, y, k, cnt; int a[N], t[N], b[N], vis[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); scanf(...
3
#include <bits/stdc++.h> using namespace std; const int P = 4; const long long INF = 998244353000000ll; class Application { private: public: void run() { int n; cin >> n; string s; vector<long long> a(n); vector<vector<long long>> dp(n + 1); for (int i = 0; i < n + 1; ++i) dp[i] = {0, INF, I...
4
#include <bits/stdc++.h> using namespace std; int n, m, a; long long memo[2020][2020]; long long umb[2020]; int rain[2020]; long long dp(int i, int u) { if (i == a) return 0; long long &ret = memo[i][u]; if (ret != -1) return ret; if (rain[i]) { ret = umb[i] + dp(i + 1, i); if (u != a) ret = min(ret, um...
6
#include<stdio.h> #include<algorithm> using namespace std; int dat[5000][5]; int m[5]; int main(){ int a; while(scanf("%d",&a),a){ for(int i=0;i<5000;i++) for(int j=0;j<5;j++)dat[i][j]=0; for(int i=0;i<5;i++)m[i]=0; int count=0; for(int p=0;p<a;p++){ int b,c,d; scanf("%d%d%d",&b,&c,&d);d--; count+...
0
#include <bits/stdc++.h> using namespace std; int binarysearch(long long arr[], int n, int num) { int start = 0, end = n - 1; int mid = (start + end) / 2; while (start <= end) { if (num > arr[mid]) { start = mid + 1; mid = (start + end) / 2; } else if (num < arr[mid]) { end = mid - 1; ...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; // 75 = (2+1) * (4+1) * (4+1) // 75 = (2+1) * (24+1) // 75 = (4+1) * (14+1) // 75 = (74+1) ll num(vector<ll> table, ll n) { ll res = 0; for (ll num : table) { if (num >= n-1) res += 1; } return res; } int main() { ll N; cin >> N; ...
0
#include <bits/stdc++.h> using namespace std; int n, m[500005], pos, ans; long long dp[500005], dp1[500005], mx; stack<pair<int, int> > s; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &m[i]); while (!s.empty() and s.top().first > m[i]) s.pop(); if (s.empty()) pos = 0; ...
3
#include <bits/stdc++.h> using namespace std; const int limit = 1000000; int gcd(int a, int b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(a % b, b); } int absolute(int a) { if (a < 0) return -a; return a; } struct point { int x, y; point() {} point(int x, int y) : x(x), y(y) {} }; point n...
6
#include<iostream> #include<math.h> #include<vector> #include<algorithm> #include<cstdio> #include <string> using namespace std; int main(){ int n,i; long long tmp,sum=0; long mean; cin>>n; for(i=0;i<n;i++){ cin>>tmp; sum+=tmp; } mean=sum/n; cout<<mean<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<int> merge(vector<int> a, vector<int> b) { vector<int> res(a.size() + b.size()); int aI = 0, bI = 0; for (int i = 0; i < res.size(); i++) { if (aI == a.size() || (bI != b.size() && a[aI] >= b[bI])) { res[i] = b[bI]; bI++; } else if (bI == b....
2
#include <bits/stdc++.h> using namespace std; int segtree[1000001]; void build(int node, int l, int r, int low, int high, int i) { if (low > r || l > high) return; if (l >= low && r <= high) { segtree[node] = i; return; } int m = (l + r) / 2; build(2 * node + 1, l, m, low, high, i); build(2 * node +...
5
#include <bits/stdc++.h> using namespace std; int main() { long long m, n, u, v; cin >> m >> n; for (long long i = 0; i < n; i++) { cin >> u >> v; if (u % 2 == v % 2) { cout << (((u - 1) * (m) + 1) / 2) + v / 2 + v % 2 << endl; } else { cout << (m * m) / 2 + (m * m) % 2 + ((u - 1) * m) / 2...
2
#include <bits/stdc++.h> using namespace std; const int N = 5005; using ll = long long; int n; char str[N]; int dp[N]; int len[N], lef[N], rig[N]; int sp[N]; bitset<N> vis; int main() { for (int i = 1; i < N; i++) { vis.reset(); for (int j = 1; j <= i; j++) { vis.set(dp[max(j - 2, 0)] ^ dp[max(0, i - j ...
5