solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n; cin >> n; double a[103]; for (int i = 0; i < n; i++) scanf("%lf", &a[i]); sort(a, a + n); double ans = 0.0, curr = 1.0; for (int i = n - 1; i >= 0; i--) { if (ans < ((ans * (1.00 - a[i])) + (curr * (a[i])))) ...
2
#include <bits/stdc++.h> using namespace std; int x[300005]; int y[300005]; int z[300005]; long long FT[4][300005]; vector<int> g[300005]; void add(int t, int idx, long long amt) { while (idx < 300005) { FT[t][idx] += amt; idx += idx & -idx; } } long long sum(int t, int idx) { long long ret = 0ll; while...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k, u; cin >> n >> k; int i, j; set<string> set; vector<string> v(n); for (i = 0; i < n; i++) { cin >> v[i]; set.insert(v[i]); } int cnt = 0; for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { string g = ""; ...
2
#include <bits/stdc++.h> using namespace std; int getVal(int a, int b, int c, int d) { int e = d - '0'; e += (c - '0') * 10; e += (b - '0') * 100; e += (a - '0') * 1000; return e; } int main() { int n; cin >> n; vector<int> v(n); set<int> st; char a, b, c, d; int me, e; for (int i = 0; i < n; ++...
1
#include<iostream> #include<cmath> using namespace std; int main(){ int n; cin >> n; while(n-- > 0){ int x = 0, y = 0, dx, dy, ma = 0, ansx, ansy; while(cin >> dx >> dy, dx+dy){ x += dx, y += dy; if(x*x+y*y > ma || (x*x+y*y == ma && x > ansx)){ ma = x...
0
#include <bits/stdc++.h> using namespace std; void solve() { int N; cin >> N; if (N % 2) { cout << "black" << endl; } else { cout << "white" << endl; cout << 1 << ' ' << 2 << endl; } } int main() { solve(); return 0; }
4
#include <bits/stdc++.h> using namespace std; string getStr(string s1) { string p = ""; for (int i = 0; i < s1.size(); i++) { if ((s1[i] >= 'a' && s1[i] <= 'z') || (s1[i] >= 'A' && s1[i] <= 'Z')) p += tolower(s1[i]); } return p; } int main() { string s1, s2, s3; cin >> s1 >> s2 >> s3; int n; c...
2
#include <bits/stdc++.h> using namespace std; long long f[100][3]; long long s, x; vector<int> sm, xr; long long dfs(int j, int g) { if (j == sm.size()) { return (g == 0); } long long &res = f[j][g]; if (res != -1) { return res; } res = 0; if (g == 0 && xr[j] == 0 && sm[j] == 0) { res = dfs(j ...
1
#include <bits/stdc++.h> using namespace std; const int max_n = 200222, inf = 1000111222; int n, a[max_n], b[max_n]; map<int, vector<int>> m; set<int> all; long long ans; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = 0; i < n; ++i) { scanf("%d", &b[i]); ...
1
#include <bits/stdc++.h> using namespace std; const int N = 200003; string s, t; int n, m, lft[N], rht[N]; bool solve(int L) { bool c = 0; for (int i = 1; i < n - L; i++) { int lf = lft[i - 1], rt = rht[i + L]; if (lf >= rt || rt - lf < 2) { c = 1; break; } } if (rht[L] == 0) c = 1; if...
4
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; if(a+b==15) cout<<'+'; else if(a*b==15) cout<<'*'; else cout<<'x'; cout<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long w1, h1, w2, h2; cin >> w1 >> h1 >> w2 >> h2; long long ans = h1 + h2 + 2; ans += h1 + h2 + 2 + (w1 - w2); ans += w1 + w2; cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxN = 2005; const int dx[10] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; const int dy[10] = {0, 1, -1, 0, 0, -1, 1, -1, 1}; int n, area, sx, sy; bool p[maxN][maxN], vis[maxN][maxN]; void init() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n;...
5
#include<bits/stdc++.h> using namespace std; const double pi=acos(-1.0); int main(){ int a,b,x; scanf("%d%d%d",&a,&b,&x); if(a*a*b>=(x<<1)){ printf("%.8f\n",atan((double)a*b*b/(x*2))*180/pi); }else{ printf("%.8f\n",atan((double)(2*b-2.0*x/(a*a))/a)*180/pi); } }
0
#include <bits/stdc++.h> using namespace std; vector<int> A, B; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; A.push_back(x); } for (int i = 0; i < n; i++) { int x; cin >> x; B.push_back(x); } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); ...
3
#include <bits/stdc++.h> using namespace std; const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; int n, m; char s[1010][1010]; bool vis[1010][1010]; bool fail(int x, int y) { return x < 1 || y < 1 || x > n || y > m || s[x][y] == '.'; } int main() { scanf("%d%d", &n, &m); f...
2
#include <bits/stdc++.h> using namespace std; struct paire { int pos; int val; }; bool sortbyval(const paire &a, const paire &b) { return (a.val < b.val); } bool sortbypos(const paire &a, const paire &b) { return (a.pos < b.pos); } int main() { int n; cin >> n; paire a[n]; for (int i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; long long t, n, k, d1, d2, a, b, c; bool func(long long x, long long y) { long long sum = 2 * x + y; if (k - sum >= 0 && (k - sum) % 3 == 0) { a = (k - sum) / 3; b = a + x; c = b + y; if (a < 0 || b < 0 || c < 0) return 0; long long maxx = max(a, max...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int i; int n; cin>>n; int a[n],b[n]; for (i = 0 ; i < n ; i++) cin>>a[i]; for (i = 0 ; i < n ; i++) cin>>b[i]; int s[3*n+2]; s[0] = -2; for (i = 1; i < n+1 ; i++)...
0
#include <bits/stdc++.h> using namespace std; const int N = 60; int n; int a[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int x; scanf("%d", &x); a[i] = max(a[i], x); } } for (int i = 0; i < n; i++) if (a[i] == n - 1) { a[i] = ...
2
#include<bits/stdc++.h> using namespace std; #define pii pair<long long,long long> #define ppi pair<long long, pair<long long, long long>> #define pq priority_queue #define v vector<long long> #define pb push_back #define mp make_pair #define setbits(x) __builtin_popcountll(x) #...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; signed main() { std::ios::sync_with_stdio(0); std::cin.tie(0); ; int t; cin >> t; while (t--) { int n; cin >> n; vector<unordered_set<int>> v; for (int i = 0; i < n - 1; i++) { int k; cin >> k; unordered...
6
#include <bits/stdc++.h> int main() { char str[200000] = {0}; int n, i = 0, value = 0, arr[27] = {0}, key = 0; scanf("%d", &n); scanf("%s", str); while (str[i * 2 + 1] && i <= 100000) { arr[str[i * 2] - 'a']++; arr[str[i * 2 + 1] - 'A']--; if (arr[str[i * 2 + 1] - 'A'] < 0) { arr[str[i * 2 +...
1
#include<iostream> #include<cstring> #include<string> #include<queue> #include<map> #include<algorithm> using namespace std; map<string,int>dp; int dx[4]={1,-1,4,-4}; void bfs() { queue<string>que; string p; p="01234567"; dp[p]=0; que.push(p); while(que.size()) { string q; q=que.front(); que.pop(); int k; ...
0
#include <iostream> using namespace std; int n; double xa,xb,xc,xd,ya,yb,yc,yd,ta,tb,tc,td; int main(){ int i; cin >> n; for(i=0;i<n;i++){ cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd; ta = xa - xb; tb = ya - yb; tc = xc - xd; td = yc - yd; if(tc/td == ta/tb) cout << "YES" << endl; else if(ta ==...
0
#include <bits/stdc++.h> const int N = 2005; int n, a[N][N], md = 2e9; long long d[N]; bool used[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) scanf("%d", &a[i][j]), a[j][i] = a[i][j], md = std::min(md, a[i][j]); for (int i = 1; i <= n; ++i) { d[i] =...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int q, n, x; int main() { ios_base::sync_with_stdio(false); cin >> q; for (int i = 0; i < q; ++i) { cin >> n >> x; int best = -1; int best_d = 0; for (int i = 0; i < n; ++i) { int d = 0; int h = 0; cin >> d >> ...
2
#include <bits/stdc++.h> using namespace std; int main() { string s; char ch[30], x, y; int n, m; cin >> n >> m; cin >> s; for (int i = 0; i < 26; i++) ch[i] = i + 'a'; for (int i = 0; i < m; i++) { cin >> x >> y; for (int l = 0; l < 26; l++) { if (ch[l] == x) { ch[l] = y; } el...
2
#include <iostream> using namespace std; int main(void) { int n; cin >> n; cout << 111 * ((n + (110)) / 111) << endl; }
0
#include <bits/stdc++.h> using namespace std; int arr[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; cin >> TESTS; long long int sum = 0, n = 1; stack<int> s; s.push(0); while (TESTS--) { int t; cin >> t; if (t == 1) { int a, x; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int len, op, i, j; char ch1, ch2; cin >> len >> op; string line; cin >> line; while (op--) { cin >> i >> j >> ch1 >> ch2; for (; i <= j; i++) { if (line[i - 1] == ch1) line[i - 1] = ch2; } ...
1
#include <bits/stdc++.h> using namespace std; int main() { int K; cin >> K; cout << ((K + 1) / 2) * (K / 2) << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; string S; cin >> n; while (n > 0) { if (n % 7 == 0) { S += '7'; n -= 7; } else { S += '4'; n -= 4; } } if (n == 0) cout << S << endl; else cout << "-1" << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #pragma GCC push_options #pragma GCC optimize("unroll-loops") const int N = int(1e6 + 20); int fen[N]; void update(int i, int add) { while (i > 0 && i < N) { fen[i] += add; i += (i & (-i)); } } int sum(int i) { int s = 0; while (i > 0) { s += fen[i]; ...
4
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { while (true) { if (a == 0) return b; b %= a; if (b == 0) return a; a %= b; } } int main() { int n, m; cin >> n >> m; int a, gcd = 0; for (; n > 0; --n) { cin >> a; gcd = GCD(gcd, a - 1); } while (gcd % 2 == 0) ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<int> g[N]; int was[N]; bool Q[N]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0, u, v; i < m; i++) { scanf("%d %d", &u, &v); g[u].push_back(v); } for (int u = 1; u <= n; u++) { if (!was[u]) { was[u] =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int h[n]; int hprev = 0; long long tot = 0; for (int i = 0; i < n; i++) { cin >> h[i]; tot += fabs(hprev - h[i]) + 2; hprev = h[i]; } tot--; cout << tot << endl; }
2
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b ? gcd(b, a ...
1
#include <bits/stdc++.h> using namespace std; vector<int> pos[110]; int n; int main() { int m; cin >> n >> m; int i, j; char c; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> c; if (c == '1') pos[i].push_back(j); } if (pos[i].empty()) { cout << -1 << endl; retur...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int maxn = (int)1e5 + 10; char s[maxn]; int main() { gets(s); int n = strlen(s); int i = 0; while (i < n) { if (s[i] == ' ') { i++; continue; ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(0); int n; cin >> n; if (n < 4) { cout << "NO\n"; } else if (n == 4) { cout << "YES\n"; cout << 1 << " * " << 2 << " = " << 2 << "\n"; cout << 2 << " * " << 3 << " = " << 6 << "\n"; cout << 4 << " * " << 6 << ...
1
#include <bits/stdc++.h> using namespace std; using vint = vector<int>; using vvint = vector<vint>; using vvvint = vector<vvint>; const int nl = 20; const int nm = 10; vint depth; vvint adj_list; vvint node_min; vvvint log_min; vvint log_parent; vint vmerge(const vint& left, const vint& right) { vint ans(left); ans...
5
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; const int M = 1e6; const long long INF = (long long)(1e18); const int inf = 1e9; const long long MOD = 1000000007LL; void solve() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a1, a2, k1, k2, n; cin >> a1 >> a2 >> k1 >> k2 ...
1
#include <bits/stdc++.h> using namespace std; inline namespace Infinity { inline namespace IO { const char CR = '\n'; const char SP = ' '; inline void write(const int n) { printf("%d", n); } inline void write(const unsigned n) { printf("%u", n); } inline void write(const long long n) { cout << n; } inline void write(co...
3
#include <bits/stdc++.h> using namespace std; using Int = int_fast64_t; constexpr double PI = 3.1415926535897932384626433832795; double ans; Int n; using P = pair<double, double>; vector<P> v; double dot(P a, P b){ return a.first * b.first + a.second * b.second; } double norm(P a){ return sqrt(a.first * a.first + ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, s; cin >> n >> s; long long cs = 0; vector<int> v; for (int i = 0; i < n - 1; ++i) v.push_back(1); v.push_back(s - (n - 1)); if (s < 2 * n) cout << "NO" << "\n"; ...
4
/* Nintai-ryoku ga ari, jikan ga kakaru purosesu o shinrai suru ~ 死神 */ #include <bits/stdc++.h> /* #include<boost/multiprecision/cpp_int.hpp> namespace mp=boost::multiprecision; */ using namespace std; /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!shortcuts!!!!!!!!!!!!!!!!!...
3
#include <bits/stdc++.h> using namespace std; const long long int N = 105; vector<pair<long long int, long long int>> adj[N]; vector<bool> vis(N); bool dfs(long long int u, long long int v, long long int col) { vis[u] = true; if (u == v) { return true; } for (auto i : adj[u]) { long long int vert = i.fi...
2
#include <iostream> #include <algorithm> using namespace std; int Q; int N; int solve(int n) { if (0 <= n && n <= 9) return 0; int max_n = 0; for (int i = 10; i <= n; i *= 10) { int a = n / i; int b = n % i; max_n = max(max_n, a*b); } return solve(max_n) + 1; } int main()...
0
#include <bits/stdc++.h> using namespace std; int a[1005]; int main() { memset(a, 1, sizeof(a)); int m, n, k; cin >> n >> m >> k; int nn, t; for (int i = 0; i < n; i++) { cin >> nn >> t; a[nn] = min(a[nn], t); } int res = 0; for (int i = 1; i <= m; i++) res += a[i]; cout << min(res, k) << endl...
1
#include <bits/stdc++.h> using namespace std; int main() { string s,t; cin>>s>>t; if(s == t.substr(0, s.size())) cout<<"Yes\n"; else cout<<"No\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { vector<int> v; for (int i = (1); (i) <= (n); ++(i)) { int tmp; cin >> tmp; v.push_back(tmp); } bool *flag = new bool[n + 1]; int q, p, x, y; cin >> q; while (q > 0) { cin >> p >> ...
2
#include <bits/stdc++.h> using namespace std; int main(void) { long int n, m; long long int k; cin >> n >> m >> k; cout << (k - 1) / (2 * m) + 1 << ' '; cout << ((k - 1) % (2 * m)) / 2 + 1 << ' '; if ((k - 1) % 2 == 0) cout << 'L'; else cout << 'R'; cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 55; int main() { int n, m; cin >> n >> m; string s[maxn]; int sx = -1, sy = -1; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < m; j++) { if (s[i][j] == 'S') { sx = i, sy = j; } } } string w; ci...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char s[N]; int a[N], sta[N], tp; int main() { scanf("%s", s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; ++i) if (s[i] == '0') { if (tp) a[sta[tp--]] = 1; } else sta[++tp] = i; for (int i = 1; i <= n; ++i) printf("...
4
#include <bits/stdc++.h> using namespace std; int r[9]; int n; int a[9]; int b[3][3]; int x[3], y[3], z, k; set<int> s; int main() { cin >> n; for (int i = 0; i < n * n; i++) { cin >> a[i]; r[i] = i; } do { for (int i = 0; i < 9; i++) b[i / n][i % n] = a[r[i]]; memset(x, 0, sizeof(x)); memse...
4
#include <bits/stdc++.h> using namespace std; int n, m, k, x, t1; int v[200005], tot[4], a[200005], pos[4]; long long b[4][200005], s[4][200005], ans; int getcnt(int t, int x, int y) { for (int i = 0; i < 4; i++) { pos[i] = upper_bound(b[i], b[i] + tot[i], t) - b[i]; if (i == 3) pos[i] = max(pos[i], x);...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = (long long)1e18 + 5; const int MAXN = 100005; struct BIT { int c[MAXN]; void add(int p, int v) { while (p < MAXN) { c[p] += v; p += p & -p; } } int get(int p) { int res = 0; while (p...
3
#include <bits/stdc++.h> using namespace std; const long long inf = 1000 * 1000 * 1000; const long long mod = 1000 * 1000 * 1000 + 7; int main() { ios_base::sync_with_stdio(false); bool arr[17]; arr[1] = true; arr[2] = false; arr[3] = false; arr[4] = true; arr[5] = false; arr[6] = true; arr[7] = false...
4
#include <bits/stdc++.h> using namespace std; const int INFTY = 1 << 29; const pair<int, int> EMPTY = make_pair(-1, -1); ostream& operator<<(ostream& os, const pair<int, int>& p) { return os << '(' << p.first << ',' << p.second << ')'; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& a) { o...
1
#include <iostream> #include <fstream> #include <queue> #include <map> #include <set> #include <algorithm> using namespace std; typedef long long ll; typedef __int128 lll; constexpr ll mod = 1000000007; int n, k[2], a[200000][2], p, q; queue<int> v; int root(int node, int tr) { int c = node; while (a[c][tr...
0
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main(){ while(1){ int n, s[100]={0}; scanf(" %d", &n); if(n==0) break; for(int i=0; i<n; ++i){ for(int j=0; j<5; ++j){ int a; scanf(" %d", &a); s[i]+=a; } } sort(s, s+n); printf("%d %d\n", s[n-1],...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << "-1\n"; return 0; } for (int i = (0); i < (n); ++i) cout << i << " "; cout << "\n"; for (int i = (0); i < (n); ++i) cout << (n - i - 1 - i + 3 * n) % n << " "; cout << "\n"; for (int i = (0); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 201000; int n, m, k, x, y, dx, dy, bx[N], by[N]; char dir[10]; set<int> bk[N], pnt[N]; vector<pair<int, int> > tv1[N], tv2[N]; long long ret; void ff() { int px = x, py = y; if (dx == -1) px += 1; if (dy == -1) py += 1; if (!bk[px + dx].count(py + dy))...
5
#include <bits/stdc++.h> using namespace std; int n, a[100001], b[100001]; long long int k, SS; int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; SS = SS + a[i]; } if (SS < k) { cout << ...
2
#include <bits/stdc++.h> using namespace std; long long n; long long beuty(string s) { long long l = s.size(), b = 0; int ch[130]; memset(ch, 0, sizeof(ch)); for (int i = 0; i < l; i++) { int c = s[i] - 'A'; ch[c]++; b = max(b, (long long)ch[c]); } if (b < s.size()) b = min((long long)s.size...
2
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> n >> k; int even = 0; int odd = 0; for (int i = 0; i < n; ++i) { int a; cin >> a; if (a % 2 == 0) ++even; else ++odd; } int left = n - k; int dan = left / 2; int stan = left / 2 + left % 2; if (le...
3
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); { long long n; cin >> n; vector<long long> v(n); for (auto &ele : v) cin >> ele; long long answer = 1e18L; long long total = accumu...
2
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long bp(long long x, long long y) { long long ans = 1; x %= mod; while (y) { if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1; } return ans; } long long mod_inverse(long long x) { return bp(x, mod - 2); } long l...
3
#include <bits/stdc++.h> #define N 100100 using namespace std; int n, ind[N], ld[N], cnt, num[N]; vector<int> G[N]; void dfs(int u, int p, int now, int &dep, int &pnt) { if (now > dep) dep = now, pnt = u; for (int v : G[u]) if (v != p) dfs(v, u, now + 1, dep, pnt); } inline void getans(int *p) { ...
0
#include <iostream> #include <algorithm> #include <queue> using namespace std; unsigned char memo[1<<20]; int mask[5][5][6][6]; void printS(int s){ int tmp[5][5]; fill(tmp[0], tmp[5], 0); for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ tmp[i][j] = s >> (i*5+j) & 1; } } for(int i=0;i<5;i++){ f...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m; cin >> m; int discounts[100005]; for (int i = 0; i < m; i++) cin >> discounts[i]; sort(discounts, discounts + m); int n; cin >> n; int arr[100005]; for (int i = 0; i < n; i++)...
3
#include <iostream> #include <string> using namespace std; string t[26] = { "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "1001...
0
#include <bits/stdc++.h> using namespace std; const int TAM = 3e5 + 3; int k, n, s; void prt() { cout << n << endl << -1 << " "; s++; for (int i = 0; i < n - 1; i++) { if (i) cout << s / (n - 1) << " "; else cout << (s / (n - 1)) + s % (n - 1) << " "; } cout << endl; } int main() { ios_b...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; int Mat[1003][1003]; int main() { int n; while (scanf("%d", &n) != EOF) { int sum = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { cin >> Mat[i][j]; if (i == j) sum = s...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 505; char mp[maxn][maxn]; int cc[maxn][maxn]; int siz[maxn * maxn]; int vis[maxn * maxn]; int inside[maxn * maxn]; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int n, k; bool legal(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= n; } void...
3
#include <bits/stdc++.h> using namespace std; const long long N = 100 * 1000 + 5, LG = 19, mod = 1000 * 1000 * 1000 + 7; long long n, q; long long sz[N], h[N]; long long sumd[N], sumu[N], dpd[N], dpu[N]; pair<long long, long long> par[N][LG]; vector<pair<long long, long long> > adj[N]; void dfs1(long long v) { sz[v] ...
4
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; string S; map<string,int> card; for(int i=0; i<N; i++){ cin >> S; card[S]++; } int M; cin >> M; for(int i=0; i<M; i++){ cin >> S; card[S]--; } int max_card = 0; for(auto x:card){ if(max_card < x....
0
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n, k, a, b, count = 0, max = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a >> b; if (b < k) { count = a; if (count > max) max = count; } else { count = a - (b - k); if (count > max || max == 0) m...
1
#ifdef debug #include <chrono> #endif #include <iostream> #include <algorithm> // next_permutation #include <iomanip> #include <cmath> #include <vector> #include <sstream> #include <string> #include <cstring> //memcpy #include <cstdio> #include <stack> #include <queue> #include <list> #include <numeric> //accumulate /...
0
#include <bits/stdc++.h> using namespace std; char mirro[] = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}; bool ismirror(char code[], int len) { int i; for (i = 0; i < len; i++) { bool tt = false; for (int j = 0; j < 11; j++) { if (code[i] == mirro[j]) { tt = true; break; ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int d,s,t; cin>>d>>t>>s; if(d*1.0/s>t) cout<<"No"; else cout<<"Yes"; }
0
#include <iostream> #include <algorithm> using namespace std; int arr[100005]; int main() { int n,ans; scanf("%d",&n); for (int i=0;i<n;i++) scanf("%d",&arr[i]); sort(arr,arr+n); long long sum=0; for (int i=0;i<n;i++) { if (arr[i]>2*sum) ans=1; else ans++; sum+=arr[i]; } printf("%d",ans); }
0
#include <bits/stdc++.h> using namespace std; template <class T> inline istream& operator>>(istream& str, vector<T>& a) { for (auto& i : a) str >> i; return str; } long long M = 1e9 + 7; void solve() { long long int k; cin >> k; vector<char> v = {'c', 'o', 'd', 'e', 'f', 'o', 'r', 'c', 'e', 's'}; vector<lon...
2
#include <bits/stdc++.h> using namespace std; int vis[109]; int len[109]; int main() { int n; cin >> n; string w; for (int i = 0; i < n; ++i) { cin >> w; for (int j = 0; j < w.length(); ++j) vis[i] |= 1 << (w[j] - 'a'); len[i] = w.length(); } int mx = 0, sel; for (int i = 0; i < 26; ++i) f...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b)...
4
#include <bits/stdc++.h> using namespace std; long long n, h[300005], ans; long long stk1, stk2; signed main() { scanf("%lld", &n); for (long long i = 1; i <= n; i++) { scanf("%d", &h[i]); ans += h[i] / 2; if (h[i] % 2) { if (i % 2) { stk1++; } else { stk2++; } } ...
2
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 88; const int maxn = 2e5 + 88; long long a[maxn], cur[10], cura[10]; long long curbase[10][10], base[10][10]; long long k; int n; int readint() { int cur; scanf("%d", &cur); return cur; } long long readll() { long long cur; scanf("%I64...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int cNum, sum = 0; int middle = (n - 1) / 2, lDiag = 0, rDiag = n - 1; for (int i = 0; i < n; ++i, rDiag--, lDiag++) { for (int j = 0; j < n; ++j) { scanf("%d", &cNum); if (i == middle) { sum += cNum; ...
1
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int n; vector<long long int> v; long long int l, r; void solve() { vector<long long int> bits(31, 0); long long int n; cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; i++) { cin >> v[i]; long lo...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; const int INF = 1e9; vector<int> g[maxn * 2][2]; int cost[maxn][maxn][2], L[maxn * 2][2], R[maxn * 2][2], DP[maxn], sz[maxn * 2][2]; int N, A, B; void DFS(int v, int f) { sz[v][f] = v != 1; for (int u : g[v][f]) { DFS(u, f); sz[v][f] +...
6
#include <iostream> int main() { char A; std::cin >> A; A++; std::cout << A; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 101; const int MAXNODES = 5; int N; bool visit[MAXNODES]; int from[MAXN], to[MAXN], value[MAXN], degree[MAXNODES]; vector<int> G[MAXNODES][MAXNODES]; void input() { cin >> N; for (int i = 1; i <= N; i++) { cin >> from[i] >> value[i] >> to[i]; } } ...
5
#include <bits/stdc++.h> using namespace std; long long n; bool check(long long x) { long long temp = n, sum = 0; while (temp) { if (temp > x) temp -= x, sum += x; else sum += temp, temp = 0; temp -= temp / 10; } if (sum >= (n + 1) / 2) return true; return false; } long long erfen(long...
3
#include <bits/stdc++.h> using namespace std; long long mod(long long a) { return a > 0 ? a : -a; } const int N = 333333; long long dp[N], best[N], t[N]; int main() { int n, m, dd; cin >> n >> m >> dd; for (int i = 1; i <= m; i++) { long long a, b; cin >> a >> b >> t[i]; long long d = (t[i] - t[i - 1]...
3
#include<bits/stdc++.h> using namespace std; int main(){ int X,A,B; cin>>X>>A>>B; if(B<=A)cout<<"delicious"<<endl; else if(B>A+X)cout<<"dangerous"<<endl; else cout<<"safe"<<endl; }
0
#include <bits/stdc++.h> using namespace std; int n; string a, b, tmp; int main() { ios_base::sync_with_stdio(0); cin >> a >> b; n = (int)a.length(); for (int i = 0; i < n; i++) { if (a[i] < 'z') { tmp = a; tmp[i]++; for (int h = i + 1; h < n; h++) tmp[h] = 'a'; if (tmp < b) { ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T& x, T y) { if (x < y) x = y; } template <typename T> void chkmin(T& x, T y) { if (x > y) x = y; } inline int read() { int x = 0; char c = getchar(); bool f = 0; while (c < 48) f |= c == '-', c = getchar(); while (c > 47) x =...
4
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const dou...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string foo; getline(cin, foo); for (int i = 0; i < n; i++) { string s; getline(cin, s); string st = s.substr(0, min(5, (int)s.length())), b = s.substr(max((int)s.length() - 5, 0), 5); cerr << st << " " << b ...
1