solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long int n, i, k, q, t, v[200010]; long long int check[200010], conta = 1, fine = 1 << 31 - 1; void dfs(vector<long long int> p, long long int k, long long int tot) { if (!k) { if (tot < fine) fine = tot; return; } vector<long long int> u, z; bool zeri ...
11
#include <bits/stdc++.h> using namespace std; struct edge { int u; int v; int w; }; const int N = 1e6 + 5; int n, m, s; long long weight[N]; vector<long long> ps; vector<long long> sum; vector<pair<int, int>> graph[N]; vector<pair<int, int>> rgraph[N]; int col[N]; long long dp[N]; vector<pair<int, int>> adj[N]; v...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> s; cin >> n; if (s.size() < n) { cout << "impossible"; return 0; } map<char, bool> m; for (int i = 0; i < s.size(); ++i) { m[s[i]] = 1; } int ans = n - m.size(); if (ans < 0) ans = 0; cout << ans; re...
2
#include <bits/stdc++.h> using namespace std; int s[100050], d[100050]; pair<int, int> p[100050]; int main() { int n, k; long long b; scanf("%d%d%lld", &n, &k, &b); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); p[i] = make_pair(x, i); } n--; sort(p, p + n); long long sum = 0; for (...
9
#include <bits/stdc++.h> using namespace std; int a[300005]; int x[2][1 << 22]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; long long int nop = (k * (k - 1)); if (n > nop) { cout << "NO" << endl; } else { cout << "YES" << endl;...
9
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const double pi = 3.1415926535897932384626433832795028841971693993751058209749445...
14
#include <bits/stdc++.h> int A[26]; int B[27]; char s[100001], p[100001]; int main() { int i, j, sl, pl, t = 0, flag; gets(s); gets(p); sl = strlen(s); pl = strlen(p); for (i = 0; p[i]; i++) { A[p[i] - 'a']++; } if (pl <= sl) { for (j = 0; j < pl; j++) { if (s[j] == '?') B[26]++; ...
7
#include <bits/stdc++.h> using namespace std; int II; long long I_O; char CC, SS[20]; const int N = 1e5 + 4; inline long long read() { II = 1, I_O = 0; while (!isdigit(CC = getchar())) if (CC == '-') II = -1; while (isdigit(CC)) I_O = I_O * 10 + CC - '0', CC = getchar(); return I_O * II; } inline void wonl(...
12
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, d; pair<int, int> f[N]; int main() { scanf("%d%d", &n, &d); for (int i = 1; i <= n; ++i) scanf("%d%d", &f[i].first, &f[i].second); sort(f + 1, f + n + 1); int uk = 1; long long mx = 0, cur_sum = 0; for (int i = 1; i <= n; ++i) { ...
7
#include <bits/stdc++.h> using namespace std; struct node { long long v, pa, l; } bfa[3010]; vector<int> mat[3010]; int que[3010], h, r, dp[3010][3010]; void bfs(int p, int pa) { h = r = 0; dp[pa][p] = bfa[p].l = 0; bfa[p].pa = -1; bfa[p].v = 1; que[r] = p; r++; while (h != r) { for (int i = 0; i < ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int n, m; int pos[maxn]; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; bool check(int i, int j) { int x1 = (i - 1) / m + 1; int y1 = (i - 1) % m + 1; int x2 = (j - 1) / m + 1; int y2 = (j - 1) % m + 1; for (int k = 0; k < 4; k++) { ...
14
#include <bits/stdc++.h> using namespace std; int n; vector<int> v(305); bool adj[305][305]; bool vis[305]; vector<int> p(305); void dfs(int node, vector<int> &cur) { vis[node] = true; cur.push_back(node); for (int i = 1; i <= n; i++) { if (vis[i] || !adj[node][i]) continue; dfs(i, cur); } } int main() ...
8
#include <bits/stdc++.h> using namespace std; string s[1111]; int ans, b[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; bool vis[1111][1111]; void bfs(int i, int j) { queue<pair<int, int> > q; q.push(make_pair(i, j)); vis[i][j] = 1; pair<int, int> a; bool check = 1; while (check) { int tmp = q.size(); ...
7
#include <bits/stdc++.h> using namespace std; vector<string> a; int main() { string s; getline(cin, s); a.clear(); for (int i = 0; i < s.size();) if (s[i] == ',') { a.push_back(","); i++; } else if (s[i] == '.') { a.push_back("..."); i += 3; } else if (isdigit(s[i])) { ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, q; scanf("%lld%lld", &n, &q); while (q--) { long long a; scanf("%lld", &a); if (a % 2) { printf("%lld\n", (a + 1) / 2); continue; } long long m = n; while (a % 2 == 0) { a = m - a / 2; m = a; ...
9
#include <bits/stdc++.h> using namespace std; long long solve(vector<int> a, int k) { sort(a.begin(), a.end()); int n = a.size(); vector<long long> dp(n + 1); for (int i = 1; i < n; i++) { dp[i] = dp[max(0, i - k)] + a[max(0, i - k)] + a[i]; } return dp[n - 1] + a[n - 1]; } void testCase() { int n, k;...
5
#include <bits/stdc++.h> using namespace std; int mod = 1000000007LL; long long large = 2000000000000000000LL; void gcdE(long long a, long long b, long long& d, long long& x, long long& y) { if (!b) { d = a; x = 1; y = 0; } else { gcdE(b, a % b, d, y, x); y -= x * (a / b); } } long long inv(lo...
18
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = LLONG_MAX; const int inf = INT_MAX; const int nmax = 2e3 + 5; const int mod = 1e9 + 7; using namespace std; int n, i, j, k; long long a[nmax][nmax]; int main() { ios_base::sync_with_stdio(false); ci...
11
#include <bits/stdc++.h> using namespace std; int main() { int m1[10][10], i, j; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) cin >> m1[i][j]; } for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { if (m1[i][j] == 1) { int p = abs(2 - i) + abs(2 - j); cout << p << endl; }...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); if (n >= k) printf("%d\n", ((n - (n % k)) + k)); else printf("%d\n", k); }
0
#include <bits/stdc++.h> const int maxn = 200001, mod = (1 << 16) - 1; int q, p1, p2, len, cnt[1 << 16], ans; unsigned int bitA[32][maxn >> 5], bitB[32][maxn >> 5], *it, *jt; char A[maxn], B[maxn]; inline int popcnt(unsigned int x) { return cnt[x >> 16] + cnt[x & mod]; } int main() { scanf("%s%s%d", A, B, &q); for ...
20
#include <bits/stdc++.h> using namespace std; void addmod(int &a, long long b) { a = (a + b); if (a >= 1000000007) a -= 1000000007; } void mulmod(int &a, long long b) { a = (a * b) % 1000000007; } template <class T> bool domin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool domax(T &a, ...
13
#include <bits/stdc++.h> using namespace std; long double X, Y, Z, R, Ux, Uy, Uz, tx, ty, tz; struct sphere { long double x, y, z, r; }; vector<sphere> base; sphere t_sphere; int i, j, n, k; long double MAX_TIME; long double L(long double x, long double y, long double z) { return sqrt(x * x + y * y + z * z); } long...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int i; for (i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) break; } if (i == n - 1) cout << "NO" << endl; else cout << "YES\n" << s.substr(i, 2) << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m, x, y; vector<int> a; vector<int> b; vector<pair<int, int> > ans; int main() { cin >> n >> m >> x >> y; for (int k = 0; k < n; k++) { int tmp; cin >> tmp; a.push_back(tmp); } for (int k = 0; k < m; k++) { int tmp; cin >> tmp; b.push_...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long ma = 2 * n / (k + 1); if (k > ma) { cout << -1 << endl; exit(0); } long long q = 0, s = k * (k + 1) / 2; for (int i = 1; i < sqrt(n) + 1; i++) { if (!(n % i)) { if (i >= s) { q = n...
11
#include <bits/stdc++.h> using namespace std; template <typename T> T inline SQR(const T &a) { return a * a; } int main() { ios::sync_with_stdio(false); string aux; bool last = false, printed = false; while (getline(cin, aux)) { istringstream iss(aux); string aux2; iss >> aux2; if (aux2[0] == ...
9
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; static const double PI = acos(-1.0); inline bool in(int p, pair<int, int> r) { return p >= r.first && p <= r.second; } inline bool in(pair<int, int> r1, pair<int, int> r2) { return r1.first >= r2.first && r1.second <= r2.second; } inline ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 123; int a[maxn]; vector<int> v; struct node { int data; int num; } Hash[maxn], heap[maxn]; int Hashnum, heapnum; int twopoint(int left, int right, int k) { int l = left, r = right; while (l <= r) { int mid = (l + r) / 2; if (Hash[mid]...
10
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 28; const double INF = 1e12, EPS = 1e-9; enum type { UP, DOWN, LEFT, RIGHT }; struct V { int l, r, u, d; type t; }; V v[5000]; int sz; int h, w; void make_graph(vector<vector<int> > &node, vector<string> &in) { vector<int> line(w, -1); int left;...
15
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; struct rec { int dp[5][5]; void init() { for (int i = 0; i < 5; ++i) for (int j = i; j < 5; ++j) if (i == j) dp[i][j] = 0; else dp[i][j] = inf; } rec operator+(const rec &a) const { rec b;...
18
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int maxn = 3e5 + 5; long long int f[maxn]; long long int rt[maxn], lt[maxn]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; vector<long long int> v(...
8
#include <bits/stdc++.h> using namespace std; int n, m; int main() { char w[500][500]; bool use[26]; int i, j, t1; long long k, ans; while (scanf("%d%d\n", &n, &m) != EOF) { ans = 1; for (i = 0; i < n; i++) scanf("%s", w[i]); for (i = 0; i < m; i++) { memset(use, 0, sizeof(use)); for (...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int data[N][2]; vector<int> p_son[N]; vector<int> res; int mark[N]; int key = 0, n; int dfs(int par); int main() { scanf("%d", &n); memset(mark, 0, sizeof(mark)); int sum = 0; for (int i = 1; i <= n; i++) { scanf("%d %d", &data[i][0], &dat...
12
#include <bits/stdc++.h> using namespace std; int dp[1000005]; int sum[1000005][10]; int solve(int n) { if (dp[n] != -1) return dp[n]; if (n < 10) return dp[n] = n; else { int res = 1, nn = n; while (nn > 0) { int lastDigit = nn % 10; if (lastDigit != 0) res *= lastDigit; nn /= 10; ...
5
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; int Tar, n, Ans; void dfs1(int x, int a, int b) { if (x > Tar) { mp[make_pair(a, b)]++; return; } int i, j; for (i = 1; i <= n; i++) { if (((a >> (i - 1)) & 1) == 1) { continue; } j = x - i + 1; if (j > 0 &&...
11
#include <bits/stdc++.h> using namespace std; int arrt[101] = {0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); priority_queue<int> pq; int n, m; cin >> n >> m; int res[n]; int sum = 0; for (int p = 0; p < n; p++) { int k; cin >> k; res[p] = 0; sum += k; int ...
9
#include <bits/stdc++.h> using namespace std; char next_rotation(char actual) { if (actual == '+') { return '+'; } else if (actual == '-') { return '|'; } else if (actual == '|') { return '-'; } else if (actual == '^') { return '>'; } else if (actual == '>') { return 'v'; } else if (actu...
12
#include <bits/stdc++.h> using namespace std; long long k, d, t; long long T, T1, T2; long long v; double res; int main() { cin >> k >> d >> t; if (k % d == 0) { res = 1.0 * t; printf("%f\n", res); } else { T = k + d - k % d; T2 = d - k % d; T1 = k; t = t * 2; v = 2 * k + T2; res =...
9
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") long long mul(long long a, long long b) { return (a * b) % (1000000007); } long long add(long long a, long long b) { return (a + b) % (1000000007); } long long sub(long long a, long long b) { return ((a - b) % (1000000...
11
#include <bits/stdc++.h> using namespace std; long long ans = 0; long long n, t; long long y[1000]; long long c[100][100]; void check() { long long tans1 = 0; long long tans2 = 0; for (long long i = 2; i <= n - 1; i++) if ((y[i - 1] < y[i]) && (y[i] > y[i + 1])) tans1++; for (long long i = 2; i <= n - 1; i+...
11
#include <bits/stdc++.h> using namespace std; inline void using_file(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } mt19937 gen_rand; template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &a) { os << "("; os << a.first << ", "; os <<...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int m, x, y; cin >> m; map<int, int> mp; for (int i = 0; i < m; i++) { cin >> x; mp[i + 1] = x; } cin >> x >> y; for (int i = 1; i <= m; i++) { int begi = 0, semi = 0; for (auto ...
2
#include <bits/stdc++.h> using namespace std; int e[1010][5]; int n, k; struct edge { int v, pre; } bi[1010 * 1010]; int tot, h[1010], que[1010], degree[1010], f[1010]; void deal() { int p, q, x, y, i, j; p = q = 0; for (x = 1; x <= n; x++) if (degree[x] == 0) { que[q++] = x; } while (p < q) { ...
11
#include <bits/stdc++.h> using namespace std; int answer; string str; int main() { ios_base::sync_with_stdio(false); cin >> str; stack<char> S; for (int i = 0; i < str.size(); i++) { char c = str[i]; if (c == ')') { if (!S.empty() && S.top() == '(') { S.pop(); answer += 2; } ...
6
#include <bits/stdc++.h> using namespace std; vector<long long> azaza; long long x, mid, x1, x2, z, max1, i, j, k, n, y, lp, rp, p, l, r, ql, qr, m, M_cnt, k1, k2, ost, ur, a[100500][3], dp[100500][2]; vector<long long> f; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b...
10
#include <bits/stdc++.h> using namespace std; long long a[100005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; long long ans = 0; for (int i = 0; i < n - 1; i++) { int t = 1; while (i + t * 2 < n) t = t * 2; a[i + t] = a[i + t] + a[i]; ans = ans + a[i]; cout << a...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n > 0) { string o; cin >> o; int counter = 0, max_area = 0; bool fact = true; for (int i = 0; i < o.size(); i++) { if (o[i] == 'L') { fact = false; break; } } if (fact == true...
3
#include <bits/stdc++.h> using namespace std; int main() { int i, n, k, q, j, temp, x, t, size; int level[100] = {0}; bool *flag; bool rate; flag = new bool[100]; for (i = 0; i < 100; i++) flag[i] = true; cin >> n >> k; t = k; k = n / k; for (i = 0; i < n; i++) cin >> level[i]; long int max = -1, ...
11
#include <bits/stdc++.h> using namespace std; int t, n, m, a[200100], endur[200100], it[800100]; void init(int k, int l, int r) { if (l == r) { it[k] = a[l]; return; } int mid = (l + r) / 2; init(k * 2, l, mid); init(k * 2 + 1, mid + 1, r); it[k] = max(it[k * 2], it[k * 2 + 1]); } int get(int k, int...
9
#include <bits/stdc++.h> using namespace std; long long n, q, x, y; long long g[100005]; int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) { long long a; scanf("%lld", &a); g[a]++; if (g[a] % 4 == 0) x++; if (g[a] % 2 == 0) y++; } scanf("%lld", &q); while (q--) { char t[5]; ...
6
#include <bits/stdc++.h> unsigned d[10], p[7] = {1869, 6198, 1896, 1689, 1986, 1968, 1698}, m, i; int main() { char c; while ((c = getchar()) > 0) if (c >= '0') d[c - '0']++; d[1]--; d[8]--; d[6]--; d[9]--; for (i = 10; --i;) while (d[i]--) { m = (m * 3 + i) % 7; putchar('0' + i); ...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); string str; getline(cin, str); while (t--) { getline(cin, str); int d = 0; int c = 0; for (int i = 1; i <= str.size(); i++) { if (str[i - 1] == 'R') { d = max(d, i - c); c = i; } ...
3
#include <bits/stdc++.h> using namespace std; const int NMAX = 100010; int N, D, B; int V[NMAX], leftSum[NMAX], rightSum[NMAX]; int computeLeft(int kStud) { int prefixSum = 0; int answer = 0; for (int i = 1; i <= (N + 1) / 2; ++i) { int right = i + 1ll * D * i <= N ? i + D * i : N; if (leftSum[right] - pr...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, i, j, k, d; cout << "?" << " " << "1" << " " << "2" << "\n"; fflush(stdout); cin >> a; cout << "?" << " " << "2" << " " << "3" << "\n"; fflush(stdout); ci...
6
#include <bits/stdc++.h> using namespace std; int vis[1000]; int main() { int n, k, t, cnt = 1; cin >> n >> k; int arr[30]; for (int i = 0; i < k; i++) { cin >> t; arr[i] = t; vis[t] = 1; } for (int i = 0; i < k; i++) { cout << arr[i] << " "; int j = 0; while (j < n - 1 && cnt < 1000...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) cout << "1"; else { vector<int> a; for (int i = 0; i < n; i++) a.push_back(1); for (int i = 0; i < n; i++) { if (a[i] == a[i + 1]) { a[i + 1]++; a.erase(a.begin() + i); i = -1; ...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e1 + 10; vector<int> v[N][N]; int cnt[N][N]; int deg[N]; int flag[N]; class UnionSet { public: int fa[N]; void init(int n = N) { memset(fa, -1, sizeof(int) * n); } int treesize(int x) { return -fa[Find(x)]; } int Find(i...
12
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b /...
3
#include <bits/stdc++.h> using namespace std; int mod1 = int(1e9) + 7; long long inp[100010]; long long S, L; struct SegNode { long long mmax, mmin; }; SegNode combine(SegNode &x, SegNode &y) { SegNode z; z.mmax = max(x.mmax, y.mmax); z.mmin = min(x.mmin, y.mmin); return z; } SegNode initNode(int inpI) { Se...
12
#include <bits/stdc++.h> using namespace std; int n; int m; char stra[100][100]; int p[10000]; map<int, vector<pair<int, int>>> mapa; inline int get(int i, int j) { return i * 100 + j; } int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } void fail() { puts("No"); exit(0); } void succeed() { puts("Yes")...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (int)1e9 + 7; const long long LINF = (long long)9e18 + 7; const long long P1 = 353251; const long long P2 = 239017; const long long MOD = 1e9 + 7; const long long MOD1 = 1e9 + 7; const long long MOD2 = 1e9 + 9; int...
15
#include <bits/stdc++.h> using namespace std; long long i, n, a[100505], p[100505], m, j; vector<long long> d[100505]; long long pomod(long long a, long long b) { long long x = 1; while (b > 0) { if (b % 2 == 1) { x = x * a; x %= 1000000007; } a = a * a; a %= 1000000007; b = b / 2; ...
12
#include <bits/stdc++.h> using namespace std; signed main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); } long long x, y, z; cin >> x >> y >> z; if (x == y && !z) cout << '0' << "\n"; else if (x - z > y) cout << '+' << "\n"; else if (y - z > x) cout << '-' << ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n; cin >> n; vector<long long> adj[2 * n]; vector<pair<long long, long long> > a; for (long long i = (0); i < (n); i++) { long long x, y; cin >> x >> y; x--; y--; pair<long long, long l...
18
#include <bits/stdc++.h> using namespace std; const int Rea = 1e5 + 3; struct Rin { char c; inline char gc() { static char rea[Rea]; static char *head, *tail; return head == tail && (tail = (head = rea) + fread(rea, 1, Rea, stdin), head == tail) ? EOF ...
19
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int>> p; bool is(int val) { int c = 0; vector<bool> pres(n, 0); bool flag = 0; for (int i = 0; i < m; i++) { c = 0; for (int j = 0; j < n; j++) { if (p[i][j] >= val) { pres[j] = true; c++; } } if (c...
10
#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 vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<doub...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int i; for (i = 0; i < t; i++) { int n; cin >> n; for (int j = 0; j < n; j++) { cout << "1" << " "; } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> ans; while (n != 2 and n != 3) { ans.push_back(2); n -= 2; } ans.push_back(n); cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 50 + 20; int n, m, maxu, maxr, minr = MAXN, minu = MAXN; char a[MAXN][MAXN]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] == '*') { minu = min(minu, j); ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int v; cin >> v; long long int deg[v]; long long int s[v]; long long int sum = 0; queue<long long int> q; for (int i = 0; i < v; i++) { cin >> deg[i] >> s[i]; sum += deg[i]; if (deg[i] == 1) q.push(i); } long long int e =...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, c; cin >> n >> m; a = n % m; b = n / m; c = m - a; for (int i = 0; i < c; i++) { cout << b << " "; } for (int i = 0; i < a; i++) { cout << b + 1 << " "; } return 0; }
0
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void inout() {} int main() { fast(); inout(); int t; cin >> t; while (t--) { int n; cin >> n; if (n == 1) { cout << 1 << "\n"; continue; } if (n % 2) cout <<...
0
#include <bits/stdc++.h> using namespace std; int n, m, k, s; int a[2005][2005]; int q[100005]; int dis[20][20]; bool bio[2005][2005]; int memo[2005][2005]; int memo2[2005][2005]; void bfs(int x) { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { bio[i][j] = false; memo[i][j] = -1; me...
14
#include <bits/stdc++.h> using namespace std; int a[30]; int main() { string s; cin >> s; int c = 1, mx = 0; for (int i = 0; i < s.size(); i++) { if (a[s[i] - 'a'] == 0) { a[s[i] - 'a'] = c; c++; mx = max(mx, s[i] - 'a'); } } for (int i = 0; i <= mx; i++) { if (a[i] != i + 1) {...
3
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf("%d%d", &n, &k); for (int i = 1; i < n - k; ++i) printf("%d ", i); for (int j = n; j >= n - k; --j) printf("%d ", j); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; int n, m, p; int arr[MAXN][MAXN]; vector<pair<int, int> > pos[MAXN * MAXN]; int ma[MAXN * MAXN]; int cnt = 0; int dist[MAXN][MAXN][MAXN]; int xx[4] = {-1, 1, 0, 0}; int yy[4] = {0, 0, -1, 1}; int dp[MAXN][MAXN]; int di[MAXN][MAXN]; int ur[MAXN][MAXN]; ...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; const int inf = 0x3f3f3f3f; int arr[maxn]; int dp[maxn][4]; int getmin1(int a, int b, int c, int d) { int x = a < b ? a : b; x = x < c ? x : c; return x < d ? x : d; } int getmin(int a, int b, int c) { int x = a < b ? a : b; return x < c ?...
6
#include <bits/stdc++.h> using namespace std; int main() { long int n, m, i, j, c, k, l; cin >> n >> m; long int a[n], b[m]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < m; i++) { cin >> b[i]; } i = 0; j = 0; c = 0; k = a[0]; l = b[0]; while ((i < n) && (j < m)) { if (k...
3
#include <bits/stdc++.h> using namespace std; double dist(int x1, int y1, int x2, int y2) { double d = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2)); return d; } int main() { int n, k; cin >> n >> k; int x1 = 0, y1 = 0, x2 = 0, y2 = 0; double d = 0; cin >> x2 >> y2; for (int i = 1; i < n; i++) { x1 = ...
1
#include <bits/stdc++.h> using namespace std; vector<vector<int>> groups; vector<int> p, h; int color(int u) { if (u == p[u]) return u; return p[u] = color(p[u]); } void join(int u, int v) { u = color(u); v = color(v); if (u == v) return; if (h[u] > h[v]) { p[v] = u; } else { p[u] = v; } if (h...
9
#include <bits/stdc++.h> using namespace std; char MAP[102][102]; int row[102]; int colum[102]; bool Row[102]; bool Colum[102]; int main() { int n; cin >> n; memset(row, 0, sizeof(row)); memset(Row, false, sizeof(Row)); memset(colum, 0, sizeof(colum)); memset(Colum, false, sizeof(Colum)); for (int i = 1; ...
7
#include <bits/stdc++.h> using namespace std; vector<int> colour; vector<int> c(2); vector<vector<pair<long long, long long> > > g; bool ok; void dfs(long long v) { c[colour[v]]++; for (auto i : g[v]) { if (colour[i.first] == -1) { colour[i.first] = colour[v] ^ i.second; dfs(i.first); } else if ...
9
#include <bits/stdc++.h> using namespace std; int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1}; int n; void add(int i, int j) { printf("%d + %d = %d\n", i, j, i + j); } void sub(int i, int j) { printf("%d - %d = %d\n", i, j, i - j); } void mul(int i, int j) { printf("%d * %d = %lld\n", i...
7
#include <bits/stdc++.h> using namespace std; const int max_n = 110; vector<pair<long long, long long> > les, gre; int main() { long long t, i, j, a, b, c, n, m, k, x, left, right, sum = 0; cin >> n; for (i = 0; i < n; ++i) { cin >> x >> a; if (x < 0) les.push_back(make_pair(x, a)); else g...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; if (n == 2 && x == 0) { cout << "NO" << endl; return 0; } cout << "YES" << endl; long long pw = 1 << 17; if (n == 1) cout << x << endl; else if (n == 2) cout << 0 << " " << x << endl; else { int te ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, a, g = 1; cin >> n; j = n * n; for (i = 1; i <= n; i++) { a = g; for (k = 1; k <= n / 2; k++) { cout << a << " "; a++; } for (k = 1; k <= n / 2; k++) { a--; cout << j - a + 1 << " "; } g +=...
2
#include <bits/stdc++.h> using namespace std; const int LIM_N = 3e5 + 5; vector<int> adj[LIM_N]; vector<int> cols[LIM_N]; int ans[LIM_N]; set<int> avils; void restor(const int pos, const int pv) { for (int i = cols[pos].size(); i; i--) avils.insert(i); for (const int x : cols[pos]) { if (ans[x]) { avils.e...
14
#include <bits/stdc++.h> using namespace std; template <typename T> inline void ckmax(T& x, T y) { x = (y > x ? y : x); } template <typename T> inline void ckmin(T& x, T y) { x = (y < x ? y : x); } char arr[1 << 20]; char* p; string str; void get_nxt() { while (*p == ' ' && *p != 0) { ++p; } if (*p == 0) ...
18
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; vector<int> e[100010], ei[100010]; int bad[100050], w[100050], d[100050], in[100050], st[100050], stn, ste[100050]; vector<vector<int> > be; int dfs(int v, int p = -1) { d[v] = 1; in[v] = 1; st[stn++] = v; for (int i = 0; i < e[v].size();...
16
#include <bits/stdc++.h> using namespace std; long long n = 1, m; long long add[4 * 200003]; long long tree[4 * 200003]; void Update(long long cx, long long cy, long long qx, long long qy, long long val, long long pos) { long long d = cy - cx + 1; if (cy < qx || qy < cx) return; if (qx <= cx && cy <= ...
8
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cout.tie(0); long long n; cin >> n; deque<long long> a; vector<vector<long long> > zap; vector<long long> ans(n, 0); long long e = n - 1; long long bal = 0; for (long long i = 0; i < 2 * n; ++i) { char c;...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; unordered_map<long long int, int> m; int b[n]; for (int i = 0; i < n; i++) { cin >> b[i]; } deque<int> q; for (int i = 0; i < n; i++) { if (m[b[i]] == 1) { } else { if ((int)q.size() == k) { int...
2
#include <bits/stdc++.h> using namespace std; const int LEN = 1 << 20 | 1; static char buf[LEN], *_s, *_t; static char obuf[LEN], *O = obuf; struct ios { inline bool Isdigit(char c) { return (c >= '0' && c <= '9') ? 1 : 0; } inline char gc() { return (_s == _t) && (_t = (_s = buf) + fread(buf, 1, LEN, stdin)), ...
19
#include <bits/stdc++.h> using namespace std; map<string, char> M; int main() { string pass, s; getline(cin, pass); for (int i = 0; i < 10; i++) { getline(cin, s); M[s] = char(i + '0'); } string ans = ""; for (int i = 0; i < 8; i++) ans += M[pass.substr(i * 10, 10)]; cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int Tc; cin >> Tc; while (Tc--) { int n; cin >> n; string s; cin >> s; int count = 0, sum = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '(') { count++; } else if (s[i] == ')') { count--; } ...
2
#include <bits/stdc++.h> struct S { int i, p, q; } ss[100000 + 100000]; int pp[20 + 1][100000 + 100000]; int compare_(const void *a, const void *b) { struct S *s = (struct S *)a; struct S *t = (struct S *)b; return s->p != t->p ? s->p - t->p : s->q - t->q; } int compare(const void *a, const void *b) { int ia ...
18
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define int long long #define pb push_back #define mod 1000000007 #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define inf 1e18 #define pre(x,y) fixed<<setprecision(y)<<x #define pq priority_queue<int> #define mp...
4
#include <bits/stdc++.h> using namespace std; char el = '\n'; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int o = 0, e = 0, s = 0; for (int i = 0; i < n; i++) { int temp; cin >> temp; s += temp; if (temp % 2 == 0) e++; else o++; } if...
1