Dataset Viewer
Auto-converted to Parquet Duplicate
solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int maxn = 15e2 + 20; int l[maxn], r[maxn], a[maxn], n, s, m, k; int dp[maxn][maxn]; bool check(int x) { memset(dp, 0, sizeof dp); for (int i = 1; i <= n; i++) { int last = i + 5; for (int j = 0; j < s; j++) if (l[j] <= i && i <= r[j]) last = min(las...
8
#include <bits/stdc++.h> using namespace std; const int MaxN = int(2e6) + 256; const long long INF = (long long)(1e18); const int mod = 10056; const double pi = 3.1415926535897932384626433832795; long long n, m, ans, a[MaxN], b[MaxN], d[MaxN]; bool used[MaxN]; vector<int> g[MaxN]; void dfs(int v, int c) { d[v] = c; ...
9
#include <bits/stdc++.h> using namespace std; void solve() { int n, x, m; cin >> n >> x >> m; x--; int i, j; int start = x, end = x; for (i = 0; i < m; i++) { int l, r; cin >> l >> r; l--; r--; if (max(l, start) <= min(r, end)) { start = min(l, start); end = max(r, end); ...
2
#include <bits/stdc++.h> using namespace std; struct vertex { long long sum, dist; int cnt; vertex(long long sum, long long dist, int cnt) { this->sum = sum; this->dist = dist; this->cnt = cnt; } vertex() { sum = dist = cnt = 0; } }; int x[100100]; int b[100100]; int ty[100100]; int l[100100]; int...
8
#include <bits/stdc++.h> using namespace std; vector<int> adj[10001]; vector<bool> visit(10001, false); void dfs(int n) { visit[n] = true; int i, s = adj[n].size(); for (i = 0; i <= s - 1; i++) if (!visit[adj[n][i]]) dfs(adj[n][i]); } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout....
2
#include <bits/stdc++.h> using namespace std; int di[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dj[] = {1, -1, 0, 0, 1, -1, 1, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; if (N % 4 > 1) { cout << -1 << '\n'; return 0; } if (N == 1) { cout << 1 << '\n'; ret...
3
#include<bits/stdc++.h> using namespace std; int main() { int t,n,m,i,j; cin>>t; while(t--) { cin>>n>>m; int dp[n+1][m+1]; memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { char c; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, l = 0, r = 0; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x < 0) l++; else r++; } if (l <= 1 || r <= 1) cout << "YES"; else cout << "NO"; }
0
#include <bits/stdc++.h> using namespace std; static const int maxn = 100010; int n; int digit[10]; int main() { while (~scanf("%d", &n)) { memset(digit, false, sizeof digit); int sum = 0; for (int i = 0; i < n; ++i) { int t; scanf("%d", &t); sum += t; digit[t]++; } if (dig...
4
#include <bits/stdc++.h> using namespace std; struct node { long long flag; long long number; long long len; long long pre_len; } vis[100000 + 10]; int Solve(long long repos, long long n) { int l, r, pos, x; l = 0; r = n - 1; while (l <= r) { x = (l + r) / 2; if (vis[x].len <= repos) { pos...
4
#include <bits/stdc++.h> using namespace std; vector<int> E[300010]; int ans[300010]; int p[300010]; inline int find(int a) { if (p[a] == a) return a; p[a] = find(p[a]); return p[a]; } inline void _union(int a, int b) { p[find(a)] = find(b); find(a); } int depth; int v; inline void dfs(int u, int last, int d)...
6
#include <bits/stdc++.h> using namespace std; int n, p, q, a, b; bool visited[10001][10001]; int d[1001][1001]; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; queue<int> qx, qy; inline double sqr(double z) { return z * z; } bool in(double x1, double y1, double x2, double y2, double x3, double y3) { double ax = s...
2
#include <bits/stdc++.h> using namespace std; double a[310], b[310], c[310]; struct POINT { double x; double y; POINT(double a = 0, double b = 0) { x = a; y = b; } }; struct LINE { double a; double b; double c; LINE(double d1 = 1, double d2 = -1, double d3 = 0) { a = d1; b = d2; c = ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10, MOD = 1000 * 1000 * 1000 + 7; int main() { int n, m, i; cin >> n >> m; int a, one, minus; one = minus = 0; for (i = 1; i <= n; i++) { cin >> a; if (a == 1) one++; else minus++; } int l, r, M; for (i = 0;...
0
#include <bits/stdc++.h> using namespace std; struct point { double x; double y; bool operator<(const point& pt) const { if (fabs(x - pt.x) > 1e-9) return (x < pt.x); if (fabs(y - pt.y) > 1e-9) return (y < pt.y); return false; } }; struct circle { point p; double r; }; double dist(point p1, poin...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int hash[3002] = {}; int a; for (int i = 0; i < n + 1; i++) { cin >> a; hash[a]++; } for (int i = 1; i < 3002; i++) { if (hash[i] == 0) { cout << i << "\n"; break; } } }
2
#include <bits/stdc++.h> using namespace std; int main() { int len, cnt; int t; cin >> t; while (t) { cin >> len >> cnt; while (len) { int index = 97; while (index < cnt + 97 && len) { if (len > 0) { cout << char(index); len--; index++; } }...
0
#include <bits/stdc++.h> using namespace std; int a[(int)1e5 + 10]; int line[(int)1e5 + 10]; int cnt[(int)1e5 + 10]; int n; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int p = 1; for (int i = 0; i < n; i++) { if (n % 2) { if (i < n / 2) line[i] = p++; else lin...
5
#include <bits/stdc++.h> using namespace std; int c[1024][1024]; int a[1024]; int sqr(int i) { return i * i; } int main() { int n, m; int i, j; int li, lj; long long ans = 0, ans1; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &c[i][j]); for (i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int n, m, f[1010], vis[100020], used[100020]; struct edge { int a, b, w, id; bool operator<(const edge& b) const { return w < b.w; } edge(int x = 0, int y = 0, int ok = 0, int z = 0) : a(x), b(y), w(ok), id(z) {} } e[100020]; int find(int x) { return f[x] == x ?...
7
#include <bits/stdc++.h> using namespace std; const long long SZ = 1e5 + 7; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long MOD = 998244353; vector<long long> pre(SZ); void init() { for (long long i = 1; i < SZ; ++i) { pre[i] = pre[i - 1] + 3 * i - 1; } } void solve() { long long n;...
1
#include <bits/stdc++.h> using namespace std; long long int f(long long int b, long long int c) { long long int c1 = (c / b) * b; long long int c2 = (c / b + 1) * b; if (!c1) c1 = c2; if (abs(c1 - c) < abs(c2 - c)) return c1; else return c2; } int main() { ios_base::sync_with_stdio(false); cin.tie...
6
#include <bits/stdc++.h> int cnt, head[200005], col[200005]; int link[200005], vis[200005]; struct cup { int a, b; } cp[100005]; struct node { int to, nxt; }; node edge[200005 * 4]; void addedge(int u, int v) { edge[cnt].to = v, edge[cnt].nxt = head[u], head[u] = cnt++; } void init() { cnt = 0; memset(col, 0,...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; string s; cin >> n >> s; vector<int> groups; int pt = 0; for (int i = 1; i < n; ++i) { if (s[i] != s[pt]) { groups.push_back(i - pt); pt = i; } } groups.push...
4
#include <bits/stdc++.h> using namespace std; vector<int> deg(16); vector<vector<int>> dist(16, vector<int>(16, 1000000000)); vector<int> temp(16); int timer = 1; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int x, y, w; long long res = 0; for (int i = 1; i...
8
#include <bits/stdc++.h> using namespace std; bool check(int mid, int n, int m) { int x = (n + m) / 2; n = abs(x - n); m = abs(x - m); x = (n * (n + 1)) / 2 + (m * (m + 1)) / 2; if (mid >= x) return true; return false; } int bs(int n, int m) { int l = 0, h = 1000000000, mid = 0, ans; while (l <= h) { ...
0
#include <bits/stdc++.h> std::vector<std::pair<int, int>> node[131072]; int par[131072], dir[131072], deep[131072]; long long int dis[131072]; void preprocess(int u, long long int cur_dis = 0, int cur_deep = 0) { dis[u] = cur_dis, deep[u] = cur_deep; for (const auto &it : node[u]) preprocess(it.first, cur_dis +...
11
#include <bits/stdc++.h> using lint = long long; void solve() { int n; lint k; std::cin >> n >> k; lint l1, r1, l2, r2; std::cin >> l1 >> r1 >> l2 >> r2; if (l1 > l2) { std::swap(l1, l2); std::swap(r1, r2); } lint ans = 0; if (l2 <= r1) { lint len = std::max(r1, r2) - std::min(l1, l2), ...
6
#include <bits/stdc++.h> using namespace std; const int N = 100010, T = 1000; int n, m, tot, cnt, tp, ans, p[N], head[N], to[N], nxt[N], siz[N], son[N], topx[N], dep[N], f[N], t[N], dfn[N], rnk[N], q[N], w[N], clr[N], a[N], stk[N], ff[N], fhead[N], fnxt[N], fto[N], idx[N], e[N], ad[T * 2 + 10], ct[T * 2 + 1...
10
#include <bits/stdc++.h> const int N = 100; const int moder = 1e9 + 7; int power[N]; int test; int powermod(int a, int exp) { int ret = 1; for (; exp; exp >>= 1) { if (exp & 1) { ret = 1ll * ret * a % moder; } a = 1ll * a * a % moder; } return ret; } int sum(int x) { return 1ll * x * (x + 1) /...
9
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; int n1, n2; n1 = int(sqrt(a)) + 1; n2 = int((-1 + sqrt(1 + 4 * b)) / 2.0) + 1; if (n1 <= n2) { cout << "Vladik" << endl; } else { cout << "Valera" << endl; } return 0; }
0
#include <bits/stdc++.h> int n, d, q; int main() { scanf("%d%d%d", &n, &d, &q); while (q--) { static int x, y; scanf("%d%d", &x, &y); if (y >= x - d && y <= x + d && y >= -x + d && y <= -x + 2 * n - d) puts("YES"); else puts("NO"); } }
1
#include <bits/stdc++.h> using namespace std; vector<long long> add[2000000], del[2000000]; struct pp { long long size, v; } tr[4000000]; struct aa { long long l, r, c, p; bool operator<(const aa b) const { return c < b.c; } } edge[300000]; long long n, m, k; void upd(long long rt, long long l, long long r, long ...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } int c = 0; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1...
0
#include <bits/stdc++.h> using namespace std; bool judge(int num) { int k = sqrt(num); if (k * k == num) return true; else return false; } int main() { int n, m; while (~scanf("%d %d", &n, &m)) { int a, b, c, d; int flag = 0; for (a = 1; a <= 100; a++) { for (b = 1; b <= 100; b++) { ...
8
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int a, b, n, krok = 0; cin >> a >> b >> n; bool podm = false; int g; while (n > 0) { if (krok % 2 == 0) { g = gcd(a, n); n -= g; podm = true; ...
0
#include <bits/stdc++.h> using namespace std; string tostr(int x) { stringstream ss; ss << x; string s; ss >> s; return s; } string tostr(vector<string> vs) { string s = ""; for (int _n(((int)((vs).end() - (vs).begin())) - 1), i(0); i <= _n; i++) s += vs[i]; s += "$" + tostr((int)((vs).end() - (vs)....
5
#include <bits/stdc++.h> using namespace std; inline int ge() { int r = 0, f = 1; char c = getchar(); while (!isdigit(c)) f = c == '-' ? -f : f, c = getchar(); while (isdigit(c)) r = (r << 3) + (r << 1) + c - 48, c = getchar(); return r * f; } int main() { int i = -1, a0[100] = {0}, a2[100] = {0}, a5[100] =...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, s1 = 0, s2 = 0, s3 = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (i % 3 == 0) s1 += a[i]; else if (i % 3 == 1) s2 += a[i]; else s3 += a[i]; } if (s1 >= s2 && s1 >= s3) cout << "ch...
0
#include <bits/stdc++.h> using namespace std; const int sz = 3e5 + 5; long long int a[sz], dp[sz], k; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int i, j, l, z, m, n; long long int fina = 1e18, bg = 0, fre = 1; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; lon...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<long, long>; using vi = vector<int>; using vl = vector<long long>; void fastIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const ll mod = 1e9 + 7; ll x[1001][1001]; voi...
4
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const int maxn = 2e5 + 10; using namespace std; int n, k, ans[maxn], f[maxn]; int a[maxn], b[maxn], pre[maxn], aft[maxn]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) f[i] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[a[i...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 10; typedef long long ll; typedef pair<ll,int> P; vector<pair<int,int> > g[N]; void push(int u,int v,int w){ g[u<<2|0].push_back({v<<2|0,w}); g[u<<2|1].push_back({v<<2|1,w}); g[u<<2|2].push_back({v<<2|2,w}); g[u<<2|3].push_back({v<<2|3,w}); g[...
8
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); } inline long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } const int MAXN = 50005; vector<int> v[MAXN]; int pos[MAXN]; unordered_map<int, int> usado; unordered_map<int, ...
5
#include <bits/stdc++.h> using namespace std; long long MOD = 999999937; long long MD(long long a, long long b) { return (b + (a % b)) % b; } signed main() { cout << "YES\n"; int n; cin >> n; for (int i = 0; i < n; ++i) { long long a, b, c, d; cin >> a >> b >> c >> d; cout << ((100000 - (a % 2) - 2 ...
6
#include <bits/stdc++.h> using namespace std; const int nax = 1e6; int mem[nax]; long long e; int f(long long n, int win) { if (n > e) return win; if (!mem[n]) { mem[n] = (!f(n + 1, win) || !f(n * 2, win)) + 1; } return mem[n] - 1; } struct Range { long long l, r; int w[2]; int f(long long p) { return...
9
#include <bits/stdc++.h> using namespace std; int n, ans; int a[1001], last[10]; int f[1001][1 << 9]; vector<int> g[10]; int check(int len) { memset(last, 0, sizeof(last)); memset(f, -1, sizeof(f)); f[0][0] = 0; for (int i = 0; i < n; i++) { for (int s = 0; s < (1 << 8); s++) if (f[i][s] >= 0) { ...
7
#include <bits/stdc++.h> using namespace std; void fileio() {} vector<vector<long long int>> g; long long int cube_root(long long int x) { long long int lo = 0, hi = 1e6 + 10; while (lo <= hi) { long long int m = (lo + hi) / 2; long long int val = m * m * m; if (val == x) return m; if (val > x) { ...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000 + 10; int c, d, n, m, k; int main() { ios_base::sync_with_stdio(false); cin >> c >> d >> n >> m >> k; int p = n * m; p -= k; int MIN = 9999999; if (p <= 0) { cout << "0"; return 0; } for (int i = 0; i <= p; i++) { int ans...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long s = 0, w = 1; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * w; } long long n...
9
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long powmod(long long a, long long b, long long MOD) { if (a == 0ll) { return 0ll; } a %= MOD; long long ans = 1;...
6
#include <bits/stdc++.h> int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: int x; int y, z; pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p.y...
9
#include <bits/stdc++.h> int n, print; char map[101][101]; int main() { int i, j, k; bool flag1 = 0, flag2 = 0; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s", map[i]); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { for (k = 0; k < n; k++) { if (map[i][k] == '.') break; } ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 1010; int T; int n, x; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> T; while (T--) { cin >> n >> x; int sum = 0; bool same = true, flag = false; for (int i = 0; i < n; i++) { ci...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[4], b[4], coord = 0; cin >> n >> m; char c[n][m]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> c[i][j]; if (c[i][j] == '*') { a[coord] = i; b[coord++] = j; } } } if (a[0] ==...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long double pi = acos((long double)-1); long long num_generator() { return rand() % 1000; } void array_generator(long long a[], long long n) { for (long long i = 0; i < n; i++) a[i] = rand() % 100; } long long update(long long n) { ...
1
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, d[N], a[N], f[N]; int cmp(int x, int y) { return a[x] > a[y]; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), f[i] = i; sort(f + 1, f + n + 1, cmp); for (int i = 2; i <= n; i++) printf("%d %d\n", f[i]...
6
#include <bits/stdc++.h> using namespace std; const int N = 2505; int n, a[N][N]; struct node { int x, y, v; node() {} node(int _x, int _y, int _v) : x(_x), y(_y), v(_v) {} bool operator<(const node k) const { return v < k.v; } }; vector<node> p; bitset<N> r[N], c[N], t; int main() { scanf("%d", &n); for (i...
8
#include <bits/stdc++.h> using namespace std; bitset<16 * 2002> dp[1 << 16]; int n, k; int a[16]; int weight[16]; int calc(int &x) { int c = 0; while (x % k == 0) x /= k, c++; return c; } int _calc(int x) { int c = 0; while (x % k == 0) x /= k, c++; return c; } void dfs(int s, int x) { if (__builtin_popco...
11
#include <bits/stdc++.h> using namespace std; int get() { char ch; while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-') ; if (ch == '-') { int s = 0; while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0'; return -s; } int s = ch - '0'; while (ch = getchar(), ch >= '0' &...
11
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e4 + 10; char a[N]; int nxt[N]; void kmp(char* a, int n) { int i, j; for (nxt[0] = j = -1, i = 1; i < n; nxt[i++] = j) { while (~j && a...
8
#include <bits/stdc++.h> using namespace std; const int Mn = 2 * 100000 + 10; const int Me = 2 * Mn + 10; int hd[Mn], nxt[Me], to[Me], cnt; int hd1[Mn], nxt1[Me], to1[Me], cnt1; int n, m; int st, ed; int S, T, len; int dfn[Mn], low[Mn], ecomp[Mn], vcomp[Me]; int ecompnum, vcompnum, num; int par[Mn], incycle[Mn], path[M...
11
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5, Mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, m; cin >> n >> m; long long ans = 0; if (n == 2 || m == 2) { if (m == 2) swap(n, m); cout << 2 * (2 * (m / 4)...
5
#include <bits/stdc++.h> using namespace std; static const int maxn = 200000 + 5; char s[maxn]; int Z[maxn]; void Z_ALGO() { int len = strlen(s); Z[0] = len; int lt = 0, rt = 0; for (int k = 1; k < len; k++) { if (k > rt) { int n = 0; while (n + k < len && s[n] == s[n + k]) n++; Z[k] = n; ...
6
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e12; const long long int mod = 1e9 + 7; vector<long long int> adj[100003]; long long int vis[100003]; void dfs(long long int n) { vis[n] = 1; for (long long int child : adj[n]) { if (vis[child] == 0) { dfs(child); } } } void so...
4
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<vector<long long>> board(n + 1, vector<long long>(n + 1)); vector<vector<bool>> board2(n + 1, vector<bool>(n + 1)); for (int i = 2 * n; i >= 2; i--) { bool tmp = true; for (int j = max(1, i - n); j <= min(n, i - 1);...
6
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; const int N = 1e4 + 100; int cnt = 0, tot, n; int head[N], to[N], nt[N], link[N]; bool vis[N]; v...
8
#include <bits/stdc++.h> using namespace std; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } using ll = long long; using pii = pair<ll, ll>; using ld = long double; template <typename T> void do_uniq(vector<T> &vec) { sort((v...
7
#include <bits/stdc++.h> using namespace std; string ch[10] = {"", "", "2", "3", "223", "5", "53", "7", "7222", "7332"}, str, an; int n; int main() { cin >> n; cin >> str; for (int i = 0; i < (str.size()); i++) an += ch[str[i] - '0']; sort((an).begin(), (an).end()); reverse((an).begin(), (an).end()); ...
3
#include <bits/stdc++.h> using namespace std; int n; long long k; struct Tp { long long x; int i; } a[111111]; bool ByX(Tp A, Tp B) { return A.x < B.x || A.x == B.x && A.i < B.i; } bool ByI(Tp A, Tp B) { return A.i < B.i; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i].x; a[i].i ...
5
#include <bits/stdc++.h> using namespace std; int abs(int a) { return a < 0 ? -1 * a : a; } void solve() { int n, m, bx, by; cin >> n >> bx; int x[n]; for (int i = 0; i < n; i++) cin >> x[i]; cin >> m >> by; int y[m]; for (int i = 0; i < m; i++) cin >> y[i]; long long X = 0, Y = 0; for (int i = n - 1;...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline void rread(T& num) { num = 0; T f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar(); num *= f; } const in...
4
#include <bits/stdc++.h> using namespace std; const long long N = 2e7 + 5; long long mind(long long x, long long y) { if (x > y) { return y; } else { return x; } } long long poww(long long a, long long b) { if (b < 0 || a <= 0) return 0; long long ans = 1LL; while (b) { if (b & 1) ans = ans * a;...
3
#include <bits/stdc++.h> using namespace std; long long int N, MAX = INT_MIN, MIN = INT_MAX, sayi, a, b, f; void read() { cin >> N; for (int i = 1; i <= N; i++) { cin >> f; if (f > MAX) MAX = f, a = 1; else if (f == MAX) a++; if (f < MIN) MIN = f, b = 1; else if (f == MIN) ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, j; cin >> n; int arr[n + 1]; vector<int> ans(n + 10, 0), tmp(n + 10, 0); for (i = 1; i <= n; i++) cin >> arr[i]; for (i = 1; i <= n; i++) { ans[arr[i]] = max(ans[arr[i]], i - tmp[arr[i...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e9; int main() { string a, b; cin >> a >> b; int k1 = a.size(), k2 = b.size(), ans; ans = k1 + k2; k1--, k2--; for (int i = 0; i <= min(k1, k2); i++) { if (a[k1 - i] == b[k2 - i]) ans -= 2; else break; } cout << ans << e...
0
#include <bits/stdc++.h> using namespace std; const long long int M = 1e9 + 7; const long long int N = 2e5; long long int power(long long int x, long long int y, long long int M = ::M) { x %= M; long long int ans = 1; while (y) { if (y & 1) ans = (ans * x) % M; y >>= 1LL; x = (x * x) % M; } return...
4
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 10; const long long M = 2111; const long long MX = 1e6 + 55; const long long INF = 1e18; const long long inf = -1e18; const long long MOD = 1e9 + 7; const long long xesh = 31; long long n, m, k, ans, v[N], cnt[N]; pair<long long, long long> a[N]; i...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, i, a[5]; cin >> n; for (i = 0; i < 5; i++) { a[i] = n % 10; n /= 10; } n = a[3] + 10 * a[1] + 100 * a[0] + 1000 * a[2] + 10000 * a[4]; m = n; m = n * n; m %= 100000...
3
#include <bits/stdc++.h> double a[1001], b[1001]; double max(double x, double y) { return x < y ? y : x; } int main() { int n, r; scanf("%d %d", &n, &r); for (int i = 0; i < n; i++) scanf("%lf", &a[i]); for (int i = 0; i < n; i++) { double center = r; for (int j = 0; j < i; j++) { center = ...
3
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(nam...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; int val[MAXN], q[MAXN]; int N, T; int Stack[MAXN], top; int main() { while (scanf("%d", &N) != EOF) { for (int i = 1; i <= N; i++) scanf("%d", &val[i]); memset(Stack, 0, sizeof(Stack)); top = 0; scanf("%d", &T); for (int i = 1...
6
#include <bits/stdc++.h> using namespace std; vector<long long> Peaks_count(81), a_to_first(81), a_to_last(81), b_to_first(81), b_to_last(81); void Init(long long x, int n, vector<long long> &first, vector<long long> &last) { if (n == 0) { first[0] = 0; last[0] = 0; return; } if (n == 1)...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, INF = 1e9; pair<int, int> t[N * 4]; int t_2[N * 4], a[N]; void build(int v, int l, int r) { if (l == r) { t[v] = make_pair(a[l], l); t_2[v] = 1; } else { int m = (l + r) / 2; build(v * 2, l, m); build(v * 2 + 1, m + 1, r); ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(), i = 0; if (s[0] == '9') { i++; } while (i < n) { if (s[i] >= '5') { s[i] = '9' - s[i] + '0'; } i++; } cout << s; return 0; }
2
#include <bits/stdc++.h> using namespace std; inline int read() { static int r; static char c; r = 0, c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') r = r * 10 + (c - '0'), c = getchar(); return r; } template <typename T> inline void print(T *a, int n) { for (int i =...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1007; int n, m; int c[MAX_N][MAX_N]; long long sx[MAX_N], sy[MAX_N]; long long cal(int i, int j) { if (i < j) return (j - i) * 4 - 2; return (i - j) * 4 + 2; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { for (int j = 1; j...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:60000000") 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 = 3.1415926535897932384626433832795; const string task = ""; template <class T> T sqr(T x) { retu...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vb = vector<bool>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vd = vector<double>...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; set<string> A, B; vector<string> C(max(n, m)); string tt; for (int i = 0; i < n; i++) cin >> tt, A.emplace(tt); for (int i = 0; i < m; i++) cin >> tt, B.emplace(tt); auto it = set_intersection(A.begin(), A.end(), B.begin...
1
#include <bits/stdc++.h> using namespace std; bool mark[100000000]; set<int> ooxx; int main() { int n, limit; int s; scanf("%d %d", &n, &limit); bool flag = false; for (int i = 0; i < n; i++) { scanf("%d", &s); ooxx.insert(s); if (s == 1) flag = true; } if (limit == 2) { printf("0\n"); ...
8
#include <bits/stdc++.h> using namespace std; int arr[2 * 100005]; int main() { vector<int> ans; int n, i, num; double ave = 0; cin >> n; for (i = 0; i < n; i++) cin >> num, ave += num, arr[i] = num; ave /= (double)n; for (i = 0; i < n; i++) if (arr[i] == ave) ans.push_back(i + 1); cout << ans.size(...
2
#include <bits/stdc++.h> using namespace std; void testCase() { long long n; cin >> n; vector<string> grid(n); vector<pair<long long, long long>> ans; for (string &s : grid) cin >> s; if (grid[0][1] == grid[1][0]) { if (grid[n - 1][n - 2] == grid[0][1]) ans.push_back({n - 1, n - 2}); if (grid[n - 2]...
1
#include <bits/stdc++.h> using namespace std; int main() { int num, k; cin >> num >> k; int arr[num + 1]; arr[0] = 1; for (int i = 1; i <= num; i++) cin >> arr[i]; sort(arr, arr + num + 1); if (arr[k] == arr[k + 1]) cout << "-1" << endl; else cout << arr[k] << endl; }
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; const int MOD = 998244353; long long modpow(long long x, long long p) { if (p == 0) return 1; if (p % 2 == 1) return x * modpow(x, p - 1) % MOD; long long r = modpow(x, p / 2); return r * r % MOD; } long long modinv(long long x) { return modpow(...
9
#include <bits/stdc++.h> using namespace std; int d[4005][4005]; int x[4005], y[4005]; int deg[4005]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= m; ++i) { scanf("%d %d", &x[i], &y[i]); d[x[i]][y[i]] = 1; d[y[i]][x[i]] = 1; ++deg[x[i]]; ++deg[y[i]]; } int ans = 1000...
3
#include <bits/stdc++.h> using namespace std; long long n, m, v; int main() { cin >> n >> m; if (n < m * 2) cout << 0; else cout << n - (2 * m); cout << " "; for (long long i = 0; i <= n; i++) if (i * (i - 1) / 2 >= m) { v = i; break; } cout << n - v << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; string s; cin >> s; long long cnt = 0, sum = 0; vector<long long> v; long long f = 0; char c = '?'; for (long long i = 0; i < s.length(); i++) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int k, d, i, j; cin >> k >> d; if (d != 0) { for (i = 1; i <= k; i++) { if (i == 1) cout << d; else cout << 0; } } if (d == 0) { if (k == 1) cout << 0; else cout << "No solution"; } }
1
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for...
3
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
3