solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; void solved_by_satyapsr13() { string s, k; cin >> s >> k; int size_s = s.size(); int size_k = k.size(); int pos = 1; int j = 0; for (int i = 0; i < k.size(); ++i) { if (s[j++] == k[i]) { pos++; } else { j--; } } cout << pos << "\n";...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 7; int n, k; long long a[maxn]; long long dp[maxn]; bool check(long long x) { for (int i = 1; i <= n; i++) dp[i] = 0x3f3f3f3f; dp[1] = 0; for (int i = 2; i <= n; i++) { dp[i] = i - 1; for (int j = i - 1; j >= 1; j--) { if (abs(a[i...
12
#include <bits/stdc++.h> using namespace std; int nums[5], r, n, T; int main() { ios::sync_with_stdio(0); cin >> T; while (T--) { cin >> n >> r; int sum = 0; for (int c = 1; c < n; c++) { int i; cin >> i; sum -= i; } sum += r; sum += n * 1000; cout << (sum % n + 1) <<...
16
#include <bits/stdc++.h> const int MAXC = 1e5 + 5; const int MAXK = 11; const int MAXN = 505; int card[MAXC]{}; int dp[MAXN][MAXK * MAXN]{}; int fave[MAXC]{}; int h[MAXK]{}; int c, f, K, N; int main() { scanf(" %d%d", &N, &K); int KN = K * N; for (int i = 0; i < KN; ++i) { scanf("%d", &c); ++card[c]; } ...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; long long r[MAXN]; long long h[MAXN]; int v[MAXN]; long long t[4 * MAXN]; double pi = (double)3.14159265358979323846; long long query(int idx, int L, int R, int i, int j) { if (L > R || R < i || L > j) return 0; if (L >= i && R <= j) return t[id...
12
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MOD = INF + 7; const int MAXN = 100010; struct edge { int w, b, p; edge(int _w, int _b, int _p) { w = _w; b = _b; p = _p; } }; bool cmp(edge a, edge b) { if (a.w != b.w) { return a.w < b.w; } else if (a.b != b....
9
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; const int maxn = 300 + 50; const int INF = 0x3f3f3f3f; long long Qpow(int n, long long x) { long long ans = 1; while (n) { if (n & 1) ans = (ans * x) % Mod; x = (x * x) % Mod; n >>= 1; } return ans; } long long solve(long long n)...
7
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; const long double E = 1e-5; unsigned char ccc; bool _minus = false; template <typename T> inline T sqr(T t) { return (t * t); } inline void read(long long &n) { n = 0; _minus = false; while (true) { ccc = getchar(); if (ccc == ' ' ||...
16
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int inf = 0x3f3f3f3f; const int hinf = 0x3f3f3f3f; const long long mod = 1000000007; int n, k; int len; string name; string limit; char ans[110]; int main() { cin >> n >> k >> name >> limit; len = name.length(); memset(ans, 0, sizeof(ans...
13
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
19
#include <bits/stdc++.h> using namespace std; inline void re(int &x) { x = 0; bool flag = false; char c = getchar(); while (c < '0' || c > '9') { flag = c == '-'; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ '0'); c = getchar(); } if (flag) x = -x; ret...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 2e3 + 1; int a[N][N]; int m[2][N], n; bool use[N]; long long dp[N][N], t[N]; int f(int i) { return i & (-i); } void fenw(int s, int i, int j) { while (i <= n) { m[s][i] += j; i += f(i); } } int fw(int s, int i) { ...
21
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(const T &a) { return a * a; } const long double EPS = 1e-9; const long double PI = 2 * acos(0.0); const int N = 200100; bool var_set[N]; bool var_ans[N]; bool var_used[N]; bool disj_used[N]; bool v_used[N]; vector<pair<int, bool>> disjs[N];...
17
#include <bits/stdc++.h> template <typename T> inline T max(T a, T b) { return a > b ? a : b; } template <typename T> inline T min(T a, T b) { return a < b ? a : b; } template <typename T> inline T abs(T a) { return a > 0 ? a : -a; } template <typename T> inline bool repr(T &a, T b) { return a < b ? a = b, 1 : ...
15
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, flag; cin >> t; while (t--) { int x = 10000; flag = 0; cin >> n; int s[n]; for (i = 0; i < n; i++) { cin >> s[i]; } sort(s, s + n); for (i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) { cout...
0
#include <bits/stdc++.h> using namespace std; const int N = 12; int n, A[N][N]; int dp[N][N][3][200 + 5][200 + 5]; const int d0[8][2] = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, 2}, {1, -2}, {-1, 2}, {-1, -2}}; const int d1[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; const int d2[4][2] = {{1, 0},...
14
#include <bits/stdc++.h> using namespace std; long long int fast_pow(long long int base, long long int exp) { if (exp == 0) return 1; if (exp == 1) return base % 998244353; long long int t = fast_pow(base, exp / 2); t = ((t % 998244353) * (t % 998244353)) % 998244353; if (exp % 2 == 0) return t; else ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int c = 0; long long int i; for (i = 5; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) { c = 1; break; } else { if (n / i > 5) { c = 1; break; ...
3
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") long long n, a[200005]; vector<pair<long long, long long>> v; set<long long> s; map<long long, long long> mp, mpf; void solve() { cin ...
9
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1, *p2; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } int rd() { int x = 0; char c = gc(); for (; c < 48 || c > 57; c = gc()) ; for (; c ...
23
#include <bits/stdc++.h> using namespace std; vector<vector<long long int>> cur(20, vector<long long int>(2)); vector<long long int> adj[(long long int)(2e5 + 5)], s((long long int)(2e5 + 5)), a((long long int)(2e5 + 5)); vector<bool> mrk((long long int)(2e5 + 5)); long long int dfs(long long int c, long long int p...
13
#include <bits/stdc++.h> using namespace std; long long n, m; string s[100]; long long dp[100][2][2][2]; long long ans(long long pos, long long lc, long long dig, long long sym) { if (dp[pos][lc][dig][sym] != -1) return dp[pos][lc][dig][sym]; if (pos == n + 1) { if (lc && dig && sym) return 0; else ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, a[2210], ans = 0; cin >> n >> k; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (long long i = 0; i < k; i++) ans += a[i]; cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; struct poz { int c1, c2, r1, r2, nr; }; struct drum { int y, t; drum(int y, int t) { this->y = y; this->t = t; } }; struct nodS { int cul; bool viz; vector<drum> vecini; }; int t, n, i, nr0, nr1, ans; bool ok; int a[200005]; int b[200005]; poz fr[20000...
15
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const double EULER = 0.577215664901532860; const double PI = 3.1415926535897932384626; const double E = 2.71828182845904523536028; long long pow_mod(long long a, lon...
15
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 10; const long long INF = 1e18; const long long MOD = 1e9 + 7; int main() { long long n, m, k; cin >> n >> m >> k; k--; long long o = k / (m * 2); cout << o + 1 << ' '; k -= o * (m * 2); k += 2; cout << k / 2 << ' '; k--; if ...
0
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) int q, q1, a[500], s[500], d[500], f[500], ans[500]; int abs(int w) { if (w < 0) w = -w; return w; } int l(int e, int r) { return abs(a[e] - a[r]) + abs(s[e] - s[r]); } bool slv() { int w, e, r, t; for (w = 0; w < q; w += 2) { ans...
8
#include <bits/stdc++.h> using namespace std; char t[10][10][11]; int k, n, m; int dfs(int z, int y, int x) { if (!(0 <= z && z < k && 0 <= y && y < n && 0 <= x && x < m && t[z][y][x] == '.')) { return 0; } t[z][y][x] = '$'; return dfs(z - 1, y, x) + dfs(z + 1, y, x) + dfs(z, y - 1, x) + df...
6
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j, k; char c; cin >> t; while (t--) { c = 'a'; cin >> n >> k; j = n % k; while (j--) cout << c; n /= k; for (i = 0; i < k; i++) { j = n; while (j--) cout << c; c++; } cout << endl; } ret...
0
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <string> #include <iostream> #include <map> #include <set> #include <vector> #include <math.h> #include <queue> #include <bitset> #include <unordered_map> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; const int INF = 0x3f3f3f3f; const int P = 131; int block, n, m, a[N]; long long cnt[N], ans[N]; long long sum; struct node { int l, r, id; bool operator<(const node &w) const { if (l / block != w.l / block) return l < w.l; return r < w.r;...
14
#include <bits/stdc++.h> using namespace std; const int N = 1111111; const int md = (int)1e9 + 7; inline void add(int& a, int b) { a += b; if (a >= md) { a -= md; } } int dp[N][22][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int x = log2(n); dp[1][x][0] = 1; if ((1...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { long long n; cin >> n; long long arr[n]; long long ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; ans += arr[i]; } int q; cin >>...
13
#include <bits/stdc++.h> using namespace std; char gragh[10][10][11]; int k, n, m, x, y, ans; void bfs(int x, int y, int z) { if (gragh[x][y][z] == '#' || x < 0 || x >= k || y < 0 || y >= n || z < 0 || z >= m) return; ++ans; gragh[x][y][z] = '#'; bfs(x + 1, y, z); bfs(x - 1, y, z); bfs(x, y + 1, z...
6
#include <bits/stdc++.h> using namespace std; int n; int q[128]; int v[111]; int a[111]; int x[10]; int y[10]; bool ok() { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (v[i] == v[j] && a[i] != a[j] && !y[a[i]] && !y[a[j]]) return false; if (!x[v[i]] && !x[v[j]] && a[i] != a[j] &&...
9
#include <bits/stdc++.h> using namespace std; set<int> x; int n; bool moho(int mit) { int mit2 = mit; while (x.count(mit2) > 0) { mit2 /= 2; } if (mit2 == 0) { return 0; } else { x.erase(mit); x.insert(mit2); return 1; } } int main() { cin >> n; int y; for (int i = 0; i < n; i++) {...
11
#include <bits/stdc++.h> using namespace std; const int mxN = 2e5; int n, m, ans, p[mxN]; array<int, 3> e[mxN]; bool c[mxN]; int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); } bool join(int x, int y) { if ((x = find(x)) == (y = find(y)) || c[x] && c[y]) { if (c[x]) return 0; return c[x] = 1; } ...
17
#include <bits/stdc++.h> using namespace std; const int N = 200050; vector<int> adj[N]; int n, m, k; vector<int> pos; int A[N]; bool vis[N]; int pai[N], peso[N]; int dist[N]; int fd(int x) { return pai[x] == x ? x : pai[x] = fd(pai[x]); } void join(int u, int v) { u = fd(u), v = fd(v); if (peso[u] > peso[v]) swap(u...
12
#include <bits/stdc++.h> using namespace std; unordered_map<long long, long long> mp; int main() { long long n, p, k; cin >> n >> p >> k; for (int i = 1; i <= n; i++) { long long x; cin >> x; mp[(((x * x % p) * (x * x % p) - k * x % p) % p + p) % p]++; } long long ans = 0; for (auto it = mp.begi...
15
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const long long P = 1000000007LL; const int maxN = 210000; char s[maxN], t[maxN]; vector<int> prefix_function(string s) { int n = (int)s.length(); vector<int> pi(n); for (int i = 1; i < n; ++i) { int j = pi[i - 1]; w...
12
#include <bits/stdc++.h> using namespace std; int a[105][105]; int main() { int n; int ans = 0; cin >> n; int x1, y1, x2, y2; for (int i = 1; i <= n; i++) { cin >> x1 >> y1 >> x2 >> y2; for (int j = x1; j <= x2; j++) for (int k = 100 - y1 + 1; k >= 100 - y2 + 1; k--) { a[j][k]++; }...
2
#include <bits/stdc++.h> using namespace std; long long n, a[101], b[101]; long long c[101], dp[101][101][101]; vector<pair<long long, long long> > v; long long sol(long long in, long long rem, long long sim) { if (in == n) return 0; if (dp[in][rem][sim] < 1e13) return dp[in][rem][sim]; long long ans = 1e13; if...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, C1 = 0; cin >> n; char ch[n]; for (int i = 0; i < n; i++) { cin >> ch[i]; } for (int i = 0; i < n; i++) { if ((ch[i] == 'R' && ch[i + 1] == 'U') || (ch[i] == 'U' && ch[i + 1] == 'R')) { C1++; i++; } else...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a; a = (n % 4 == 0) ? n / 4 : n / 4 + 1; for (int i = a; i < n; i++) { cout << 9; } while (a--) { cout << 8; } cout << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; long long i, m, n, sum, k; int main() { cin >> n >> m >> k; if (k < n) { cout << k + 1 << " " << 1; return 0; } k -= n; long long x = (k) / (m - 1); long long y = (k) % (m - 1); x = n - x; if (x % 2 == 0) y += 2; else y = m - y; cout << x...
5
#include <bits/stdc++.h> using namespace std; int a[105]; int n, k, t; void prnt() { for (int i = 0; i < n; ++i) cout << a[i] << " "; exit(0); } int main() { cin >> n >> k >> t; for (int i = 0; i < n; ++i) for (int j = 0; j <= k; ++j) { int sum1 = 0, sum2 = 0; for (int z = 0; z < n; ++z) sum1 +=...
5
#include <bits/stdc++.h> using namespace std; const long long M = 1e6 + 1, MOD = 1e9 + 7; long long prefixsum[M]; long long arr[M]; int main() { ios::sync_with_stdio(false); cin.tie(0); int test_case; cin >> test_case; map<char, long long> mp; set<char> st; vector<pair<long long, char>> v; vector<string...
9
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int llINF = 0x3f3f3f3f3f3f3f; const long long int MOD = 1e9 + 7; vector<pair<long long int, long long int> > nodes[100100]; map<pair<int, int>, int> used; set<int> caras; int vis[100100]; int hgt[100100]; long long int dist[100100...
16
#include <bits/stdc++.h> using namespace std; int n, m; int t[200010]; priority_queue<int, vector<int>, less<int>> pq_max; priority_queue<int, vector<int>, greater<int>> pq_min; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> t[i]; int sum = 0, fail_...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 5; int n, k, a[maxn], b[maxn], dp[maxn][200000 + 5]; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); } memset(dp, -0x3f, sizeof(dp)); dp...
11
#include <bits/stdc++.h> using namespace std; long long arr[200006], brr[200006]; int main() { int n, k; scanf("%d%d", &n, &k); int x = (n - k) / 2; if (n == k) { for (int i = 1; i <= n; i++) cout << 1; cout << endl; return 0; } for (int i = 1; i <= x; i++) cout << "1"; cout << "0"; for (int...
14
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md)); } const int xn = 3e5 + 10; const int xm = -20 + 10; const int SQ = 320; cons...
16
#include <bits/stdc++.h> using namespace std; int main() { int a; scanf("%d", &a); if (a == 1) { puts("1 1"); puts("1"); } else { printf("%d 2\n", 2 * a - 1); puts("1 2"); } }
6
#include <bits/stdc++.h> using namespace std; const int Maxn = 2005; int n, m; char B[Maxn][Maxn]; int r1 = Maxn, r2, c1 = Maxn, c2; int cnt; bool Check(int r1, int c1, int a) { if (r1 < 0 || r1 + a - 1 >= n || c1 < 0 || c1 + a - 1 >= m) return false; int got = 0; for (int i = r1; i < r1 + a; i++) got += (B[i...
13
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = v * 10 + c - '0'; while (isdigit(c = getchar())) v = v * 10 + c - '0'; x = v * f; } void readll(long long &x) { l...
18
#include <bits/stdc++.h> using namespace std; long long n, a[10000], b[10000], has; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (a[i] == a[j]) { has += b[i]; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, as, a, i; cin >> n; for (i = 1, as = 0; i <= n; i++) { cin >> a; as = max(a, as); } as = max(0, as - 25); cout << as << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } const int32_t mod = 1e9 + 7; const long long INF = 1e18; const long long N = 1e5 + 5, M = 103;...
5
#include <bits/stdc++.h> using namespace std; long long getint() { char ch = getchar(); long long f = 1, x = 0; while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return f * x; } const int N = 500500; int n, r; lon...
12
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1}; const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1}; long long min(long long a, long long b) { if (a < b) return a; return b; } temp...
15
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; const int N = 5e5 + 10; long long l, r; long long dp[16][1 << 16][16]; int a[N], cnt; long long dfs(int cnt, int mask, int mx, bool limit) { if (cnt == 0) { if (mask & (1 << mx)) return 1; return 0; } if (!limit && dp[cnt][mask][mx] !=...
21
#include <bits/stdc++.h> using namespace std; long long dd[25][2200]; long long re[25][2200]; long long ans[2200]; int main() { long long n; cin >> n; memset((dd), (0), sizeof(dd)); for (long long i = (0); i < (12); ++i) { int index = 0; int a = 2 << i; int b = 1 << i; while (1) { for (lon...
11
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); } long long int binpow(long long int a, long long int b) { a %= 1000000007; long long int res = 1; while (b > 0) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; b >>= 1; ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 85; const long long inf = 1e10; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int k1 = 0, k2 = 0; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x < 0) k1++; else k2...
0
#include <bits/stdc++.h> using namespace std; long b[100005]; int main() { long a[100005], c[100005], count = 0; long long n, m, i, l; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> a[i]; b[a[i]] = 1; } for (i = n; i > 0; i--) { if (b[a[i]] == 1) { count++; b[a[i]] = 2; } c...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("avx") int n, m, l, r, a, x, t, v[100010]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &v[i]); while (m--) { scanf("%d%d%d%d", &t, &l, &r, &x); if (t == 1) { for...
23
#include <bits/stdc++.h> using namespace std; int t, n, k, a[200010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cin >> t; while (t--) { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); long long best = 1000000000, ans = 0; ...
8
#include <bits/stdc++.h> using namespace std; char s[100]; bool ok(char *ss, int cnt) { int p = 1, q = cnt - 1; while (p <= q) { if (ss[p] == ss[q]) { p++, q--; continue; } return false; } return true; } int main() { while (scanf("%s", s + 1) != EOF) { int len = strlen(s + 1); ...
3
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> part; int n; cin >> n; for (int i = 0; i < n; ++i) { string name; int plus, minus, a, b, c, d, e; cin >> name >> plus >> minus >> a >> b >> c >> d >> e; part[name] = plus * 100 - minus * 50 + a + b + c + d + e; } int...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n; bool used[N]; set<int> setik; inline bool f(int x) { if (x < 2) return false; for (int j = 2; j * j <= x; ++j) if (x % j == 0) return false; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
7
#include <bits/stdc++.h> using namespace std; const int N = 100005, M = 100005; int sum, ty[N], qian[N], hou[N]; long long tong[N], a[N], c[N], kind, an[N]; map<long long, int> Ma; struct node { int l, r, block, id; } q[M]; inline void erase1(int p) { tong[a[p]]--; if (hou[a[p]]) kind -= tong[hou[a[p]]]; } inline...
15
#include <bits/stdc++.h> void debug() { fflush(stdin); printf("Press any key to continue"); getc(stdin); } using namespace std; long long l, r; vector<long long> g; void gen(long long cur) { if (cur > r) { g.push_back(cur); return; } if (cur >= l) g.push_back(cur); gen(cur * 10 + 4); gen(cur * 1...
3
#include <bits/stdc++.h> using namespace std; int main() { long long t, x, y, b, tx, ty; cin >> x >> y; if (x > 0 && y > 0) { tx = abs(x); ty = abs(y); b = tx + ty; cout << "0 " << b << " " << b << " 0" << endl; return 0; } if (x < 0 && y > 0) { tx = abs(x); ty = abs(y); b = tx...
2
#include <bits/stdc++.h> using namespace std; mt19937 rnd; struct node { int x = 0; int y = 0; int sz = 1; node *left = nullptr; node *right = nullptr; node() { y = rnd(); } node(int val) { y = rnd(); x = val; } }; int sz(node *r) { if (!r) { return 0; } return r->sz; } void relax(node...
10
#include <bits/stdc++.h> using namespace std; inline bool isLow(char ch) { return (ch >= 'a' && ch <= 'z'); } inline bool isUpp(char ch) { return (ch >= 'A' && ch <= 'Z'); } inline bool isDig(char ch) { return (ch >= '0' && ch <= '9'); } inline bool are_equal(double a, double b) { return fabs(a - b) < numeric_limits<...
7
#include <bits/stdc++.h> int a[105], N; int main() { int m; scanf("%d%d", &N, &m); for (int i = 1; i <= N; i++) a[i] = 0; for (int i = 1, x, y; i <= m; i++) { scanf("%d%d", &x, &y); a[x]++; a[y + 1]--; } for (int i = 1; i <= N; i++) { a[i] += a[i - 1]; if (a[i] != 1) { printf("%d %...
5
#include <bits/stdc++.h> using namespace std; const int N = 2020; int n, ans, p[N]; vector<int> nei[N]; void dfs(int v, int h = 1) { ans = max(ans, h); for (int u : nei[v]) dfs(u, h + 1); } int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> p[i]; if (p...
1
#include <bits/stdc++.h> using namespace std; long long cen, g, tpos = 1, ok = -1, ans = 0, all = 1, flag = 0; void solve() { for (int i = 1; i <= cen; i++) all *= 2; for (int i = 1; i <= cen; i++) { tpos *= 2; tpos += ok; all /= 2; if (ok == -1 && g > tpos * all) { ans += (all * 2 - 1); ...
9
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, b1, b2, b3, n, pa, pb; cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n; int total_a = a1 + a2 + a3; int total_b = b1 + b2 + b3; pa = ceil(total_a * 0.2); pb = ceil(total_b * 0.1); if ((pa + pb) > n) { cout << "NO"; return 0; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, L; scanf("%d%d", &n, &L); vector<int> c(n); for (int i = 0; i < n; i++) { scanf("%d", &c[i]); } for (int i = 1; i < n; i++) { c[i] = min(c[i], 2 * c[i - 1]); } long long ans = (long long)2e18; long long s = 0; for (int i = n -...
8
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> h[200007]; int x[200007], p[200007]; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d", &h[i].first); h[i].second = i; } sort(h, h + n); for (int i = 0; i < n; ++i) { p[h[i].second] = i; x[i] = h...
17
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; int n = 7, m, k, dots = 0, cou = 0, yes = 0, r; int sub[300005]; vector<vector<int>> g; int c1 = -1, c2 = -1; void dfs(int node, int prev) { sub[node] = 1; for (auto j : g[node]) { if (j == prev) continue; dfs(j, node); sub[node] +=...
9
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 0x3f3f3f3f3f3f3f3f; long long n; multiset<long long> ms; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 0; i < n; i += 1) { long long d; cin >> d; ms.insert(d); ...
12
#include <bits/stdc++.h> const int MAXN = 3e5 + 10; const double eps = 1e-8; const int mod = 1e9 + 9; using namespace std; struct edge { int t, v; edge *next; } e[MAXN << 1], *h[MAXN], *o = e; void add(int x, int y, int vul) { o->t = y; o->v = vul; o->next = h[x]; h[x] = o++; } long long read() { long lon...
8
#include <bits/stdc++.h> using namespace std; using points = tuple<int, int>; points arr[4]; int main() { int n, i, a, b, c, d; long long int ans = 0, max, min; scanf("%d", &n); scanf("%d%d%d%d", &a, &b, &c, &d); arr[0] = make_tuple(a + b, 0); arr[1] = make_tuple(a + c, 0); arr[2] = make_tuple(b + d, 0); ...
6
#include <bits/stdc++.h> using namespace std; int T; string t, s; int a[110]; map<pair<int, long long>, long long> mp; long long func(int start, long long step) { if (step == 0) return 0; if (step == 1) return a[start]; pair<int, long long> st = make_pair(start, step); if (mp.find(st) != mp.end()) return mp[st]...
12
#include <iostream> using namespace std; int v[105]; int main() { int t,n,i,j,minn=101; cin>>t; for(j=1;j<=t;j++) { minn=101; cin>>n; for(i=1;i<=n;i++) { cin>>v[i]; if(v[i]<minn) { minn=v[i]; } } ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; while (a > 0 and b > 0) { if (a >= 2 * b) { a = a % (2 * b); } else if (b >= 2 * a) { b = b % (2 * a); } else { break; } } cout << a << " " << b; }
3
#include <bits/stdc++.h> using namespace std; const int MAXD = 35; int n, a[300005]; long long f[300005][MAXD + 5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) a[i] /= 100; for (int i = 0; i <= n; ++i) for (int j = 0; j <= MAXD; ++j) f[i][j] = ...
16
#include <bits/stdc++.h> using namespace std; int num[10], n; int main() { scanf("%d\n", &n); for (int i = 0; i < n; i++) scanf("%d", &num[i]); for (int i = 0; i < n - 1; i++) { if (abs(num[i] - num[i + 1]) >= 2) { printf("NO\n"); return 0; } } printf("YES\n"); return 0; }
8
#include <bits/stdc++.h> using namespace std; const int oo = 0x3c3c3c3c; long long n, a[1000001], res, sum = 0, ans = 0; int main() { cin >> n; res = n + 1; for (long long i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } for (long long i = 1; i <= 5; i++) { if ((sum + i) % res != 1) ans++; } ...
2
#include <bits/stdc++.h> using namespace std; const int inf = int(1e9); const double eps = 1e-9; const double pi = 4 * atan(double(1)); const int N = 2000; int n; bool used[N + 10]; int l[N + 10], r[N + 10], num[N + 10], can[N + 10], sz[N + 10], perm[N + 10]; inline bool can_build(int mid) { for (int i = 0; i < n; i+...
21
#include <bits/stdc++.h> using namespace std; int a[8], i; bool f; int main() { srand(time(NULL)); cin >> a[0] >> a[1] >> a[2] >> a[3]; for (i = 0; i < 200000; ++i) { random_shuffle(a, a + 4); if (a[0] + a[1] == a[2]) f = 1; if (a[0] + a[1] > a[2] && a[1] + a[2] > a[0] && a[0] + a[2] > a[1]) ret...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; const int MAXM = 1e6 + 5; int n, m, val[MAXN][MAXN]; int tot, prime[MAXM]; bool is_prime[MAXM]; void sieves() { memset(is_prime, true, sizeof(is_prime)); tot = 0; for (int i = 2; i <= 1e6; i++) { if (is_prime[i]) prime[tot++] = i; for (in...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5; const long long mod = 1e9 + 9; const int inf = 0x3f3f3f3f; namespace IO { inline int read() { int s = 0, ww = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') ww = -1; ch = getchar(); } while ('0' <= ch && ch <= '9')...
22
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m == 0) { if (n == 1) return printf("0 0\n"), 0; else return printf("-1 -1\n"), 0; } if (m > 9 * n) return printf("-1 -1\n"), 0; int mm = m; string ans; for (int i = 0; i < n; i++) { for (int ...
6
#include <bits/stdc++.h> char a[1111][1111]; int main() { int i, j, n, m = 0, t, flag = 0; for (n = 0; fgets(a[n], 1111, stdin); n++) m = std::max(m, (int)(strlen(a[n]) - 1)); for (i = 0; i < m + 2; i++) putchar('*'); puts(""); for (i = 0; i < n; i++) { putchar('*'); t = strlen(a[i]) - 1; for ...
4
#include <bits/stdc++.h> using namespace std; int dp[2010][2010]; int n, k; vector<vector<int> > del(2010); void calc() { int i, j; for (j = 1; j <= n; j++) { int targ = sqrt(j); for (i = 1; i <= targ; i++) { if (j % i == 0) { del[j].push_back(i); if (j / i != i) { del[j].pus...
6
#include <bits/stdc++.h> const double EPS = 1e-7, PI = acos(-1.0); using namespace std; template <class T> inline T IN(T& num) { num = 0; char c = getchar(), f = 0; while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = 1, c = getchar(); while ('0' <= c && c <= '9') num = num * 10 + c - '0'...
13
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; const int MOD = 1e9 + 7; priority_queue<pair<long long int, int> > pq; vector<pair<long long int, long long int> > vp; map<long long int, long long int> mp, mpp; long long int dp[N]; vector<long long int> v, v1, v2; stack<long long int> s, s1; long lo...
3