solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5; int t, n, k; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); while (cin >> t) { while (t--) { cin >> n >> k; cin >> s; int wins = 0, losses = 0, wins_streaks = 0; ...
6
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6; void solve() { string s; cin >> s; long long n = s.size(); if (n % 2) { cout << "NO" << '\n'; return; } bool ans = 1; for (long long i = 0; i < n / 2; i++) { if (s[i] != s[i + (n / 2)]) { ans = 0; break; ...
0
#include <bits/stdc++.h> const int N = (1 << 20) + 5; int n, m, a[111], d[21], p[N], f[N]; char c[21]; int main() { int i, j, x, y; scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%d", a + i); std::sort(a + 1, a + n + 1, std::greater<int>()); scanf("%d", &n); for (i = 1; i <= n; ++i) scanf(" %c %d", c + i,...
14
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; template <typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; } int main() { ...
5
#include <bits/stdc++.h> using namespace std; int n1, n2, m, DEG[4040]; vector<int> res[4040]; struct edge { int u, v, cap, flow; }; struct Graph { int n; vector<vector<int> > g; vector<edge> e; vector<int> d, ptr; Graph() {} Graph(int n) : n(n), g(n + 1), d(n + 1), ptr(n + 1) {} void addEdge(int u, int...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n > m) swap(n, m); if (n == 1 || m == 1) cout << m * n << endl; else if (n == 2 && m >= 2) cout << (m / 4) * 4 + min(m % 4, 2) * 2 << endl; else cout << (m * n + 1) / 2 << endl; return 0; }
10
#include <bits/stdc++.h> using namespace std; int dp[1000005][3][3]; int a[1000005]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { int a_i; scanf("%d", &a_i); a[a_i]++; } for (int i = 1; i <= m; i++) { for (int j = 0; j <= 2; j++) { for (int k = 0; k <= 2; k++) { ...
14
#include <bits/stdc++.h> using namespace std; void solve() { long long arr[7]; for (int i = 0; i < 7; i++) cin >> arr[i]; cout << arr[0] << " " << arr[1] << " " << (arr[6] - (arr[0] + arr[1])) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int minx, maxx, miny, maxy; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x < minx || i == 0) minx = x; if (x > maxx || i == 0) maxx = x; if (y < miny...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000009; vector<int> g[N]; vector<pair<int, int> > v2; long long stopien[N]; bool v[N]; void dfs(int a) { v[a] = true; for (int i = 0; i < g[a].size(); i++) { int b = g[a][i]; if (!v[b]) dfs(b); } } bool bylakurwa[N]; int main() { int n, m; s...
13
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int exgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int r = exgcd(b, a % b, x, y); int t = y; y = x - a / b * y; x = t; return r; } inline int lcm(int a, int...
2
#include <bits/stdc++.h> using namespace std; struct candy { int height; int mass; bool operator<(const candy &rhs) const { if (height == rhs.height) return mass < rhs.mass; return height < rhs.height; } }; int solve(vector<candy> first, vector<candy> second, int x) { int c_first = first.size(); int...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100007; long long a[maxn]; int main() { int n; cin >> n; long long sum = 0; long long s = 0; for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; s = sum; sort(a + 1, a + 1 + n); for (int i = 1; i <= n / 2; i++) sum -= a[i]; cout << sum ...
1
#include <bits/stdc++.h> using namespace std; long long n, a, b, ans[1000111]; int main() { scanf("%lld%lld%lld", &n, &a, &b); if (a < b) swap(a, b); for (long long i = 0; a * i <= n; i++) { if ((n - a * i) % b != 0) continue; long long ac = i, bc = (n - a * i) / b; for (long long i = 0; i < ac; i++) ...
8
#include <bits/stdc++.h> using namespace std; int n; vector<int> a(1001, -1); int difficulty(vector<int> &a, int &n, int &no) { int diff, maxi = 0; for (int i = 1; i <= n - 1; i++) { diff = a[i + 1] - a[i - (i == no)]; if (diff > maxi) maxi = diff; } return maxi; } int mindiff(vector<int> &a, int &n) { ...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return s; } const int N = 1e5 + 5, M = 5e6 + 5; int n, m; vector<int> G[N]; int dfn[N], top[N], siz[N], fa[N], dep[N...
24
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 20; int n, m, x, s1[maxn], s2[maxn], ans; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> x; s1[i] = s1[i - 1] + x; } for (int i = 1; i <= m; i++) { cin >> x; s2[i] = s2[i - 1] + x; } int i = 1, j = 1; w...
3
#include <bits/stdc++.h> using namespace std; int gi() { char cc = getchar(); int cn = 0, flus = 1; while (cc < '0' || cc > '9') { if (cc == '-') flus = -flus; cc = getchar(); } while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar(); return cn * flus; } const int inf = 1e8; const int...
23
#include <bits/stdc++.h> using namespace std; int m, n, k; long long result; int a[500002], b[500002]; vector<pair<int, int> > temp; int pre[500002], suf[500002]; int suf1[500002]; void setup() { scanf("%d", &n); scanf("%d", &k); scanf("%d", &m); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); } void shortenAr...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; float count = 1, p1[n][2], p2[n][2]; for (int i = 0; i < n; i++) { cin >> p1[i][0] >> p1[i][1] >> p2[i][0] >> p2[i][1]; } for (int i = 1; i < n; i++) { float midx = abs(p1[i][0] - p2[i][0]) / 2 + min(p1[i][0], p2[i][0]); ...
11
#include <bits/stdc++.h> using namespace std; long long mod(long long n) { if (n < 0) return -n; return n; } void blowback() { long long i, j, l, k, n, m, x, ans = 0, sum = 0; cin >> n >> m; long long a[n], d[n], s[n + 1], c[n], b[n]; s[0] = 0; for (i = 0; i < n; i++) { cin >> a[i]; s[i + 1] = s[i...
14
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, d; cin >> t; int a[t]; for (int l = 0; l < t; ++l) { cin >> n >> k >> d; int m[n]; int mn; map<int, int> mp; for (int j = 0; j < n; ++j) { cin >> m[j]; } for (int i = 0; i < d; ++i) { mp[m[i]]++; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; vector<int> Vec(n); for (int k = 0; k < n; k++) scanf("%d", &Vec[k]); sort(Vec.begin(), Vec.end()); printf("%d\n", Vec[b] - Vec[b - 1]); return 0; }
0
#include <bits/stdc++.h> using namespace std; int t, n; int a[100100]; int b[100100]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } int blocks = 0; for (int i = 0; i < n; i++) { i...
2
#include <bits/stdc++.h> using namespace std; void solve(int test_number); void pre() { cout.setf(ios::fixed); cout.precision(20); cerr.setf(ios::fixed); cerr.precision(3); } void post() { fprintf(stderr, "\n"); fprintf(stderr, "Execution time: %Lf", (long double)clock()); } const int MAXN = 100100; int a[2...
5
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; x = x % 1000000007; if (x == 0) return 0; while (y > 0) { if (y & 1) res = ((res % 1000000007) * (x % 1000000007)) % 1000000007; y = y >> 1; x = ((x % 1000000007) * (x % 1000000007)) % 100000...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; const double eps = 1e-4; const long long M1 = 998244353; const long long M2 = 1000000007; const long long M = 1333331; struct Hash_data { int vX, vY, id; } Hash[M]; struct data { double X, Y; } point[maxn]; data mid; double len[maxn]; bool vis[max...
21
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int mod1 = 1e9 + 7, mod2 = 1e9 + 9; const int base1 = 233, base2 = 47; pair<int, int> h[30][N]; int n, m, pw1[N], pw2[N]; char s[N]; inline pair<int, int> GetHashVal(int id, int l, int r) { pair<int, int> ans = h[id][r]; ans.first = ((a...
15
#include <bits/stdc++.h> using namespace std; struct line { int k, b; }; int n; bool cmp(const line &a, const line &b) { return 1ll * a.b * b.k < 1ll * a.k * b.b; } bool equal(line a, line b) { return 1ll * a.b * b.k == 1ll * a.k * b.b; } int main() { cin >> n; vector<line> v; for (int i = 0; i < n; i++) { ...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; int dp[N]; bool vis[N]; int f[N]; vector<int> getarray(int c, int s) { vector<int> v; int a = s / 2; a = s - a; for (int i = 0; i < c; ++i) { v.push_back(a + i - c / 2); } return v; } int get(int n) { if (vis[n]) return dp[n]...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1000; int main() { int n, m, k; scanf("%d", &k); if (!(k & 1)) { printf("NO\n"); return 0; } n = 4 * k - 2; m = k * n / 2; printf("YES\n"); printf("%d %d\n", n, m); printf("%d %d\n", 1, n); for (int i = 1; i < k; i++) { print...
11
#include <bits/stdc++.h> using namespace std; long int cnt; void me(long int d, long int k, long int m) { if (d < (m * k) + 1) { return; } else if (d == (m * k) + 1) { cnt++; } else { cnt++; cnt += (d - (m * k) - 1) / (k + 1); } return; } int main() { long int j, i, d, k, t, n, m; string s...
5
#include <bits/stdc++.h> using namespace std; int n, s1[3005][3005], s2[3005][3005], s3[3005][3005], s4[3005][3005], s5[3005][3005]; vector<int> l[3005], r[3005]; inline int areasum(int x1, int y1010101010101, int x2, int y2) { if (x2 > 3000 || y2 > 3000) return -1; return s1[x2][y2] - s1[x1 - 1][y2] - s1[x2][y...
16
#include <bits/stdc++.h> using namespace std; int g[2][1000 + 20][1000 + 20]; int ans[1000 + 20][1000 + 20]; vector<pair<int, int> > edge; int cans = 0; int n; void dfs(int sd, int u, int v, int coloru, int colorv) { int t = g[sd ^ 1][v][coloru]; g[sd][u][coloru] = v; g[sd ^ 1][v][coloru] = u; if (sd == 0) ...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; long long arr[n], sum = 0, x = 0, ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } sort(arr, arr + n); for (int i = 0; i < n ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int T, n, m; int a[maxn], ans[maxn]; bool solve(int p, bool b) { if (p > n) return true; if (!a[p]) return solve(p + 1, true); int q = p + 1; while (q <= n && !a[q]) q++; if (q > n) return false; int t = p; while (t + 2 < q) ans[++m] =...
17
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); long long n; cin >> n; vector<long long> p(n); vector<long long> passing(n); long long before = 0; long long after = 0; long long sum = 0; for (int i = 0; i < int(n); ++i) { cin >> p[i]; --p[i]; ++passin...
11
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } ret...
4
#include <bits/stdc++.h> using namespace std; struct node { int step, height; }; int h[10005], sum[10005]; node dp[10005]; int main() { int n; scanf("%d", &n); sum[0] = 0; for (int i = 1; i <= n; i++) { int x; scanf("%d", &h[i]); sum[i] = sum[i - 1] + h[i]; } dp[0].step = 0; dp[0].height = 0...
13
#include <bits/stdc++.h> using namespace std; const int N = 101; int n, k, len[N]; char g[N][N], s[N], ch, res[N]; bool can[N]; bool check(int b, int i) { if (b + len[i] > n) return false; bool can = true; for (int j = 0; j < len[i] && can; ++j) can &= tolower(s[b++]) == tolower(g[i][j]); return can; } int ...
8
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; map<int, int> mp1; map<int, int> mp2; long long ans = 0; int i; for (i = 0; i < n; i++) { int x, y; cin >> x >> y; ans += mp1[x + y]++; ans += mp2[x - y]++; } cout << ans << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; const string months[12]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int main() { string s; int k; getline(cin, s); cin ...
1
#include <bits/stdc++.h> using namespace std; const int mod = (1e9) + 7; const int siz = (1e5) + 100; int n, m; struct en { int mh, sh, rg; }; set<pair<int, int>> mm[siz]; multiset<pair<int, int>> inter; int bo, in, da; en ens[siz]; int main() { scanf("%d%d", &n, &m); scanf("%d%d%d", &bo, &in, &da); for (int i ...
17
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } template <class T> ve...
2
#include <bits/stdc++.h> using namespace std; int main() { int R, d, n; int xi, yi, ri, count = 0; double pyth; cin >> R >> d; int aux = R - d; cin >> n; for (int i = 0; i < n; i++) { cin >> xi >> yi >> ri; pyth = (xi * xi) + (yi * yi); pyth = sqrt(pyth); if ((pyth >= (aux + ri)) && ((pyth...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n][n], p = 0, g = n - 1, sum = 0; 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++) { if (i != g) { sum += a[i][p]; sum += a[i][g]; sum += a[i][n / 2]; ...
0
#include <bits/stdc++.h> using namespace std; vector<int> d, sz, ans; vector<vector<int>> g, pa; void dfs(int i) { d[i] = d[pa[i][1]] + 1; for (int j : g[i]) if (j != pa[i][1]) pa[j][1] = i, dfs(j); } int lca(int i, int j) { if (d[i] < d[j]) swap(i, j); for (int k = 19; k; --k) if (d[pa[i][k]] >= d[j]) ...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n, k, b, c; int arr[MAXN]; int cp[MAXN]; int main() { ios_base::sync_with_stdio(0); cin >> n >> k >> b >> c; if (b > 5 * c) b = 5 * c; for (int g = 1; g <= n; g++) { cin >> arr[g]; cp[g] = arr[g]; } sort(arr + 1, arr + n + 1)...
16
#include <bits/stdc++.h> using namespace std; const int N = 3010; const int MX_LEN = 110; const long long inf = 1e15; const int mod = 1e9 + 7; long long dp[N][MX_LEN]; long long solve(int rem, int len) { if (len == 0) { if (rem == 0) return 1; return 0; } if (rem < 0 || 25 * len < rem) return 0; if (dp[...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 5; int N, M, A[MAXN][MAXN], res, c[MAXN]; char str[MAXN]; int main() { scanf("%d %d", &N, &M); for (int i = 1; i <= N; ++i) { scanf("%s", str + 1); for (int j = 1; j <= M; ++j) A[i][j] = (str[j] - '0') == 1 ? (A[i][j - 1] + 1) : 0; ...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; struct edge { int u, v, val; bool operator<(const edge &x) const { return val < x.val; } } e[1005 * 1005]; char mp[1005][11][11]; vector<int> g[1005]; vector<int> cost[1005]; int rt[1005]; int find(int x) { if (rt[x] == x) return x; retur...
10
#include <bits/stdc++.h> using namespace std; const long long maxn = 256; const long long inf = 2e9; struct node { long long num, p; string s; inline bool operator>(const node& n1) const { if (s.length() != n1.s.length()) return s.length() > n1.s.length(); return s > n1.s; } node(long long num, long l...
16
#include <bits/stdc++.h> using namespace std; const long double PI = 2 * acos(0.0); void yes() { cout << "YES\n"; } void no() { cout << "NO\n"; cout << -1 << "\n"; exit(0); } long long m(long long a) { return (a + 1000000007) % 1000000007; } long long cel(long long x1, long long y1) { ; if ((x1 % y1) == 0) re...
9
#include <bits/stdc++.h> using namespace std; long long n, m, k, ans = 0; int main() { scanf("%I64d%I64d%I64d", &n, &m, &k); ans = 0; if (n + m - 2 < k) { printf("-1\n"); return 0; } if (k <= n - 1) ans = max(ans, n / (k + 1) * m); if (k <= m - 1) ans = max(ans, m / (k + 1) * n); if (k > n - 1) an...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; k--; char c[n][m]; vector<pair<int, pair<int, int> > > v; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> c[i][j]; } } for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m ...
8
#include <bits/stdc++.h> using namespace std; 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') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 1005; con...
14
#include <bits/stdc++.h> using namespace std; void solve() { return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; while (q--) { string s; cin >> s; long long n = s.length(); long long u = 0, d = 0, r = 0, l = 0; for (int i = 0; i < n; i++) { if (s[...
4
#include <bits/stdc++.h> using namespace std; int n; char s[204]; vector<int> g; set<int> ss; int main() { scanf("%d", &n); scanf("%s", s + 1); g.push_back(0); for (int i = 1; i <= n; i++) if ('A' <= s[i] && s[i] <= 'Z') g.push_back(i); g.push_back(n + 1); int ans = 0; for (int i = 0; i < g.size() - 1...
2
#include <bits/stdc++.h> using namespace std; ifstream fin("test.in"); ofstream fout("test.out"); int a[100010], b[100010]; int n, m; bool check(long long first) { for (int i = 1; i <= n; ++i) b[i] = a[i]; if (first <= n) return 0; int i = 1; int j = 1; while (j <= m) { long long op = i - 1; while (i ...
14
#include <bits/stdc++.h> using namespace std; const int inf = 0x20202020; const int mod = 1000000007; template <class T> inline void read(T& first) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') fu = 1, c = getchar(); for (first = 0; c > 32; c = getchar()) first = first...
18
#include <bits/stdc++.h> using namespace std; string s, t; int n, m, i, fl; int main() { cin >> n >> m >> s >> t; if (s.find('*') != string::npos && n > m + 1) { printf("NO\n"); return 0; } else if (s.find('*') == string::npos && n != m) { printf("NO\n"); return 0; } for (i = 1; i <= s.size() ...
4
#include <bits/stdc++.h> using namespace std; int main() { int l; cin >> l; string s; cin >> s; int count = 1; for (int j = 0; j < l; j++) { for (int i = 0; i < l; i++) { if ((count * 4) - 1 > l) break; if (s[i] == '*' && s[i] == s[i + count] && s[i + count] == s[i + count * 2] && ...
5
#include <bits/stdc++.h> struct Point { int x, y; } point[3010]; int n, p[3010], vis[3010]; char S[3010]; int cross(int i, int j, int k) { int x1 = point[i].x - point[j].x; int x2 = point[k].x - point[j].x; int y_1 = point[i].y - point[j].y; int y2 = point[k].y - point[j].y; return 1ll * x1 * y2 > 1ll * x2 ...
18
#include <bits/stdc++.h> #define ll long long #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() using namespace std; const int tINF = (int)INT_MAX; const long long lINF = (long long)LLONG_MAX; int getd(pair <int,int> l, pair <int,int> r) { return abs(l.first - r.first) + abs(l.second - r....
2
#include <bits/stdc++.h> using namespace std; void PT(long long a); void PT1(long long a); const long long M = 3 * (1e5) + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; { long long n, sum; cin >> n >> sum; long long sum1 = sum; long long m = sum; vec...
6
#include <bits/stdc++.h> using namespace std; template <class T> void printQueue(T& q) { while (!q.empty()) { cout << q.top() << endl; q.pop(); } } int main() { long long dp[2609][109]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 2600; j++) { ...
12
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; int main() { long long a, t, n, m, i, j, k, d, f = 0, p = 0, cnt; cin >> t >> m; while (m--) { cin >> n; mp.clear(); f = 0; for (i = 0; i < n; i++) { cin >> a; if (mp[-a] == 1) { f = 1; } else ...
5
#include <bits/stdc++.h> using std::bitset; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::string; using std::stringstream; using std::vector; class MyTimer { public: void reset() {} vo...
9
#include <bits/stdc++.h> using namespace std; long long C, hr, hb, wr, wb; long long f(long long x) { return hr * x + (C - wr * x) / wb * hb; } int main() { while (cin >> C >> hr >> hb >> wr >> wb) { long long res = 0; for (int turn = 0, _a = (2); turn < _a; turn++) { long long left = 0, right = C / wr;...
12
#include <bits/stdc++.h> const int N = 2e5 + 10; const int mod = 998244353; const double PI = acos(-1.0); const double eps = 1e-8; using namespace std; inline int read() { int num = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { num = (num << ...
18
#include <bits/stdc++.h> using namespace std; int n, xa, xb, ya, yb, da, db; int min(int a, int b) { if (a < b) return a; else return b; } int main() { scanf("%d%d%d%d%d", &n, &xa, &ya, &xb, &yb); if (ya == n) da = (3 * n) + n - xa; if (xa == n) da = (2 * n) + ya; if (ya == 0) da = n + xa; if (xa ...
5
#include <bits/stdc++.h> using namespace std; int n, a[101]; bool f[101], g[101] = {1}; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) if (a[i] & 1) { for (int j = i; j > 0; j -= 2) if (a[j] & 1) { if (g[j - 1]) f[i] = 1; ...
2
#include <bits/stdc++.h> int N, A[1000], K; static constexpr int MOD = 998244353; int subtask(int D) { static int dp[1001][1001]; for (int i = 0; i <= N; ++i) dp[i][1] = i; for (int i = 2; i <= K; ++i) { for (int j = 0; j < i; ++j) dp[j][i] = 0; for (int j = i; j <= N; ++j) { dp[j][i] = dp[j - 1][i]...
17
#include <bits/stdc++.h> using namespace std; char s[500010]; vector<int> vs, vh; bool vis[500010]; int n, t, hh; bool gao(int mid) { int p; if (vs.size() + mid < vh.size()) return false; int endd = max(mid >= vh.size() ? 0 : vs[vh.size() - 1 - mid], vh[vh.size() - 1]); for (int i = 0; i < n; i++) { i...
15
#include <cstdio> #include <algorithm> #include <numeric> int as[100005]; int main(){ int T; scanf("%d",&T); while(T--){ int N; scanf("%d",&N); for(int i=0;i<N;i++){ scanf("%d",&as[i]); } long long total=std::accumulate(as,as+N,0LL); long long max=*std::max_element(as,as+N); lo...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 200500; int a[MAXN], b[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int r = 0; int cnt = 0; for (int i = 0; i < n; i++) { while (r < n && a[i] != b[r]) r++; if (...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long po(long long a, long long b) { if (b == 0) return 1 % mod; long long y = po(a, b / 2); y = y * y % mod; if (b % 2 == 1) y = y * a % mod; return y; } long long inv(long long i) { return po(i, mod - 2); } struct trie { lo...
11
#include <bits/stdc++.h> int main() { long k2, k3, k5, k6, a = 0; scanf("%ld", &k2); scanf("%ld", &k3); scanf("%ld", &k5); scanf("%ld", &k6); while (k2 > 0 && k5 > 0 && k6 > 0) { a = a + 256; k2 = k2 - 1; k5 = k5 - 1; k6 = k6 - 1; } while (k3 > 0 && k2 > 0) { a = a + 32; k3 = k3 ...
0
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
21
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e9; const long long INF = 1e18; const long double EPS = 1e-8; const long double Pi = acosl(-1); const long long P = 31; const long long dx[4] = {0, 0, 1, -1}; const long long dy[4] = {1, -1, 0, 0}; const long long N = 1e...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 5; int n, m, vis[N], p[N], to[N], fl = 0; vector<int> ans, g[N]; void dfs(int v) { vis[v] = 1; int u; if ((to[p[v]] != to[v]) || (p[v] == v)) { if (to[v] != v) { fl = 1; } ans.push_back(v); } for (int i = 0; i < (int(g[...
12
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { s << "{ "; for (int i = 0; i < P.size(); ++i) { if (i > 0) s ...
18
#include <bits/stdc++.h> using namespace std; struct inque { long long nom, level; }; long long n, i, j, ans = 0, mx, x, lv, k, col = 0, m, p, lc, ln; char c[200][200]; pair<long long, long long> pl[200]; long long cols[200]; long long mymod(long long x) { if (x < 0) return x * (-1); else return x; } int ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long p[200020]; long long s[200020], e[200020]; int main() { int n, k, x; cin >> n >> k >> x; for (int i = 1; i <= n; i++) cin >> p[i]; s[0] = 0; for (int i = 1; i <= n; i++) { s[i] = s[i - 1] | p[i]; } e[n + 1] = 0; for (in...
9
#include <bits/stdc++.h> using namespace std; using INT = long long; using pii = pair<int, int>; int a[200100]; int calc(vector<int> vec) { if (vec.size() == 1) return vec.size(); vector<int> tmp[31]; for (int x : vec) { int id = 31 - __builtin_clz(x); int op = id + 1; if (x == 0) op = 0; int val ...
13
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 1e6 + 7, mod = 1000000007, M = 2e9; const long long MAX = 5e18; int n, u, mx[N], lef[N], ans, child[N], v; vector<int> g[N]; int dfs(int u = 1, int p = 0) { if (lef[u]) return 1; int ret = M * mx[u]; for (int i : g[u]) { i...
11
#include <bits/stdc++.h> using namespace std; const int mod = int(1e9 + 7), MAXN = int(2e5 + 1); long long n, q, x; void solve(long long x) { if (x % 2 == 1) printf("%lld\n", (x + 1) / 2); else { x += n - (x / 2); solve(x); } } int main() { cin >> n >> q; for (int i = 0; i < q; i++) { cin >> x...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (auto i = 0; i < t; i++) { long long n, x, y, a, b; cin >> n >> x >> y; long long score = x + y; long long temp = score + 1 - n; if (temp > n) cout << n << " " << n << "\n"; else { if (temp <= 1) ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; string answer = ""; for (int i = 0; i < s.length(); i++) { if (s[i] == '2') answer = answer + "2"; if (s[i] == '3') answer = answer + "3"; if (s[i] == '4') answer = answer + "322"; if (s[i] == '5'...
6
#include <bits/stdc++.h> using namespace std; int n, ans = 0; int main() { scanf("%d", &n); if (n == 0) ans = 15; if (n == 1) ans = 14; if (n == 2) ans = 12; if (n == 3) ans = 13; if (n == 4) ans = 8; if (n == 5) ans = 9; if (n == 6) ans = 10; if (n == 7) ans = 11; if (n == 8) ans = 0; if (n == 9)...
11
#include <bits/stdc++.h> using namespace std; int main() { string s, t[15]; int n, ans = 0; cin >> s; cin >> n; for (int i = 0; i < n; i++) cin >> t[i]; for (int j = 0; j < n; j++) { int t1 = 0, t2 = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == t[j][0]) t1++; else { ...
8
#include <bits/stdc++.h> using namespace std; const int MAX_N = 7000; const int MAX_M = 7000; const int MAX_C = 1 << 17; const int BN = 13; struct Op { int t, l, r, x; Op() {} Op(int _t, int _l, int _r, int _x) : t(_t), l(_l), r(_r), x(_x) {} }; int ps[MAX_C][BN], xs[MAX_M]; Op ops[MAX_M]; inline bool ise2(int a)...
16
#include <bits/stdc++.h> using namespace std; const int N = 510; int tab[N][N]; int S[N][N]; int F[2][N][N]; int n, m; int sum(int w, int k, int dw, int dk) { return S[w + dw - 1][k + dk - 1] - S[w - 1][k + dk - 1] - S[w + dw - 1][k - 1] + S[w - 1][k - 1]; } int main() { scanf("%d %d", &n, &m); for (int ...
11
#include <bits/stdc++.h> using namespace std; int INF = 1e9 + 7; long long LLINF = 1e18; int MOD = 998244353; ostream& operator<<(ostream& out, vector<int>& v) { for (int num : v) out << num << ' '; return out; } ostream& operator<<(ostream& out, vector<long long>& v) { for (long long num : v) out << num << ' '; ...
10
#include <bits/stdc++.h> using namespace std; struct Point { long long int a; long long int b; }; bool acomparenum1(Point x, Point y) { if (x.a != y.a) { return x.a > y.a; } else { return x.b > y.b; } }; int main() { long long int n; cin >> n; Point array[n]; for (long long int i = 0; i < n; i...
11
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } template <typename T> inline void write(T x) { int i = 20; char buf[...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &m); if (i == n - 1) printf("%d\n", m % 2 ? m : m - 1); else printf("%d ", m % 2 ? m : m - 1); } return 0; }
0
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < '0' || C > '9';) if (C == '-') F = 1; for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0') ; F && (T = -T); } int F[200][200]; int Need[200][200]; int N; void Init() {...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s; cin >> s; int sar = 0; int numf = -1; vector<int> v; long long ans = 0; for (int i = 0; i < (int)s.size(); i++) { if (s[i] == 'F') numf++; else continue; int he = i - numf; if (h...
12
#include <bits/stdc++.h> char a[100005], b[100005]; int main() { gets(a); gets(b); int i, j, ans = 0, lena = strlen(a), lenb = strlen(b); for (i = 0; i < lena; i++) { for (j = i; j < i + lenb; j++) { if (a[j] != b[j - i]) break; } if (j == i + lenb) { ans++; i += lenb - 1; } ...
4