solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; int main() { int n, k; cin >> n >> k; vector<int> p(n), c(n); rep(i, n) { cin >> p[i]; p[i]--; } rep(i, n) { cin >> c[i]; } ll ans = -1e18; rep(i, n) { int now...
0
#include <bits/stdc++.h> using namespace std; void init() { freopen("input.txt", "r", stdin); } void printDigit(signed long int x) { if (x < 5) { printf("O-|"); } else { printf("-O|"); } switch (x % 5) { case 0: printf("-OOOO"); break; case 1: printf("O-OOO"); break; ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen("input.in", "r")) { freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); } int n; cin >> n; long long a[maxn]; a[0] = 0; for (int i = 1; i <=...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cpu[101]; int ram[101]; int hdd[101]; int cost[101]; cost[0] = 1000000; for (int i = 1; i <= n; i++) cin >> cpu[i] >> ram[i] >> hdd[i] >> cost[i]; bool mark[101] = {false}; for (int i = 1; i <= n; i++) for (int j = 1...
2
#include <iostream> using namespace std; int main() { int n, m, t[110], h[110], ha, ta, a1, a2, best; bool ok; while (1) { ha=0; ta=0; ok=false; best=500; cin>>n>>m; if (n==0 && m==0) break; for (int i=0; i<n; i++) { cin>>t[i]; ta+=t[i]; } for (int i=0; i<m; i++...
0
#include<iostream> #include<algorithm> using namespace std; const int MAX = 1001; int sumj[MAX][MAX],sumo[MAX][MAX], sumi[MAX][MAX]; string data[MAX]; int x,y; void make(){ for(int i = 1; i <= y; i++){ for(int j = 1; j <= x; j++){ sumj[i][j] = sumj[i-1][j]+sumj[i][j-1]-sumj[i-1][j-1]; sumo[i][j] =...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<int, int>; const double eps = 1e-8; const ll MOD = 1000000007; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; template <typena...
0
#include <bits/stdc++.h> using namespace std; long long a1, a2, b1, b2, c1, c2, d1, d2; int main() { cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; for (int q = 0; q < 4; q++) { if (q == 0) { d1 = b1 - (a1); d2 = b2 - (a2); } if (q == 1) { d1 = b1 - (-a1); d2 = b2 - (-a2); } if...
5
#include <bits/stdc++.h> using namespace std; const long long MAXI = 1234567890123456LL; const long long SQRTMAXI = 32622776; const long long MOD = 998244353LL; const long long N = 111; vector<bool> sieve; vector<int> primes; vector<int> factor; unordered_map<long long, long long> mp; void init(long long n) { sieve =...
5
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; using namespace std; int main(int argc, char const *argv[]) { std::ios::sync_with_stdio(false); cin.tie(0); long long n, p, j, l, d1 = 0, d2 = 0, fd = 0, presses = 0, flag, foo = -1LL; string str; cin >> n >> p >> str; if (p > n / ...
3
#include <bits/stdc++.h> using namespace std; int n, p, s; int a[55]; long long memo[55][55][55][55]; double fact[55]; long long dp(int x, int sum, int cnt, int forb) { if (x == n) return (cnt == 0) && (a[forb] > sum); long long &dev = memo[x][sum][cnt][forb]; if (dev == -1) { dev = 0LL; if (sum >= a[x] &...
4
#include <bits/stdc++.h> const double PI = 3.141592653589793238462643383279502884197169399375105820974944; using namespace std; char a[2001][2001]; vector<pair<long long, long long> > dp[2001]; int x, y, r, c, n, m; bool visited[2001][2001]; void bfs(int r, int c) { deque<pair<long long, long long> > q; q.push_...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long n, m; cin >> n >> m; lon...
2
#include <bits/stdc++.h> using namespace std; #define C continue; #define R return #define int long long #define D double #define I insert #define ull unsigned long long #define ui unsigned int #define ld long double #define pb emplace_back #define pf push_front #define F first #define S second #define mp make_pair ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; long long k = 0, kol1 = 0; cin >> k; cin >> s; if (!(s[0] == ')') and !(s.size() >= 3 and (s[s.size() - 2] == '('))) { vector<int> ar(s.size(), 0); long long kolx = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '(') {...
3
#include <bits/stdc++.h> using namespace std; const int N = 2048; int v[N]; int ss[N]; int vv(char c) { return c == 'W' ? 0 : c == 'R' ? 1 : c == 'Y' ? 2 : 3; } bitset<N> a[N]; bool ha[N] = {false}; void gg() { puts("NO"); exit(0); } int n, k; void ins(bitset<N> &b) { for (int i = 2 * n; i >= 0; i--) { if (b[...
6
#include <cstdio> int w[] = { 2, 3, 5, 10, 12, 15 }; int v[] = { 380, 550, 850, 1520, 1870, 2244 }; int n = 6; #define M 50 #define INF 10000000 #define min(x, y) ((x) < (y) ? (x) : (y)) int dp[M+10]; int main() { for (int i = 0; i <= M; ++i) dp[i] = INF; for (int i = 0; i < n; ++i) dp[w[i]] = v[i]; for (int i = ...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long q, a, z; cin >> q; while (q--) { cin >> a; z = a % 4; if (z == 0) { cout << a / 4 << "\n"; } else if (z == 1 && a >= 9) { cout << a / 4 - 1 << "\n"; } else if (z == 2 && a >= 6) { cout << a / 4 << "\n"; ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 5005; vector<int> cand[maxn], repl[maxn]; int n, m; int t[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { int ai, bi; cin >> ai >> bi; cand[ai].push_bac...
1
#include <bits/stdc++.h> using namespace std; int n; long long x[100005], y[100005]; bool solve(int pos) { long long temp = x[pos + 1]; for (int i = sqrt(temp); i >= 1; i--) { if (temp % i || (i + temp / i) % 2) continue; long long tx = (i + temp / i) / 2, ty = (temp / i - i) / 2; if (ty > y[pos - 1]) {...
5
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int n, k, t, pre = 0, buf = INT_MAX, bef = 0; cin >> n >> k; bool flag = false, fz = false; for (int i = 0; i < n; i++) { cin >> t; if (fz) { fz = false; buf = t; } if (k ==...
1
#include <bits/stdc++.h> using namespace std; void print(list<int> *gr, int n) { for (int i = 1; i < n; ++i) { cout << i << "->"; for (auto nbr : gr[i]) { cout << nbr << " "; } cout << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, t; cin >> n >> t; if (t == 1...
1
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } int n, k, f[80][80...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ara[32]; for (int i = 0; i <= 30; i++) { ara[i] = pow(2, i) - 1; } int x = n; vector<int> v; int f = 0; int cnt = 0; for (int i = 0;; i++) { for (int j = 0; j <= 30; j++) { if (x == ara[j]) { f = 1;...
2
#include <bits/stdc++.h> using namespace std; int main() { set<pair<int, int> > s; int i, n, m, k, t, a, b; cin >> n >> m >> k >> t; vector<int> v(t + 1); for (i = 0; i < k; i++) { scanf("%d%d", &a, &b); s.insert(make_pair((a - 1) * m + b, 0)); } for (i = 0; i < t; i++) { scanf("%d%d", &a, &b)...
2
#include <bits/stdc++.h> int main() { int i, n, m, count = 0; scanf("%d%d", &n, &m); while (n > 0 && m > 0) { if (n > m && n >= 2) { n -= 2; m--; count++; } else if (m > n && m >= 2) { m -= 2; n--; count++; } else if (n == m && m >= 2) { m -= 2; n--; ...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=998244353; const int N=2e5+10; ll f[N]; ll invf[N]; ll invmod(int a,int b) { if(b==0||b==1) return a; ll k=invmod(a,b/2); k=(k*k)%mod; if(b%2) k=(k*a)%mod; return k; } ll solve(int a, int b) { ll k=(f[a]...
4
#include <bits/stdc++.h> using namespace std; int n; vector<char> g[100500]; void say() { cout << "NO"; exit(0); } void update(int x) { if (g[x].size() < g[x - 1].size()) say(); else if (g[x].size() > g[x - 1].size()) { for (int i = 0; i < g[x].size(); i++) { if (g[x][i] == '?') { if (i ==...
5
#include <bits/stdc++.h> using namespace std; int main() { double a, d; int n; int ar[4][2]; double v[4][2]; memset(ar, 0, sizeof(ar)); while (cin >> a >> d >> n) { ar[0][1] = 1, v[0][0] = a, v[0][1] = 0; ar[1][0] = 1, v[1][0] = a, v[1][1] = a; ar[2][1] = 1, v[2][0] = 0, v[2][1] = a; ar[3][0...
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; double sqrt3 = sqrt(3.0); long long N, ans, pos, inicio, fin, pp; double dis(double x, double y) { return x * x + y * y; } bool sePuede(double x, double y) { if (dis(x, y + 1) - eps > N * N) return 0; if (dis(x, y - 1) - eps > N * N) return 0; ...
4
#include"bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++) #define REP(i,n) FOR((i),0,(n)) #define WAITING(str) int str;std::cin>>str; #define DEBUGING(str) cout<< #str << " " str<<en...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll x ;cin>>x; ll ans = x/11ll * 2ll; x%=11ll; if( x ) ans += ((x>6)?2ll:1ll); cout<< ans <<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long a[100010], on[100010], off[100010], n, M; int main(int argc, char *argv[]) { while (cin >> n >> M) { a[0] = 0; a[n + 1] = M; for (long long i = 1; i <= n + 1; i++) { if (i < n + 1) cin >> a[i]; if (i % 2) { on[i] = on[i - 1] + a[i...
2
#include <bits/stdc++.h> using namespace std; bool is_prm(int a) { for (int i = 2; i < a; i++) { if (a % i == 0) return 0; } return 1; } int main() { long long c; int n, i, j, k, l, r, len; int d, M, mx, p, B, test; char s[111]; vector<long long> a; vector<int> I; vector<int> lng(30, 0); vecto...
5
#include <bits/stdc++.h> using namespace std; double s[100020], r[100020]; int n; double k; bool check(double x) { double tol = 0; for (int i = 1; i <= n; i++) { if (r[i] < x * s[i]) { tol += x * s[i] - r[i]; } } if (tol > x * k) return false; else return true; } int main() { cin >> n ...
1
#include <bits/stdc++.h> using namespace std; int avl, ara[35004], lst[35004], seg[40 * 35004], lft[40 * 35004], rght[40 * 35004], version[35004], suf[35004]; int update(int n, int s, int e, int indx, int val) { if (s == indx && e == indx) { seg[++avl] = seg[n] + val; return avl; } if (s > indx || e <...
4
#include <bits/stdc++.h> using namespace std; vector<long long> mar; long long n, k; map<long long, long long> br; long long wy(long long tp) { long long bst = k + 1; br.clear(); for (long long i = 0; i < (n); ++i) { for (long long j = 0; j < (k + 1); ++j) { if (j * mar[i] > tp) continue; if (br.f...
5
#include <bits/stdc++.h> using namespace std; long long ans[500010], vis[500010]; struct tp { long long min, idx; } tree[500010 * 3]; tp combine(tp a, tp b) { return a.min < b.min ? a : b; } long long arr[500010]; void build(long long at, long long left, long long right) { if (left == right) { tree[at].min = ar...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int sc = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar(); return sc * f; } int main() { int n = read(); ...
5
#include <bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; for(int i = sqrt(n); i>=0; i--) { if(!(n % i)) { cout << i-1+(n/i-1); break; } } }
0
#include <bits/stdc++.h> const bool unsyncedio = std::ios::sync_with_stdio(false); using namespace std; int main() { int n, z; cin >> n >> z; vector<int> x(n); vector<int> id(n); for (long long i = 0; i < (n); i++) { cin >> x[i]; id[i] = i; } sort(x.begin(), x.end()); int lidx = n / 2; int i =...
3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void f(long long a, long long b, bool bl) { if (b == 1) { printf("%I64d%c", a - 1, 65 + bl); return; } printf("%I64d%c", a / b, 65 + bl); f(b, a % b, !bl); } int main() { long long a...
3
#include <bits/stdc++.h> using namespace std; bool a[210] = {0}; bool testcase = 1; void SieveOfEratosthenes() { long long n = 200; memset(a, true, 210); for (long long p = 2; p * p <= n; p++) { if (a[p] == true) { for (long long i = p * p; i <= n; i += p) a[i] = false; } } } long long gcd(long lo...
2
#include <bits/stdc++.h> using namespace std; void dfs(vector<int> adj[], vector<int>& in, vector<int>& val, vector<int>& vis, int i, vector<int>& arr) { int j; for (j = 0; j < adj[i].size(); j++) { if (vis[adj[i][j]] == -1) { vis[adj[i][j]] = 1; in.push_back(adj[i][j]); val.push_back...
2
#include <bits/stdc++.h> using namespace std; long long n, m, ans, c, d, k, tot, x, y, t, r, p, a[1001][1001]; int main() { cin >> n >> k; if (n < 2 * k + 1) { cout << -1; return 0; } cout << n * k << endl; for (int i = 1; i <= n; i++) for (int j = i; j < k + i; j++) printf("%d %d\n", i, j % n + 1...
3
#include <bits/stdc++.h> using namespace std; const int N = 100000; int n; tuple<int, int, int> a[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &get<0>(a[i])); for (int i = 0; i < n; ++i) scanf("%d", &get<1>(a[i])); for (int i = 0; i < n; ++i) get<2>(a[i]) = i + 1; sort(a, a + n); ...
4
#include <bits/stdc++.h> using namespace std; int main() { string str; long long int nb, ns, nc, push_back, ps, pc, money; cin >> str >> nb >> ns >> nc >> push_back >> ps >> pc >> money; long long int b, s, c; b = s = c = 0; for (long long int i = 0; i < str.size(); i++) { if (str[i] == 'B') b++; if...
3
#include <bits/stdc++.h> using namespace std; class C_ {}; template <typename T> C_& operator<<(C_& m, const T& s) { if (!1) cerr << "\E[91m" << s << "\E[0m"; return m; } C_ merr; int B[111111]; int A[111111]; int main(void) { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> B[i]; } for (...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr = vector<int>(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } if (n == 1) { cout << 0 << endl; return 0; } int maxCount = 0; int count = 0; if (arr[0] == 1 && arr[1] == 2) count++; for (int i...
1
#include <iostream> #define llint long long #define mod 1000000007 using namespace std; llint fact[2005], fact_i[2005]; llint pow(llint a, llint n) { if(n == 0) return 1; if(n % 2){ return ((a%mod) * (pow(a, n-1)%mod)) % mod; } else{ return pow((a*a)%mod, n/2) % mod; } } void make_fact() { llint val = 1; ...
0
#include<iostream> #include<algorithm> #include<math.h> #include<queue> #include<vector> #include<climits> #include<map> #include<string> #include<functional> #include<iomanip> #include<deque> #include<random> #include<set> using namespace std; typedef long long ll; typedef double lldo; #define mp make_pair #define pu...
0
#include <bits/stdc++.h> using namespace std; int n, m; int route[2010], newRoute[2010]; int a[110][110], b[110][110]; int na[110]; void read() { cin >> n >> m; int i; memset(na, sizeof(na), 0); for (i = 0; i < m + 1; i++) if (i == 0) cin >> route[i]; else { cin >> route[i]; a[route[i]...
4
#include <algorithm> #include <numeric> #include <queue> #include <iostream> #include <iomanip> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) struct Event { double time; function<void ()> proc; Event(double time, function<void ()> proc): time(time), proc(proc) {} bool operator<(const E...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; int dp[500010], color[500010]; int n; long long N, ans; int mypow(int x, int n) { int res = 1; while (n) { if (n & 1) res = 1ll * res * x % inf; x = 1ll * x * x % inf; n >>= 1; } return res; } int main() { scanf("%d", &n); ...
6
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 17; const int MOD = 1000 * 1000 * 1000 + 7; using pt = pair<int, int>; int n = 3; pt p[3]; bool read() { if (!(cin >> p[0].first >> p[0].second >> p[1].first >> p[1].second >> p[2].first >> p[2].second)) return false; return true; ...
1
#include<stdio.h> #include<stdlib.h> #include<string> #include<iostream> using namespace std; struct Node { int key; Node *right, *left, *parent; }; Node *root,*NIL; Node * treeMinimum(Node *x) { while(x->left != NIL) x=x->left; return x; } Node * find(Node *u,int k) { while(u!=NIL&&k!=u->key) { ...
0
#include <bits/stdc++.h> using namespace std; char s1[3000], s2[3000]; int f[2005][2005]; int main() { int l1, l2, ans, i, j, add; cin >> s1; cin >> s2; l1 = strlen(s1); l2 = strlen(s2); ans = l2; for (i = 0; i < l2; i++) { if (s2[i] == s1[l1 - 1]) f[l1 - 1][i] = 1; else f[l1 - 1][i] =...
1
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; using namespace std; const long long INF = 1LL << 60; const double PI = acos(-1); using ll = long long; using P = array<ll, 2>; template <typename T> istream& operator>>(istream& i, vector<T>& v) { for (ll j = (0); j < (ll)(v.size()); ++j) i >> v[j]; return i;...
2
#include <bits/stdc++.h> const int MAXN = 1e4 + 10; using namespace std; vector<int> vec[MAXN << 2]; int vul, n, q; void update(int rt, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) { vec[rt].push_back(vul); return; } int mid = (l + r) >> 1; if (ql <= mid) update(rt << 1, l, mid, ql, qr); if...
5
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { int r = x % y; while (r != 0) { x = y; y = r; r = x % y; } return y; } int main() { int n, m, x, y, a, b; cin >> n >> m >> x >> y >> a >> b; int o, p; o = a / gcd(a, b); p = b / gcd(a, b); int s = (int)n / o, l = (int)...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const int MINF = 0x80000000; const int mod = 1000000007; const int cons = 100001; int main() { int t; scanf("%d", &t); while (t--) { long long n; scanf("%I64d", &n); long long sum = n * (n + 1) / 2; for (int i = 0; (1LL << i...
1
#include <bits/stdc++.h> using namespace std; void ga(int N, long long* A) { for (int i(0); i < N; i++) scanf("%lld", A + i); } long long W; struct TK { multiset<long long> U, L; long long S; void nr() { long long a, b; while (!L.empty() && (long long)U.size() < W) S += -*L.begin() / 2, U.insert(-...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; (s[2]==s[3] && s[4]==s[5]) ? cout<<"Yes\n":cout<<"No\n"; }
0
#include <bits/stdc++.h> using namespace std; const int MX = 200111; double dp[MX][55]; int Q[55][2 * MX], t[MX]; int L[55], R[55]; double g[MX], s[MX], f[MX]; int n, K; inline double Cross(double ax, double ay, double bx, double by) { return ax * by - ay * bx; } inline double Y(int j, int k) { return dp[j][k] - g[j]...
5
#include <bits/stdc++.h> using namespace std; inline int take() { int s = 0, t = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') t = -1; c = getchar(); } while (isdigit(c)) s = s * 10 + c - 48, c = getchar(); return s * t; } struct node { int v, t; bool operator<(const node& rhs) cons...
5
#include <bits/stdc++.h> using namespace std; int a[100009 + 1], v[100009 + 1]; struct node { long long v[5]; int s; } aint[265009]; int k, poz, val; inline int caut(int a, int v[], int n) { int rez = 0; for (int pas = 1 << 16; pas; pas >>= 1) if (rez + pas <= n && v[rez + pas] <= a) rez += pas; return re...
4
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 9; const long long mod = 1e9 + 7; const long long maxn = 2e5 + 8; long long n, m, a[maxn]; void solve() { long long i, j, u, v; string s; cin >> n >> s; sort(s.begin(), s.end()); cout << s << endl; } signed main() { ios_base::sync_wi...
1
#include <bits/stdc++.h> using namespace std; int n; bool a[100], b[100]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int I = 0, i, j; I < n * n; I++) { cin >> i >> j; i--; j--; if (a[i] == 0 && b[j] == 0) { b[j] = 1; a[i] = 1; cout << I + 1 << " "; } ...
1
#include <bits/stdc++.h> using namespace std; char s[5555]; inline long long get(int st, int fn) { long long ans = 0; for (int i = st; i <= fn;) { long long cur = s[i] - '0'; while (i < fn && s[i + 1] == '*') { i += 2; cur = cur * (s[i] - '0'); } ans += cur; i += 2; } return ans;...
5
#include <bits/stdc++.h> using namespace std; const int max_int = numeric_limits<int>::max(); unsigned long long gcd(unsigned long long x, unsigned long long y) { return y > 0 ? gcd(y, x % y) : x; } unsigned long long lcm(unsigned long long x, unsigned long long y) { unsigned long long r = x / (x > y ? gcd(x, y) : ...
3
#include <bits/stdc++.h> using namespace std; int main() { int N; cin>>N; vector<tuple<string,int,int>> res; for(int i=0;i<N;i++){ string S; int P; cin>>S>>P; res.push_back(make_tuple(S,100-P,i+1)); } sort(res.begin(),res.end()); for(tuple<string,int,int> t:res){ cout<<get<2>(t)<<endl...
0
#include <bits/stdc++.h> using namespace std; string arr[150], e[150]; long long n, m; bool isinc(int i) { for (int j = 1; j < n; j++) { if (arr[j][i] < arr[j - 1][i]) return false; } return true; } bool isinc1(int i) { for (int j = 1; j < n; j++) { if (arr[j][i] < arr[j - 1][i]) { if (e[j] == e[j...
3
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (int a = v1; a < v1 * 2 + 1; a++) { for (int b = v2; b < min(a, v2 * 2 + 1); b++) { for (int c = v3; c < min(b, v3 * 2 + 1); c++) { if (c >= vm && 2 * vm >= c && 2 * vm < b) { ...
1
//ABC152-E Flatten より #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; int gcdi(int a, int b) { if(a<0) a=b; if(b<0) b=a; if (b == 0) return a; return gcdi(b, a%b); } int main()...
0
#include <bits/stdc++.h> #define va first #define vb second using namespace std; typedef long long ll; typedef pair<int, int> pii; int N, mx; ll ans; int A[101010], B[101010]; set<int> st; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N; for (int i=0; i<N; i++) cin >> A[i]; for (int i=0; i<N; i...
0
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; const long long MOD2 = (long lon...
5
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n,a[100000]; cin>>n; for(int i=0;i<n;i++)cin>>a[i]; ll ans=a[0]-1,t=2; for(int i=1;i<n;i++){ if(a[i]==t)t++; if(a[i]>t){ if(a[i]%t)ans+=a[i]/t; else ans+=((a[i]-t)/t); } } cout<<ans<<endl; return 0...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> a >> b >> c; int x, y, z; cin >> x >> y >> z; int q = a - x; int w = b - y; int e = c - z; int extra = 0; if (q > 0) extra += q / 2; if (w > 0) extra += w / 2; if (e > 0...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int a, b, c; cin >> a >> b >> c; while (a > 0) { if ((b / 2 >= a) && (c / 4 >= a)) { b = a * 2; c = a * 4; break; } else { a--; } } if (a == 0) { cout << 0; } else { cout << ...
1
#include <bits/stdc++.h> using namespace std; int dir[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}}; const long long INF = 0x7f7f7f7f7f7f7f7f; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-6; const long long mod = 1e9 + 7; inline long long read() { long long x = 0; bool f = true; ch...
3
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, k, a[N]; int main() { int ans = 0; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < k; i++) { int one = 0, two = 0; for (int j = i; j < n; j += k) { if (a[j] == 1) one++; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<char> st; for (int i = 0; i < s.size(); i++) { while (!st.empty() && st.top() < s[i]) { st.pop(); } st.push(s[i]); } stack<char> st1; while (!st.empty()) { st1.push(st.top()); st.pop(); } whi...
1
#include<iostream> using namespace std; int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int main(){ int w,h,c; cin>>w>>h>>c; int x=w*h/gcd(w,h); cout<<x/w*x/h*c<<endl; return 0; }
0
#include <bits/stdc++.h> const int N = 2e5 + 5; int a[N]; long long sum[N]; struct Line { int a; long long b; long long get(int x) { return 1ll * a * x + b; } }; struct Convex_hull { int sz; Line *hull; Convex_hull(int maxn) { hull = new Line[++maxn]; sz = 0; } void clear() { sz = 0; } bool is...
5
#include <string> #include <iostream> #include <math.h> #include <algorithm> #include <vector> #include <iomanip> #include <map> #include <set> typedef long long ll; const int mod=1e9+7; #define lol(i,n) for(int i=0;i<n;i++) using namespace std; int n,a[100010],b[100010]; //vector<pair<int,int>> a; ll sum=0,s=0; int m...
0
#include <bits/stdc++.h> using namespace std; bool two[10005] = {0}; bool three[10005] = {0}; int main() { string s; cin >> s; set<string> ans; two[s.size()] = three[s.size()] = 1; for (int i = s.size() - 2; i >= 5; i--) { string p = string(1, s[i]) + string(1, s[i + 1]); if (three[i + 2]) { ans...
3
#include<bits/stdc++.h> using namespace std; bool DFS(string q){ if(q=="ABC")return 1; if(q.size()<5)return 0; string x="";char z='B'; if(q.substr(0,3)=="ABC")z='A'; if(q.substr(q.size()-3,3)=="ABC")z='C'; int i=0; while(i<q.size()){ if(q.substr(i,3)=="ABC"){x.push_back(z);i+=3;} else{if(q[i]==z)return 0;x.p...
0
#include <iostream> #include <bitset> #include <vector> #include <string> #include <map> #include <algorithm> #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; string adj(string a, string b, unsigned long int m) { if(a.find(b) != string::npos) return a; int mmch = 0; REP(i,min(m,min(a.size(),b....
0
#include <bits/stdc++.h> using namespace std; int main() { char s[100010]; int b[100010], i, j, k = 0, c, c1, l, f = 0, a, j1, f1; scanf("%s", s); l = strlen(s); c = 0; for (i = 0; i < l; i++) { if (s[i] == '(') c++; else if (s[i] == ')') c--; else if (s[i] == '#') { a = 1; ...
3
#include <bits/stdc++.h> using namespace std; struct point { long long x, y; } C[100010]; long long triArea2(const point &a, const point &b, const point &c) { return (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)); } bool inConvexPoly(int nc, const point &p) { int st = 1, en = nc - 1, mid; while (en...
2
#include<bits/stdc++.h> #define fastasfuckboi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define test int t;cin>>t;while(t--) #define REP(i,n) for(int i=0; i<n;i++) #define rep(i,a,b) for(int i=a;i<b;i++) #define mod 1000000007 #define mod2 998244353 #define ll long long #define...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, i, j; cin >> n >> k; vector<long long> a(n); for (i = 0; i < n; ++i) cin >> a[i]; sort(a.begin(), a.end()); unordered_set<long long> s; s.insert(a.begin(), a.end()); long long ans = 0; for (i = 0; i < n; ++i) { if (s.count(...
3
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; long long MOD = 1e9 + 7; int a[1111]; int main() { int n; cin >> n; int l = -1; int res = 0; int t = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int x; x = a[n - 1 - i]; if (l == -1) { ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000006; string A, a, b; int h1[MAXN], h2[MAXN], pw[MAXN]; int f1[MAXN], f2[MAXN]; void Hash() { pw[0] = 1; for (int i = 1; i < MAXN; i++) { pw[i] = pw[i - 1] * 257; } h1[0] = A[0]; h2[0] = b[0]; for (int i = 1; i < A.size(); i++) { h1[i...
4
#include <bits/stdc++.h> using namespace std; int main() { int t, n, c0, c1, h; scanf("%d", &t); while (t--) { scanf("%d %d %d %d ", &n, &c0, &c1, &h); int cost = 0; if (c0 + h < c1) c1 = c0 + h; if (c1 + h < c0) c0 = c1 + h; for (int i = 0; i < n; i++) cost += getchar() == '0' ? c0 : c1; ...
1
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define MAXCOST 50000 double dp[51][MAXCOST+1]; int v[4]; struct INFO{ int type,val; INFO(){type=0;val=0;}; }; INFO mass[51]; int main(){ int x,y,z; while(cin >> x >> y >> z , x){ rep(i,51)mass[...
0
#include <bits/stdc++.h> using namespace std; int main() {string A, B; cin >> A >> B; cout << (A == B ? "EQUAL" : vector<string>{"GREATER", "LESS"}[A.size() == B.size() ? A < B : A.size() < B.size()]);}
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; const int N = 1e5 + 100; int a[N], k, n; bool check(int x) { if (x < 1 || x > n) return false;...
4
#include <bits/stdc++.h> using namespace std; vector<int> p; vector<vector<int>> decomp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; p.resize(n); for (int i = 0; i < n; ++i) cin >> p[i], --p[i]; { vector<bool> vis(n, false); for (int i = 0; i < n; ++i) { if (n...
2
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int base, long long int pow) { long long int res = 1; while (pow) { if (pow % 2 != 0) res = (res * base) % 1000000007; base = (base * base) % 1000000007; pow /= 2; } return res; } long long int cumfreq[(long long int)100000...
5