solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; long long r, l, h; r = k; l = k; h = 1; m -= n; while (m >= (r - l + 1) && !(l == 1 && r == n)) { m -= (r - l + 1); if (r < n) r++; if (l > 1) l--; h++; } if (l == 1 && r == n) { h +...
2
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int i, j, k, n, m, x, y, z; char a[1005][1005]; int H[2005][2005], l; int A[1005][1005][3][9]; int yon[8][2] = {0, -1, -1, -1, -1, 0, -1, 1, 0, 1, 1, 1, 1, 0, 1, -1}; bool cmp(pair<int, int> x, pair<int, int> y) { int t1 = min(x.first, y.first);...
5
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(x) (x).begin(), (x).end() #define pb emplace_back #define ll long long #define pii pair<int, int> #define ld long double const int INF = 2e9 + 1; const int mod = 1e9 + 7; vector<int> z_function(string &s) { int n = (int)s....
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long mn = 9999999999; long long mx2 = 0; while (n--) { long long x, y; cin >> x >> y; mn = min(y, mn); mx2 = max(mx2, x); } long long m; cin >> m; long long mx = 0; long long mn2 = 9999999999; wh...
2
#include <bits/stdc++.h> using namespace std; set<int> S; map<int, int> M; struct node { int x, y; } A[222222]; bool operator<(const node x, const node y) { if (x.y != y.y) { return x.y > y.y; } else { return x.x < y.x; } } int T[222222]; void add(int x) { while (x <= 200000) { T[x]++; x += ((...
6
#include <bits/stdc++.h> using namespace std; const int dr[4] = {0, 1, 0, -1}; const int dc[4] = {-1, 0, 1, 0}; int R, C; char B[(1505)][(1505)]; int r0, c0; int vr[(1505)][(1505)]; int vc[(1505)][(1505)]; queue<pair<int, int> > Q; inline int modn(int a, int n) { if (a < 0) { a = (-a) % n; a = (n - a) % n; ...
4
#include<stdio.h> int main() { long long n, K, A, B; scanf("%lld %lld %lld", &K, &A, &B); if(K<=A) n = 1; else if(A<=B) n = -1; else n = (K-B)/(A-B); if(n>0) { while(n*A-(n-1)*B<K) n++; printf("%lld\n", n*2-1); } else printf("-1\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZER...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18; const long double Pi = 3.141592653589793116, EPS = 1e-9, Gold = ((1 + sqrt(5)) / 2); long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL}; lo...
6
#include <bits/stdc++.h> using namespace std; long long int gcd1(long long int x, long long int y) { if (y == 0) { return x; } return gcd1(y, x % y); } long long int mult(long long int a, long long int b) { return (1LL * a * b) % int(1e9 + 7); } long long int msum(long long int a, long long int b) { long ...
4
#include <cstdio> #include <vector> #include <algorithm> using namespace std; int main(){ int n; while(scanf("%d", &n), n){ unsigned s = 0, p; vector<unsigned> j(n - 1); for(int i = 0; i < n; ++i){ scanf("%u", &p); s += p; } for(int i = 0; i < n - 1; ++i){ scanf("%u", &j[i]); } sort(j.begin(),...
0
#include <bits/stdc++.h> using namespace std; int fa[500005]; struct node { int opt, u, v, w, uu, vv; bool operator<(const node &a) const { return w < a.w; } } E[500005]; int n, m, Q; int find(int x) { while (x != fa[x]) x = fa[x] = fa[fa[x]]; return x; } pair<int, int> stck[500005]; int top; void merge(int x, ...
3
#include <bits/stdc++.h> using namespace std; int main(void) { long long int x, y, z; cin >> x >> y >> z; if (x + y < z) cout << "0 0"; else cout << (x + y) / z << " " << ((x + y) / z > x / z + y / z ? min(min(x % z, y % z), min(z - x % z, z - y % z)) : 0); r...
1
//begin #include <Core> /* * Package: StandardCodeLibrary.Core * Last Update: 2012-12-21 * */ #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <utility> #include <vector> #include <list> #include <string> #include <stack> #include <queue> #include <deque> #include <set> #include ...
4
#include <bits/stdc++.h> using namespace std; int n, p, k, y, r, b[1000], c[10000], ok, of; char a[100000]; int main() { cin >> n; for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { b[i] = (int)a[i] - '0'; } for (int i = n; i < 2 * n; i++) { c[k] = a[i] - '0'; k++...
2
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<map> #include<cstring> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define REP(n) rep(i,n) #define all(n) n.begin(),n.end() const int MAX = 10010; bool p[MAX]; int main() { p[0] = p[1] = 1; rep(i,MAX)if(!p[i])fo...
0
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; long long MOD = 998244353; const char nl = '\n'; const long long inf = 1e15; long long power(long long x, long long y) { long long z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /= 2; } return z; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; long long a[N]; struct t { int lval, rval, mval; } tr[N * 4]; int sign(long long x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } inline void cal(int cur, int l, int r) { int m = (l + r) / 2; int dcur = cur + cur; tr[cur].mval...
3
#include <bits/stdc++.h> using namespace std; long long oo = 100000000007; vector<long long> v; map<long long, long long> m; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long i, a, b, n, k, s; string s1, s2, s3; cin >> s1; cin >> s2; n = s1.size(); for (i = 0; i < n; i+...
2
#include <bits/stdc++.h> using namespace std; int main() { long double n, l, v1, v2, k; cin >> n; cin >> l; cin >> v1; cin >> v2; cin >> k; int rounds = ceil(n / k); long double d = l / (((2 * v1) / (v1 + v2)) * (rounds - 1) + 1); long double time = (((l - d) / v1) + d / v2); cout << setprecision(30...
1
#include <iostream> #include <string> #include <queue> using namespace std; int markpower[128]; int numpower[128]; int main() { for (char c = '0'; c <= '9'; c++) { numpower[c] = c - '0'; } numpower['T'] = 10; numpower['J'] = 11; numpower['Q'] = 12; numpower['K'] = 13; numpower['A'...
0
#include<bits/stdc++.h> using namespace std; #define N 333 #define mod 1000000007 int n,m,f[N][N][N],ans; vector<pair<int,int> > q[N]; void pls(int &x,int y){x=(x+y)%mod;} int read(){ int x=0,f=1;char ch=getchar(); for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f; for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';...
0
#include <bits/stdc++.h> using namespace std; int n, a, b, x[1005], y[1005], v[1005]; int solve() { cin >> a >> b >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> v[i]; double ans = 2e18; for (int i = 0; i < n; i++) ans = min(sqrt((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b)) / v[i], ...
1
#include <bits/stdc++.h> using namespace std; int n, m, i, a[1005]; int main() { std::ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; m = n - 1 - a[0] + 1; for (int i = 1; i < n; i++) { if (i % 2 == 1) a[i] = (a[i] - m + n) % n; else a[i] = (a[i] + m) %...
2
#include<cstdio> int solve(int a,int b){ if(b==4){ if(a==0) return 1; else return 0; } else{ int res=0; for(int i=0;i<=a&&i<10;i++){ res+=solve(a-i,b+1); } return res; } } int main(){ int n; while(~scanf("%d",&n)){ printf("%d\n",solve(n,0)); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long t = 1; while (t--) { long long n, m; cin >> n >> m; long long a[n], b[m]; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < m; i++) cin >> b[i]; vector<long long> v; for (long long i = 0; i < n; i...
1
#include <bits/stdc++.h> using namespace std; long long int a[100000] = {0}; int main() { int z; for (z = 0; z < 1000000; z++) ; for (int n, m, k; cin >> n >> m >> k;) { int i; for (i = 0; i < n && cin >> a[i]; i++) ; long long int t = m / ((n + 1) / 2); if (n % 2 == 0) { cout << 0...
1
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265359; const long long MOD = (long long)998244353ll; const long long MAXN = (long long)1e6 + 10; const long long INF = (long long)2242545357980376863; const long double EPS = (long double)1e-8; vector<pair<long long, long long> > G[MAXN]; long...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; int a[N]; int f[N][2]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) { f[i][0] = 1; if (a[i] > a[i - 1]) { f[i][0] = max(f[i][0], f[i - 1][0] + 1); f[i][1]...
4
#include<iostream> using namespace std; int main(){ int a,b; cin>>a; cout<<24-a+24<<endl; }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long inf = 1e18; const long double pi = 3.141592653589793238; long long MOD = 1000000007; const long long N = 3e5 + 10; long long n, m; long long score[N]; vector<long long> graph[N]; bool vis[N] = {0}; long long dp[N]; long long Fre...
5
#include<cstdio> #include<vector> #include<algorithm> #include<functional> using namespace std; int main(void){ int n,m; while(scanf("%d %d", &n, &m) && n != 0 ){ vector<int > a; int temp; int ans = 0; for(int i = 0; i < n; i++){ scanf("%d", &temp); a.push_back(temp); } sort(a.begin(),a....
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n; const ll nax = 1e5; vector<ll> v[nax]; const ll mod = 1e9 + 7; // (black, white) pair<ll, ll> dfs(ll s, ll p){ ll white = 1; ll black = 0; for(ll &c : v[s]){ if(c == p) continue; pair<ll, ll> pf = dfs(c, s); black = ((1LL*(white+black...
0
#include<bits/stdc++.h> using namespace std; int main() { int H,W; cin >> H >> W; vector<vector<string>>S(H,vector<string>(W)); for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { cin >> S[i][j]; if(S[i][j] == "snuke") { cout << (char)(j+'A') << i+1 ...
0
#include <iostream> #include <cstdio> #include <cstdlib> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <cmath> #include <complex> #include <map> #include <climits> #include <sstream> using namespace std; #define reep(i,a,b) for(int i=(a);i<(b);++...
0
#include <bits/stdc++.h> using ll = long long; using namespace std; namespace Debug { template <class A, class B> ostream &operator<<(ostream &out, pair<A, B> &p) { out << "(" << p.first << ", " << p.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, vector<T> &v) { out << "{"; st...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (i % 2 == 0) cout << abs(a[i]) <<...
1
#include <bits/stdc++.h> const long long SZ = 1e5 + 7; const long long inf = 1e18; const long long MOD = 1e9 + 7; #define int long long #define endl '\n' #define krosuru int __T; cin>>__T; while (__T-- > 0) #define yehbhitheekhai ios_base::sync_with_stdio(0); cin.tie(...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, j, temp; cin >> n; bool check = 0; if (n % 7 == 0 || n % 3 == 0) { check = 1; } else { temp = n; while (1) { temp -= 3; if (temp > 0 && temp % 7 == 0) { ...
1
#include <bits/stdc++.h> using namespace std; long long t, d, g, k, s, n, m; vector<long long> v1(500005), v2(500005), v3(500005), ans(500005); bool check(long long x, long long y) { long long z = (x - 1) / k + 1; if (y - g <= z * k) { for (long long j = (z - 1) * k + 1; j < x && t < g; ++j) { t++; ...
4
#include <bits/stdc++.h> using namespace std; struct Node { int l, r, i; } a[2000010], b[2000010]; int n, M, m, ans, r; bool c[2000010]; 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' && ch <= '9') {...
2
#include <bits/stdc++.h> using namespace std; int main(){ long long x,y,z; cin>>x>>y>>z; cout<<((x-z)/(y+z))<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int BITS = 62; long long N, K; vector<long long> first, second; void flip_bit(int bit) { vector<long long> A, B; for (int i = 0; i < N; i++) (second[i] & 1LL << bit ? A : B).push_back(second[i] ^ 1LL << bit); merge(A.begin(), A.end(), B.begin(), B.end(), sec...
6
#include <bits/stdc++.h> using namespace std; int x[8], a[7], key, buff, sum = 1000000007, h[8]; string ham[4], str[] = {"", "abbb", "aabb", "abab", "abaa", "aaab", "aaba", "abba"}; bool flag; int main() { for (int i = 0; i < 6; i++) cin >> a[i]; if ((a[5] - a[2] + a[1]) % 2 != 0) { cout << -1; return 0...
5
#include <bits/stdc++.h> using namespace std; string fix = "0123456789"; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int fx[] = {1, -1, 0, 0}; int fy[] = {0, 0, 1, -1}; int main() { long long n, m; cin >> n >> m; long long pairr = n / m; long long mod = n % m; long long m...
2
#include <bits/stdc++.h> using namespace std; int n, a[((int)2001 * 1000)], b[((int)2001 * 1000)], comp[((int)2001 * 1000)]; vector<int> v, e[((int)2001 * 1000)], vec[((int)2001 * 1000)]; bool mark[((int)2001 * 1000)], dead[((int)2001 * 1000)], type[((int)2001 * 1000)]; void dfs(int x, int root) { mark[x] = 1; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int size; cin >> size; long long a[size][size]; map<int, long long> r; map<int, long long> c; long long d = 0, row; long long ad = 0, col; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { cin >> a[i][j]; if (a[i]...
2
#include<bits/stdc++.h> using namespace std; #define ll long long #define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++) #define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--) #define EREP(i,u) for(int i=start[u];i;i=e[i].next) #define fi first #define se second #define mkr(a,b) make_pair(a,b) #define SZ(A) ((int)...
0
#include <iostream> #include <vector> using namespace std; int main() { long long N, S=0; cin >> N; vector<int> A(N),B(N); for(int i=0;i<N;++i) { cin >> A[i]; S+=A[i]; } if(S%(N*(N+1)/2)) { cout << "NO" << endl; return 0; } int a=S/(N*(N+1)/2); for(int i=0;i<N;++i) B[i] = A[(i+1)%N]-A[i]; for...
0
#include <bits/stdc++.h> using namespace std; int ceil(int a, int b) { if (a % b == 0) { return a / b; } return (a / b) + 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t > 0) { t--; int n, m, k; cin >> n >> m >> k; int lg = ceil(n, m), sm = ...
6
#include <bits/stdc++.h> using namespace std; const unsigned _mod = 998244353; const unsigned mod = 1e9 + 7; const long long infi = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; long long ksm(long long x, long long y) { long long ret = 1; while (y) { if (y & 1ll) ret = ret * x % mod; y >>= 1ll; x = ...
3
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef pair<int,int>P; struct st{int a,b,c;}; bool operator<(st&a,st&b){ if(a.a!=b.a)return a.a<b.a; if(a.b!=b.b)return a.b<b.b; if(a.c!=b.c)return a.c<b.c; return false; } bool operator==(st&a,st&b){ return a.a==b.a&&a.b==b.b&&...
0
#include <bits/stdc++.h> std::string a, b; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> a >> b; int i = 0, j = 0; while (a[i] == '0' && i < a.size()) i++; while (b[j] == '0' && j < b.size()) j++; int s, k; int c = 0; if (a.size() - i > b.size() - j) c = 1;...
1
#include <bits/stdc++.h> using namespace std; int N, M, i, j, k; string A, B; bool ok[25]; char c[25]; bool Check(int i, int j) { string s, sir; int cnt; if (i == N - 1) return true; for (cnt = i + 1; cnt < N; cnt++) s += B[cnt]; for (cnt = 1; cnt <= M; cnt++) if (ok[cnt] == false && cnt != j) sir += c[cn...
3
#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<map> #include<string> #include <math.h> #include<algorithm> #include<functional> #define ll long long #define inf 999999999 #define pa pair<int,int> #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b))<EPS) using namespace std; class Poi...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 2, j, high = 0, Si = 1; scanf("%d", &n); while (n >= Si) { n -= Si; Si = i * (i + 1) / 2; high++; i++; } printf("%d\n", high); return 0; }
1
#include <bits/stdc++.h> using namespace std; int rows[4] = {-1, 0, 0, 1}; int cols[4] = {0, -1, 1, 0}; bool withinGrid(int x, int y, int m, int n) { return ((x >= 0) && (y >= 0) && (x < m) && (y < n)); } bool isSafe(int x, int y, int m, int n, vector<vector<bool>> &visited, vector<string> &grid) { retu...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 0; i <= 9; i++) { cout << i << endl; getline(cin, s); if (s == "great!" || s == "cool" || s == "not bad" || s == "don't touch me" || s == "don't think so") { cout << "normal"; cout << flush; retur...
2
#include <iostream> using namespace std; const int N=55; int n,a[N],h=0;//head int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; if(abs(a[i])>abs(a[h]))h=i; } cout<<2*n-1<<'\n'; for(int i=0;i<n;i++){ cout<<h+1<<' '<<i+1<<'\n'; } if(a[h]>0){ for(int i=0;i<n-...
0
#include <bits/stdc++.h> using namespace std; int main() { int s, n; cin >> s >> n; vector<pair<int, int>> vp; int x, y; for (int i = 0; i < n; i++) { cin >> x >> y; vp.push_back(make_pair(x, y)); } sort(vp.begin(), vp.end()); for (int i = 0; i < n; i++) { if (s > vp[i].first) s += vp[...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, L, a[N], c[N]; bool check(int P) { memset(c, 0, sizeof(c)); for (int i = (L); i < (n + 1 - L + 1); ++i) { if (P < i && i < n + 1 - i && a[i] != a[n + 1 - i]) return false; if (i <= P) ++c[a[i]]; else if (n + 1 - i <= P && ...
5
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") #pragma GCC target("sse2") void opting() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); } long long inp() { long long x; cin >> x; return x; } void comping(vector<long long> &vec) { sort((vec).begin(), (vec).end()); vec.re...
5
#include <bits/stdc++.h> using namespace std; int fx[] = {0, 1, 1, 1, 0, -1, -1, -1}; int fy[] = {1, 1, 0, -1, -1, -1, 0, 1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, i, j, k; cin >> n; long long ara[100005] = {0}; for (i = 0; i < n; i++) { cin >> k; ara[k]+...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e2 + 10; int a[MAX_N][MAX_N], n; bool mark[MAX_N]; int main() { cin >> n; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (a[i][j] == 3) { m...
1
#include <bits/stdc++.h> using namespace std; int main() { int n,i; cin>>n; int b[n-1]; for(i=0;i<n-1;i++) cin>>b[i]; int sum=b[0]+b[n-2]; for(i=1;i<n-1;i++) { sum+=min(b[i],b[i-1]); } cout<<sum; return 0; }
0
#include <bits/stdc++.h> using namespace std; int t, i, a[1001], n, k; int main() { cin >> n; while (i++ < n) cin >> t, k = max(++a[t], k); cout << n - k; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char c[4] = {'a', 'b', 'c', 'd'}; for (int i = 0; i < n; i++) { cout << c[i % 4]; } cout << endl; return 0; }
2
#include<bits/stdc++.h> using namespace std; template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; ...
0
#include <bits/stdc++.h> using namespace std; struct node { int l, r, x; long long sum, lazy; node *lt, *rt; node(int a, int b) : l(a), r(b), x(-1), sum(0), lt(NULL), rt(NULL), lazy(0) { if (r == l) x = l + 1; else { int mid = (l + r) >> 1; lt = new node(l, mid); rt = new node(mi...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long dist[N], a[N]; vector<vector<pair<int, long long> > > g(N); int n, m; void dij() { priority_queue<pair<long long, int> > pq; for (int i = 1; i <= n; i++) { pq.push(make_pair(-a[i], i)); dist[i] = a[i]; } while (pq.size()) { ...
4
#include <iostream> #include <iomanip> #include <string> #include <string.h> #include <math.h> #include <cmath> #include <vector> #include <algorithm> #include <deque> #include <map> #define ll long long #define ull unsigned long long #define mod 1000000007 using namespace std; int main() { while(true){ char x[4]...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e8 + 1; bitset<maxn> have; int main() { int n, m; scanf("%d %d", &n, &m); vector<int> ans = {1}; int cur = 0; while (cur < m && ans.size() < n) { int s = ans.size() / 2; if (cur + s > m) { int need = m - cur; int d = need * 2;...
5
/* 神题 1.b[i]=a[i]~a[n*2-i] 2.b中i之前所有数都不能在b[i]~b[i+1]之间(不包括端点) f[i][j][k]=填完了b的后i个数,b的倒数第i个数有j种选择,它在这j种选择中排第k小,方案数 转移时计算选择种类数,枚举当前选择哪种 O(n^4) */ #include<cstdio> #include<cstring> #include<algorithm> #define N 110 #define mod 1000000007 using namespace std; int n, w[N], f[N][N][N], sum, ans, now, x, y, x1, x2; int main(...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000010, D = N * 22; int n, px[N], py[N], a[N], root[N]; int sum[D], l[D], r[D], dn; int m, key, ans; int insert(int d, int lt, int rt, int w) { int md = (lt + rt) >> 1; int nd = ++dn; sum[nd] = sum[d] + 1; if (lt != rt) { if (w <= md) { l[nd...
3
#include<iostream> #include<string> #include<algorithm> using namespace std; #define MOD 10000 string s; short dp[2][3][10][500][501]; //[free][増減][prev][余り][index] int m; int solve( bool fr, int updw, int pre, int mod, int index){ if( index == s.size() ) return !mod; if( dp[fr][updw][pre][mod][index] != -1 ) ret...
0
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> graph[500005]; vector<int> tgraph[500005]; int degree[500005]; int uf[500005]; int pre[500005]; int onenode[500005]; vector<int> onenode_conn[500005]; int dominated_by[500005]; int onelink[500005]; int fin(int a) { if (uf[a] == a) return a; return ...
6
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; const ld eps = 1e-9; //// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; long long a[maxn], sum[maxn]; int f[maxn], ans; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i]; f[n] = n; f[n + 1] = n + 1; for (in...
4
#include <bits/stdc++.h> using namespace std; int main() { int pts[3][2], dx, dy, nx, nxx; for (int i = 0; i < 3; i++) cin >> pts[i][0] >> pts[i][1]; cout << 3 << endl; for (int i = 0; i < 3; i++) { nx = (i + 1) % 3; nxx = (i + 2) % 3; dx = pts[i][0] - pts[nx][0]; dy = pts[i][1] - pts[nx][1]; ...
2
#include <queue> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; typedef int W; const int MAXV = 1005; const int MAXE = 5005; const int INF = 100000000; int adj[100][100]; int main() { int n,m,s,g1,g2,b1,b2,c; while(~scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2), n|m|s|g1|g2) {...
0
#include <bits/stdc++.h> using namespace std; int Aqua_Fortis, Aqua_Regia, Amalgama, Minium, Vitriol, Philosopher_stone; int main() { cin >> Aqua_Fortis >> Aqua_Regia >> Amalgama >> Minium >> Vitriol; while ((Aqua_Fortis >= 1) && (Aqua_Regia >= 1) && (Amalgama >= 2) && (Minium >= 7) && (Vitriol >= 4)) { ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int T, n, A[maxn]; long long k, SUM[maxn]; int main() { scanf("%d", &T); while (T--) { int pos = 1; long long sum = 0, ans = 0; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &A[i]); sum += 1ll *...
3
#include <bits/stdc++.h> using namespace std; typedef struct segt { long long s0, s1; long long lazy; int len; } segmenttree; segmenttree tree[524312]; long long fib[524312 >> 1]; long long fibprefix[524312 >> 1]; int n; void build(int l, int r, int index); void update(int pt, int l, int r, int index, long long v...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000008; int n, m, k, d, i, j, e; int tmp[N], pos[N], p[N], c[N]; char s[N]; int main() { scanf("%s %d", s, &m); n = strlen(s); while (m--) { scanf("%d%d", &k, &d); for (i = 0; i < n; i++) { c[i] = (i + 1) % n; pos[i] = p[i] = i; ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long a[k]; long long b[n + 1][2]; for (long long i = 0; i < k; i++) { cin >> a[i]; } for (long long i = 0; i < n + 1; i++) { b[i][0] = -1; b[i][1] = -1; } for (long long i = 0; i < k; i++) { ...
3
#include <bits/stdc++.h> using namespace std; int n, m; struct camion { int d, h, c, r; }; camion t[250000]; int a[401]; bool sirve(int v, int idCamion) { int litros = v; int cantRecargas = t[idCamion].r; for (int i = t[idCamion].d + 1; i <= t[idCamion].h; i++) { if (v < (a[i] - a[i - 1])) { return fa...
6
#include <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) using namespace std; int n,m,a[300001],f[300001][2][2],mem[300001][2]; pair<int,int>b[300001]; set<int>s; int main(){ r(i,300001)a[i]=1; cin>>n>>m; r(i,m)cin>>b[i].first>>b[i].second; sort(b,b+m); r(i,m){ int x=b[i].second; if(!s.count(x)){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; for (int i = 0; i < q; ++i) { int n; cin >> n; vector<int> a(n); for (int j = 0; j < n; ++j) { cin >> a[j]; } int ans = 1; sort(a.begin(), a.end()); ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[26]; memset(arr, -1, sizeof(arr)); cin >> n; char a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int setno = 0; for (int i = 0; i < n; i++) { if (a[i] != b[i]) { if (arr[a[i] - ...
4
#include <bits/stdc++.h> using namespace std; int b[152], gc[152][152]; inline int gcd(int x, int y) { return (y == 0) ? x : gcd(y, x % y); } inline unsigned int C(int n, int m) { int i, j, d, p; unsigned int res = 1; for (i = 1; i <= m; i++) b[i] = n - i + 1; for (i = 1; i <= m; i++) for (p = i, j = 1; (p ...
6
#include <bits/stdc++.h> long long int mod = 2000000000 + 7; long long int inf = (long long int)(1e18); using namespace std; mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count()); int main() { iostream::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); bool eq = true; ...
4
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int maxn = 2e6 + 7; struct Complex { double x, y; Complex(double _x = 0.0, double _y = 0.0) : x(_x), y(_y) {} Complex operator-(const Complex &b) const { return Complex(x - b.x, y - b.y); } Complex operator+(const Complex &b...
5
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long Cubic[N], m; int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); cin >> m; for (long long i = 1; i < N; i++) { Cubic[i] = i * i * i; if (Cubic[i] > 2 * m) break; } long long x = 0, idx = 1, ans = 0; ...
2
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; int main(){ int n,q; cin >> n >> q; vector<array<ll,3>> events; rep(i,n){ ll s,t,x; cin >> s >> t >> x; events.push_back({s-x,1,x}); events.push_back({t-x,-1,x}); ...
0
#include <algorithm> #include <iostream> #include <complex> #include <cstdio> #include <utility> #include <vector> using namespace std; using W = long double; typedef complex<W> P; typedef pair<P,P> L; typedef pair<P,W> C; typedef vector<P> Poly; #define X real() #define Y imag() const W EPS = (1e-6), INF = (1e15); W ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 505; const int maxd = 250010; const int maxm = 20010; struct edge { int y, d, next; } a[maxm]; struct node { int x, y; } q[maxd]; int n; int len, first[maxn]; int pre[maxn][maxn][2], ans[maxd][2], tot; bool v1[maxn][maxn]; void ins(int x, int y) { len...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; struct node { int n4, n7, n47, n74; void change() { swap(n4, n7); swap(n47, n74); } void mrg(node l, node r) { n4 = l.n4 + r.n4; n7 = l.n7 + r.n7; n47 = max(n4, n7); n47 = max(n47, l.n4 + r.n7); n47 = max(n47, l.n...
5
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vp; vector<int> d; int countt[200005], countSum[200005]; int trck[209], trck2[209][200005]; int main() { int i, j, k, l, temp, t, n, m, ans, caseno = 0; while (cin >> n) { vp.clear(); memset(countt, 0, sizeof(countt)); memset(trck, 0,...
3
#include <bits/stdc++.h> using namespace std; void pencilcase(long long a, long long b, long long c, long long d, long long k) { if (k <= 1) { cout << -1 << endl; return; } long long pen; long long pencil; if (a % c > 0) { pen = (a / c) + 1; } else { pen = (a / c); } if (...
1
#include <bits/stdc++.h> using namespace std; const int N = 77777 + 10, MOD = 777777777, M = 5; long long seg[4 * N], a[N], dp[M][M][N]; int n; void upd(int x, int val, int s = 0, int e = n, int id = 1) { if (x < s || x >= e) return; if (e - s == 1) { seg[id] = val; return; } int mid = (s + e) / 2; up...
5