solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int maxn = 4e5 + 7; bool dp[maxn]; int pre[maxn]; string s; bool check(int to, int from) { int cur = to; while (cur < from && s[cur] != '.') cur++; if (cur - to > 8 || cur - to == 0) return false; if (from - cur == 0 || from - cur > 3)...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); long long sum = 0; for (int i = 1; i < n; i++) { sum += arr[i] - arr[i - 1] - 1; } cout << sum << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const ui...
3
#include <bits/stdc++.h> using namespace std; long long a, b; int main() { ios_base::sync_with_stdio(false); cout << "? "; for (long long x = 1; x <= 100; ++x) cout << (x << 7) << " "; cout << endl; cin >> a; a = a & ((1ll << 7) - 1); cout << "? "; for (long long x = 1; x <= 100; ++x) cout << x << " "; ...
2
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k) for(int i = j; i < k; ++i) #define rep(i, j) FOR(i, 0, j) #define repr(i, j) for(int i = j; i >= 0; --i) #define INF (1 << 30) #define MOD 1000000007 typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; int n; string s; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n; struct REC { int a, b, c, d; } rec[N]; bool cmp1(REC& p, REC& q) { return p.a < q.a; } bool cmp2(REC& p, REC& q) { return p.b < q.b; } bool solve(int l, int r) { if (l == r) return 1; sort(rec + l, rec + r + 1, cmp1); int xmax = 0; fo...
5
#include <bits/stdc++.h> using namespace std; long long a, b, c, x, y, z; long long rem, ex; bool flag = 1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> a >> b >> c; cin >> x >> y >> z; if (a > x) ex = (a - x) / 2; if (b > y) ex += (b - y) / 2; if (c > z) ex += (c - z) / 2; if (a < ...
1
#include <bits/stdc++.h> const int inf = 2e9; using namespace std; long long MOD = 1000000007; typedef struct { int a, b, c; } iii; void mosA(vector<int> a) { for (int i = 0; i < a.size(); i++) printf("%d ", a[i]); printf("\n"); } void mosP(vector<pair<int, int> > a) { for (int i = 0; i < a.size(); i++) printf(...
5
#include <bits/stdc++.h> using namespace std; mt19937 rnd(51); const int K = 500; int add[K][K]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, cnt = 0; cin >> n >> m; vector<int> x(n), y(n), ans(m), last(n), bal(m + 1); vector<vector<int>> need(n); set<int> st; for (int i = 0; i < n; i+...
3
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<=n;i++) typedef long long ll; const int n = 26; ll s[365][26]; int main(){ ll d; cin >> d; vector<ll> c(n+1); //満足度低下 REP(i,n) cin >> c[i]; REP(i,d){ REP(j,n){ cin >> s[i][j]; } } vector<ll...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void output(int a, int b, int c) { if ((a + 3 * c) % 2 == 0) { cout << 0 << endl; } else cout << 1 << endl; } void solve() { int a, b, c; cin >> a >> b >> c; if (a >= 2 && b >= 1) { output(a, b, c); return; } if (a == 1...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int k = 0; for (int i = 0; i < n; i++) if (a[i] > a[0] && a[i] < a[n - 1]) k++; cout << k; }
1
#include <bits/stdc++.h> using namespace std; int N; vector<int> nxt[1003]; vector<pair<int, int> > solve(int l, int r) { if (l + 1 >= r) return vector<pair<int, int> >(); int t = *lower_bound(nxt[r].begin(), nxt[r].end(), l + 1); vector<pair<int, int> > move; move.push_back(pair<int, int>(l, r)); vector<pair...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; const long long inf = 2e9; const int MAXN = 200000; const int MAXM = 200000; const int INF = 0x3f3f3f3f; struct Edge { int to, next, cap, flow, cost; } edge[MAXM]; int head[MAXN], tol; int pre[MAXN]; long long dis[MAXN]; bool vis[MAXN]; int N; void i...
5
#include <bits/stdc++.h> using namespace std; int row, col, n, m, q, cnt, ara[100000 + 5], ans[100000 + 5]; unordered_map<int, int> mark; void add(int pos) { if (mark[ara[pos]] == ara[pos]) --cnt; mark[ara[pos]]++; if (mark[ara[pos]] == ara[pos]) { cnt++; } } void del(int pos) { if (mark[ara[pos]] == ara[...
2
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #define MAXN 500010 #define LL long long using namespace std; const long double eps=1e-8; int n; LL V,px[MAXN]; long double py[MAXN]; pair<LL,long double> Q[MAXN]; int head=1,tail=1; long double getK(pair<LL,long double> t1,...
0
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e18; int cnt[1000]; double EE = 0.001; int main() { int n, m; float k; cin >> n >> m >> k; map<string, int> mapp; for (int i = 1; i <= n; i++) { string s; int x; cin >> s >> x; int kk = int((k + EE) * 100); int b = int(k...
1
#include <bits/stdc++.h> using namespace std; struct Scanner { bool hasNext = 1; bool hasRead = 1; int nextInt() { hasRead = 0; int res = 0; char flag = 1, ch = getchar(); while (ch != EOF && !isdigit(ch)) { hasRead = 1; flag = (ch == '-') ? -flag : flag; ch = getchar(); } ...
5
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > matmul(vector<vector<long long> > &a, vector<vector<long long> > &b) { int i, j, k, n = a.size(); vector<vector<long long> > ans(n, vector<long long>(n)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) ...
2
#include <bits/stdc++.h> using namespace std; stringstream ss; long long mod = 1000000007LL; int t[100010]; int in[100010]; vector<int> adj[100010]; int main() { int n, x; cin >> n; for (int i = 1; i <= n; i++) cin >> t[i]; for (int i = 1; i <= n; i++) { int x; cin >> x; in[x]++; if (x) adj[i].p...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxm = 500 + 10; const long long mod = 998244353; const int inf = 0x3ffffff; const double eps = 1e-5; int n, m; int h[11]; int cntc[maxn], cntf[maxn]; int dp[5010][510]; map<int, int> mp; int check(int x, int y) { for (int i = 0; i <= ...
6
#include <bits/stdc++.h> using namespace std; const long double PI = acos((long double)-1); namespace fft { template <class T> class comp { public: T real, img; comp(T a = (T)0, T b = (T)0) : real(a), img(b) {} comp conj() { return comp(this->real, -(this->img)); } comp operator=(const comp& a) { this->rea...
5
//ICPC2012C 偏りのあるサイコロ #include<iostream> #include<algorithm> #define FIELD 9 using namespace std; enum {S,E,N,W}; int top[FIELD][FIELD];//上面の目 int z[FIELD][FIELD];//高さ int side[3+1][4]={ {}, {3,5,4,2}, {3,1,4,6}, {1,2,6,5}, }; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; void print(int t,int f,int i){ cout<<t<<' ...
0
#include"bits/stdc++.h" using namespace std; int main() { int X, Y; cin >> X >> Y; if (X == 1 && Y == 1) { cout << 1000000 << endl; } else { cout << (max(4 - X, 0) + max(4 - Y, 0)) * 100000 << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; inline long long msb(long long val) { return 63 - __builtin_clzll(val); } inline int msb(int val) { return 31 - __builtin_clz(val); } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; } int main(){ ll n, t; cin >> n >> t; vector<vector<ll>> dp(t, vector<ll>(2)); for(ll i = 0; i < n; i++){ ll a, b; cin >> a >> b; ...
0
#include<map> #include<stack> #include<queue> #include<string> #include<math.h> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int P=139; const int mod=149; const int maxn=1e6+5; typedef long long ll; const int inf=0x3f3f3f3f; const int minn=0xc0c0c0c0; int n,ans,...
0
#include <bits/stdc++.h> using namespace std; int arr[10110]; int main() { int t; cin >> t; while (t) { int n, mi = 1000000; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int i = 1; i < n; i++) { if (mi > (arr[i] - arr[i - 1])) { mi =...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const long double pi = acos((ld)-1.0); const double eps = (double)1e-9; const int inf = 1e9 + 7; const int N = 505; int n; string s; int dp[N][N]; int calc(int l, int r) { int &res = dp[l][r]; if (res != -1) return res; if...
6
#include <bits/stdc++.h> using namespace std; int a[50005], b[50005]; string s[50005]; int main() { int t, n, m, i, j; char x; cin >> t; while (t--) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin >> n >> m; for (i = 0; i < n; i++) cin >> s[i]; for (i = 0; i < n; i++) for (j = ...
2
#include <iostream> #include <cmath> using namespace std; int main() { double v; while(cin >> v) { double y = v*v / 19.6; double N = (y+5.0) / 5.0; cout << ceil(N) << endl; } return 0; }
0
#include <bits/stdc++.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } using namespace std; int main() { int t = 0; cin >> t; bool *ans = new bool[t]{}; for (int i = 0; i < t; i++) { int a, b; cin >> a >> b; if (gcd(a, b) == 1) { ans[i] = true; } else { ans[i] = false;...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; v[i] = (v[i] % k == 0 ? 0 : k - v[i] % k); } map<int, long long> remc; for (int i : v) { rem...
4
#include <bits/stdc++.h> using namespace std; void print_digit(int a); void print_dahai(int a); int main() { int d; scanf("%d", &d); if (d < 10) { print_digit(d); return 0; } if (9 < d && d < 20) { switch (d) { case 10: printf("ten"); break; case 11: printf("ele...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int walk[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; struct ARROW { int x0, y0, x1, y1; ARROW *to[55]; long long dis[55]; int dir() { return x0 < x1 ? 0 : y0 < y1 ? 1 : x0 > x1 ? 2 : 3; } }; inline bool xl(ARROW *a, ARROW *b) { retu...
4
#include <bits/stdc++.h> using namespace std; void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int q, n, br[456789], ar[456789], d, k, sum, l, r, a[3], b, i; string s, t; bool ok[123]; void dii() { cin >> n >> d >> k; for (int i = 0; i < d; i++) { cin >> b; if (!ok[b]...
1
#include<bits/stdc++.h> using namespace std; long long ans = (-1)*1E10; int main(){ int n; cin >> n; int f[n][10],p[n][10]; for(int i=0;i<n;i++){ for(int j=0;j<10;j++){ cin >> f[i][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<11;j++){ cin >> p[i][j]; } } for(int i=1;i<(1<<10);...
0
#include <bits/stdc++.h> using namespace std; int n, q, x, y, c; struct data { int id, typ, x, y; data() { id = typ = x = y = -1; } data(int _id, int _typ, int _x, int _y) { id = _id; typ = _typ; x = _x; y = _y; } }; vector<data> v; int par[100005], canPar[100005]; vector<pair<int, int> > qq[100...
5
#include "bits/stdc++.h" #define REP(i,n) for(ll i=0;i<ll(n);++i) #define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i) #define FOR(i,m,n) for(ll i=m;i<ll(n);++i) #define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i) #define ALL(v) (v).begin(),(v).end() #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()); #define INF 1000000001ll #...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10, mod = 1e7 + 7, inf = 0x3f3f3f3f; int n, m, k, t; void up(long long &x, long long y) { if (x < y) x = y; } void ex_gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return; } ex_gcd(b, a % b, x,...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 5100, mod = 1e9 + 7; int n, m; char s[MAXN], t[MAXN]; int dp[MAXN][27], sum[MAXN]; int C[MAXN][MAXN]; int gmod(int x) { return ((x % mod + mod)) % mod; } int g(int x, int y) { return C[x + 1][y + 1]; } void init() { scanf("%d", &n); scanf("%s", s + 1); ...
4
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); i++) #define repp(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD 1000000007 #de...
0
#include <iostream> #include <set> #include <vector> #include <functional> using namespace std; typedef pair<int, int> P; void solve() { vector<P> Vec; set<int, greater<int> > Set; P p; while(~scanf("%d,%d", &p.first, &p.second)) { if(!p.first && !p.second) { break; } Vec.push_back(p); Set.insert(p....
0
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long INFll = 1ll * 1000000000 * 1000000000; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; int mul(int a, int b, int mod = 998244353...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int PRIME = 999983; const int MOD = 10007; const int MULTI = 1000000007; const double EPS = 1e-9; int x[256], sum[128], blg[128]; int main() { int n, cnt = 0, m = 0; scanf("%d", &n); for (int i = 0; i < 2 * n; i++) scanf("%d", &x[i]),...
2
#include <bits/stdc++.h> int main() { int d1, d2, d3, a, b, c, s; scanf("%d %d %d", &d1, &d2, &d3); s = d1 + d2 + d3; a = 2 * (d1 + d2); b = 2 * (d1 + d3); c = 2 * (d2 + d3); if (a < b && a < c && a < s) printf("%d", a); if (b < a && b < c && b < s) printf("%d", b); if (c < a && c < b && c < s) printf...
1
#include <bits/stdc++.h> #define N 200010 using namespace std; int cnt[N], n, k; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { int k; scanf("%d", &k); cnt[k]++; } sort(cnt + 1, cnt + 1 + n); int Ans = n; for (int i = n; i > n - k; i--) Ans -= cnt[i]; cout << Ans << endl; return 0; }
0
#include <iostream> #include <string> #include <sstream> using namespace std; int main () { int count; cin >> count; for (int x = 1; x <= count; x++) { long long n; cin >> n; stringstream ss; ss << n; cout << "Case " << x << ":" << endl; for (int i = 0; i <...
0
#include <stdio.h> int d, s, t; int main() { scanf("%d%d%d", &d, &s, &t); if (s * t < d)printf("No\n"); else printf("Yes\n"); }
0
#include <bits/stdc++.h> using namespace std; long long n, ans; char s[5]; long long get(char ch) { if (ch >= 'd' && ch <= 'f') return 'f' - ch + 1; if (ch <= 'c' && ch >= 'a') return ch - 'a' + 4; } int main() { cin >> n; scanf("%s", s); if ((n - 1) % 4 == 0 || (n - 1) % 4 == 1) { ans = (n - 1) / 4 * 12 ...
2
#include <bits/stdc++.h> using namespace std; long long n,k,now=1,a[223456][60]; int d(long long now,int k){ if(!a[now][k])a[now][k]=d(d(now,k-1),k-1); return a[now][k]; } int main(){ cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i][0]; for(int i=0;i<60;i++)if((k>>i)&1)now=d(now,i); cout<<now<<endl; }
0
/* Author : Arvinder Singh */ #include <bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void INPUT() { #ifndef ONLINE_JUDGE freopen("C:/Users/arvindersingh/Desktop/Current/input.txt", "r", stdin); freopen("C:/Users/arvindersingh/Desktop/Current/output.txt", "...
3
#include "bits/stdc++.h" using namespace std; bitset <333> a[333]; int n, m; const int mod = 998244353; long long pw[333]; int main(int argc, char const *argv[]) { scanf("%d %d", &n, &m); pw[0] = 1; for(int i = 1; i <= max(n, m); i++) { pw[i] = pw[i - 1] * 2; pw[i] %= mod; } for(int i = 0; i < n; i++) { fo...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long count = 0, total_count = 0; cin >> n; vector<int> front; vector<int> back; for (int i = 0; i < n; i++) { int l, f = 0; cin >> l; int ysb[l + 1]; for (int i = 0; i < l; i++) { cin >> ysb[i]; } for ...
2
#include <bits/stdc++.h> using namespace std; int a, b, num[100][100], heng[100][100], lie[100][100], i, j, n, m; int qiu(int a, int b) { int s, x, l, r, y, ans, i, j, k; if (a > n || b > m) return (10000000); ans = 10000000; k = 0; for (i = 1; i <= a; i++) k = k + heng[i][b]; for (i = 0; i <= m - b; i++) {...
2
#include <bits/stdc++.h> using namespace std; int n; int memo[200001]; int a[200001]; int b[200001][3]; int solve(int i) { if (i == n) { return memo[i] = 0; } int &ret = memo[i]; if (ret != -1) return ret; int x1 = 1e9, x2 = 1e9, x3 = 1e9; x1 = 20 + solve(b[i][0]); x2 = 50 + solve(b[i][1]); x3 = 120...
2
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fRand(double fMin, double fMax) { double f = (double)rand() / RAND_MAX; return fMin + f * (fMax - fMin); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T max(T a, T b, T c) { return max...
4
#include <bits/stdc++.h> using namespace std; int a[5010]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int q; cin >> q; while (q--) { int x; cin >> x; int ans = 22; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (x >= a[i...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 100 * 1000 + 10; int a[MAX], b[MAX]; int main() { ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; for (int i = (int)0; i < (int)n; ++i) cin >> a[i]; for (int i = (int)0; i < (int)m; ++i) cin >> b[i]; if (n > m) { cout << "YES" <...
2
#include <bits/stdc++.h> using namespace std; int N, H; int main(int argc, char *argv[]) { scanf("%d%d", &N, &H); for (int i = 1; i < N; ++i) { printf("%.12lf ", sqrt(double(i) / double(N)) * (double)H); } printf("\n"); return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, t, x, mx; char a[2000005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { string s; cin >> s >> t; int len = s.size(); int poz = -len; for (int j = 1; j <= t; j++) { cin >> x; for (int l = max(0, poz + len - x); l < len; l++...
3
#include<bits/stdc++.h> using namespace std; int main(){ long long a,b,n; cin>>a>>b>>n; long long x=min(n,b-1); cout<<a*x/b; return 0; }
0
#include<iostream> #include<iomanip> #include<vector> #include<string> #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i) #define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define riter(i, c) for (auto i = (c).r...
0
#include <bits/stdc++.h> using namespace std; int main() { int N, arr[100009], kkiri[100009], kknan[100009], idxmin[100009], temp, valmin, imin; scanf("%d", &N); temp = 0; kkiri[0] = 0; for (int i = 1; i <= N; i++) { scanf("%d", &arr[i]); temp += arr[i]; kkiri[i] = temp; } kkiri[N + 1] =...
3
#include<iostream> using namespace std; int main(){ int l, r; while (cin >> l >> r){ int ans = 0; for (int i = l; i <= r; i++){ int q = i; while (q % 2 == 0)q /= 2; while (q % 3 == 0)q /= 3; while (q % 5 == 0)q /= 5; if (q == 1)ans++; } cout << ans << endl; } }
0
#include <iostream> using namespace std; int main() { int a,b,x; cin>>a>>b>>x; if (a<=x and a+b>x) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }
0
#include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int main() { int w,n,a,b; cin >> w >> n; int* num = new int[w+1]; for(int i=0; i<w+1; i++){ num[i]=i;} for(int i=0; i<n; i++){ scanf("%d,%d", &a, &b); swap(num[a],num[b]); } for(int i=1; i<w+1; i++){ cout << num[i] << endl;} d...
0
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long nax = 2e6 + 10; vector<vector<int> > v; vector<long long> dep; void dfs(long long s, long long p) { for (int i = 0; i < v[s].size(); ++i) { if (v[s][i] == p) continue; dep[v[s][i]] = 1 + dep[s]; dfs(v[s][i], s); }...
3
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const int MAXN = 1e7; const int MAXLOGN = 30; long long qp(long long a, long long b, long long mod) { if (b == 0) return 1 % mod; long long hold = qp(a % mod, b / 2, mod) % mod; return (((hold * hold) % mod) * (b & 1 ? a % mod : 1)) % mod; } int p...
2
#include <bits/stdc++.h> using namespace std; int n, m, cntO, fa[300005], sz[300005], st[300005], ans[300005]; struct Edge { int u, v, w, id; } e[300005], e1[300005]; bool cmp(Edge x, Edge y) { return x.w == y.w ? x.id < y.id : x.w < y.w; } void clear() { cntO = n; for (int i = 1; i <= n; ++i) fa[i] = i, sz[i] = ...
5
#include <bits/stdc++.h> using namespace std; long long T; long long a, b, c, d, zz; int main() { cin >> T; while (T--) { cin >> a >> b >> c >> d; if (a > b * c) { cout << -1 << endl; continue; } if (c <= d - 1) { cout << a << endl; continue; } if (c > d - 1) { ...
5
#include <bits/stdc++.h> using namespace std; using int64 = long long int; const int kModulo = 998244353; int idiv(int value) { int u = value; int v = kModulo; int p1 = 1, q1 = 0; int p2 = 0, q2 = 1; while (v != 0) { int q = u / v; int p3 = p1 - q * p2; int q3 = q1 - q * q2; int r = u - q * v;...
6
#include<bits/stdc++.h> using namespace std; long long int N,M,K,T,H,W,L,R; int main() { cin>>N>>M>>K; N=abs(N); long long int num=N/K; if(num>=M) { cout<<N-M*K; return 0; } H=N%K; if((M-num)&1) { cout<<K-H; } else { cout<<H; } }
0
#include <algorithm> #include <cstdio> typedef long long LL; const int N=5005,M=205; LL a[N],sum[N],ans=0; int p[M][N],v[M][N],t[M],n,m; int main(){ scanf("%d%d\n",&n,&m); for (int i=2;i<=n;i++) scanf("%lld",&a[i]),a[i]+=a[i-1]; for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ int x; scanf("%d",&x); for (;...
0
#include <bits/stdc++.h> using namespace std; int main() { int h1,m1,h2,m2,k; cin >>h1 >>m1 >>h2 >>m2 >>k; cout <<60*h2+m2-60*h1-m1-k; }
0
#include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> graph; ifstream in("buffcraft.in", ios::in); ofstream out("buffcraft.out", ios::out); int main() { double m, R, ans = 0; cin >> m >> R; for (int x = 2; x < m; x++) ans += ((x - 1) * 2 + 2 * sqrt(2.0)) * 2 * (m - x); ans += 2 * m + (2 ...
2
#include <bits/stdc++.h> using namespace std; const int NMAX = 300010; int dp[NMAX][20]; int v[NMAX]; int dp2[20]; int n; int main() { int q; scanf("%d%d", &n, &q); for (int i = 1; i <= n; i++) { scanf("%d", v + i); for (int b = 0; b < 20; b++) { if (v[i] & (1 << b)) dp[i][b] = i; else...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; void solve(){ int n; cin >> n; ll x; cin >> x; ll maxi = 0, mini = 1e18; ll s = 0; for (int i=0; i<n; i++){ ll ai; cin >> ai; ll divi = (ai + x -1)/x; maxi += divi; s += ai; } mini = (s+x-1)/x; cout << mini <...
1
#include <iostream> using namespace std; int main() { for(int w,h;cin>>w>>h,w|h;){ int ci=0,cj=0; int di[]={0,1,0,-1},dj[]={1,0,-1,0},d=1; for(;;){ string cmd; cin>>cmd; if(cmd=="FORWARD"){ int n; cin>>n; ci+=di[d]*n; cj+=dj[d]*n; ci=max(ci,0); cj=max(cj,0); ci=min(ci,h-1); cj=min(cj,w-1)...
0
#include <bits/stdc++.h> using namespace std; long long arr[200005]; map<long long, int> mpp; int main() { int n; scanf("%d", &n); long long sum = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &arr[i]); sum += arr[i]; mpp[sum] = i; } long long bk = 0; long long res = 0; for (int i = n; i >...
3
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int mod = 1000000007; int main() { int n, k; double tot = 0; scanf("%d %d", &n, &k); int i, j; double t1; for (i = 1; i <= n; i++) { scanf("%lf", &t1); tot = tot + t1; } double basictot = tot; int add = 0; while ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a; int l = 0, x; for (int i = 1; i <= n; i++) a.push_back(i); for (int j = 0; j < k; j++) { cin >> x; l = (l + x) % n; cout << a[l] << " "; a.erase(a.begin() + l); n--; } }
2
#include <bits/stdc++.h> using namespace std; long long n, m, vf[5010]; bool ds[5010], dt[5010]; vector<long long> vt[5010], bk[5010]; vector<pair<long long, long long> > ed; void dfs(long long x) { long long i; ds[x] = true; for (i = 0; i < vt[x].size(); i++) { if (!ds[vt[x][i]]) { dfs(vt[x][i]); }...
5
#include <bits/stdc++.h> using namespace std; long long pw(long long b, long long p) { if (!p) return 1; long long sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long sd(long long x) { return x < 10 ? x : x % ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *A = new int[n]; int kol = 0; int kolO = 0; for (int i = 0; i < n; i++) { cin >> A[i]; if (A[i] == 0) { kolO++; } if (A[i] == 5) { kol++; } } if (kolO == 0) { cout << -1 << endl; retur...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 20; const int MOD = 998244353; const int INF = 0x3f3f3f3f; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1.0); const double RATE = 0.995; const double eps = 1e-6; std::mt19937 rnd(time(0)); long long qpw(long long a, long long b)...
4
#include <bits/stdc++.h> using namespace std; int main() { string str; cin>>str; for(int i=0;i<str.size();i++){ cout<<"x"; } }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int sum; int c; for(int bit=0;bit<(1<<3);bit++){ sum=s[0]-'0'; for(int i=0;i<3;i++){ if(bit&(1<<i)){ sum+=s[i+1]-'0'; } else{ sum-=s[i+1]-'0'; } } if(sum==7){c=bit;break;} } cout<<s[0]; for(int i=0;i<3;i++){...
0
#include <bits/stdc++.h> using namespace std; int res[13][2]; char tmp[10]; int main() { int n; scanf("%d", &n); for (int j = 0; j < 10; j++) res[j][0] = 0, res[j][1] = 1; for (int i = 1; i <= n; i++) { int v; scanf("%s%d", tmp, &v); for (int j = 0; j < 10; j++) { if (tmp[0] == '|') { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int i, n, j, xi, yi; cin >> n; int x[n], v[n], mox = 0; for (i = 0; i < n; i++) cin >> x[i]; for (i = 0; i < n; i++) cin >> v[i]; long double mid, low, high, t, mr, ml; low = 0; for (i = 0; i < n; i++) { if (mox < x[i]) { mox = x[i]; ...
2
#include<bits/stdc++.h> using namespace std; const long long md=998244353; long long n,m,k,ft[202020],ans; long long pw(long long x,long long y) { long long ans=1; while(y) { if(y&1) { ans*=x; ans%=md; } y>>=1; x*=x; x%=md; } return ans; } long long chu(long long x) { return pw(x,md-2); } long l...
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) typedef long long ll; typedef pair<int,int> P; int main(){ int n; cin >> n; vector<P> p(n); rep(i,n) { int v; cin >> v; p.push_back(P(v,i+1)); } sort(p.begin(),p.end(),greater<...
0
#include<bits/stdc++.h> using namespace std; #define lli long long int #define loop(i,a,b) for(lli i=a;i<b;i++) #define loopb(i,a,b) for (lli i=a;i>=b;i--) #define pb push_back #define mod 1000000007 #define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define mem(a,b) memset(a,b,sizeof(a)) #define gcd(a,b) ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char str[5]; vector<string> v; stack<bool> s; s.push(false); while (scanf("%s", str) == 1) { v.push_back(str); if (!strcmp(str, "int")) { while (!s.empty()) { if (!s.top()) { s.top() = true; ...
3
#include <bits/stdc++.h> using namespace std; inline long long bip(long long x, long long n, long long mod) { long long res = 1; while (n) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } const int maxn = 1e9; const int mod = 998244353; const int N = 2e5 ...
5
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926536; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int k = 0, s = 0; for (int i = 0; i <= 1000000 / 2; i++) { if (a[k] == i && k < n) { s = a[k] - 1; k++; } } k = n - 1; int ...
2
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcoun...
4
#include <bits/stdc++.h> using namespace std; template <class T> bool maximize(T &x, const T &y) { if (x < y) x = y; else return false; return true; } const int N = 3e5 + 10; int n; long long res = 0; int a[N]; pair<long long, long long> val[N], s[N], stand[N]; pair<long long, long long> Xor(pair<long lon...
6
#include <bits/stdc++.h> using namespace std; int t1[1000005], a[1000005], b[1000005], pos[1000005], gs[1000005], sk[1000005][2], mk[1000005], mx[1000005]; int n, m, bin, mnv, mxv, lwl, hl, tp, m1, m2, vl, vr, tpv; bool iv; inline int read() { int n = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') {...
6
#include<iostream> #include<vector> #include<algorithm> using namespace std; struct Piece { int w,d; Piece(int w=0,int d=0) : w(w), d(d) {} }; int main() { int n, w, d; while (cin >> n >> w>>d, n||w||d) { vector<Piece> pieces(1); pieces[0] = Piece(w,d); for(int i =0; i<n; i++) { int p,s; ...
0