solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k, ans = 0, cnt = 0; cin >> n >> k; string s; cin >> s; char a[k]; for (int i = 0; i < k; i++) { cin >> a[i]; } bool flag; for (int i = 0; i < n; i++) { flag = false; for (int j = 0; j < k; j++) { if (s[i] ...
4
#include <bits/stdc++.h> using namespace std; long long maxm = -1e18; long long minm = 1e18; const long double Pi = 3.141592653; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n]; string k = ""; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0 ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s = ""; int i, a, b, x, y; cin >> a >> b >> x; y = x; if (y % 2 == 0) { y = (y / 2); } else { y = (y / 2) + 1; } for (i = 0; i < y; i++) { s = s + "10"; a--; b--; } if (x % 2 == 0) { if ((a != 0) && (b != 0)) {...
5
#include <bits/stdc++.h> const int N = 1e5 + 1; int i, j, n, m, q, t, d[N], lg[N], fa[N], en[N * 2], nxt[N * 2], ft[N][17]; std::priority_queue<int> b, s, f[N][17]; void Mer(std::priority_queue<int>& a, std::priority_queue<int>& x) { for (b = x; !b.empty(); a.size() > t ? a.pop() : void(0)) a.push(b.top()), b.pop...
14
#include <bits/stdc++.h> using namespace std; const int N = 100 + 7; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n / 2; ++i) scanf("%d", &a[i]); sort(a + 1, a + n / 2 + 1); int res = 1e9, sum = 0; for (int i = 1; i <= n / 2; ++i) sum += abs(i * 2 - 1 - a[i]); res = min(res, sum); ...
3
#include <bits/stdc++.h> using namespace std; template <class T> void vp(T &a, int p) { for (int i = 0; i < p; i++) cout << a[i] << " "; cout << endl; } const long long mod = 1000000007; const int N = 16; bool tc[N][N]; const string noans = "The times have changed"; void wf(int n) { for (int i = 0; i < n; i++) ...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 10e5 + 10; int n, sx[maxn], sy[maxn]; vector<int> x, y; int main() { while (~scanf("%d", &n)) { x.clear(); y.clear(); for (int i = 0; i < n; i++) { int t, w; scanf("%d%d", &t, &w); if (t == 1) { x.push_back(w); ...
9
#include <bits/stdc++.h> int a[505][505]; int main() { int x, y, x0, y0, test; char c; while (scanf("%d %d %d %d", &x, &y, &x0, &y0) != EOF) { memset(a, 0, sizeof(a)); getchar(); a[x0][y0] = 1; test = x * y; int move = 1; int again = 0; while ((c = getchar()) != '\n') { if (move ...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:10000000000") using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> ostream& operator<<(ostream& o, vector<T> x) { for (auto it : x) o << it << ' '; return o; } template <typename T> istream& ...
3
#include <bits/stdc++.h> using namespace std; int S, a, b, c; int main() { while (scanf("%d", &S) != EOF) { scanf("%d%d%d", &a, &b, &c); int sum = a + b + c; if (sum == 0) printf("%d 0.0 0.0\n", S); else printf("%.10f %.10f %.10f\n", (S * a * 1.0) / sum, (S * b * 1.0) / sum, (...
10
#include <bits/stdc++.h> using namespace std; int p[1005][1005]; long long hor[1005][1005]; long long vol[1005][1005]; long long dr[1005][1005]; long long dl[1005][1005]; long long v[1005][1005][5]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> p[...
17
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-9; int n, a[2015]; int pre1[2015], suf2[2015], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) { ...
10
#include <bits/stdc++.h> using namespace std; int N; vector<int> rt[8080]; vector<int> rrt[8080]; string s(int a) { if (a & 2) { return "row " + to_string(a / 4) + "=" + to_string(a & 1); } else { return "col " + to_string(a / 4) + "=" + to_string(a & 1); } } void mrt(int a, int b) { rt[a].push_back(b);...
13
/* 构造一个正交化的线性基 实现完全正交 is impossible; 退而求之局部正交,即crucial musk不能出现在其他向量中 竟然要用并查集我日你先人( */ #include<bits/stdc++.h> #define ll long long using namespace std; #define pb push_back const int ha = 1e9+7; inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;} inline void ADD(int &x,int y){ x+=y; if(...
13
#include <bits/stdc++.h> using namespace std; const int N = (int)200 + 7; int d[N]; int d_in[N], d_out[N]; multiset<int> g[N]; vector<pair<int, int> > go; void dfs(int v) { while (g[v].size() > 0) { int to = *g[v].begin(); go.push_back({v, to}); g[to].erase(g[to].find(v)); g[v].erase(g[v].begin()); ...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10, mod = 1e9 + 7; int q, cnt, f[N], t, k; long long dp[N][N][2], x1, x2; char c[N]; long long dfs(int pos, int dis, bool lim, bool ok) { if (!pos) return ok; if (!lim and ~dp[pos][dis][ok]) return dp[pos][dis][ok]; long long ans = 0; for (regist...
17
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const char E = '\n'; const int N = 500051; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; int a[N] = {0}; long long s = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; s += a[i]; } s...
7
#include <bits/stdc++.h> using namespace std; long long N, X, Y, C; long long D[5]; void read(void); void soups_on(void); long long yee_haw(long long); int main() { read(), soups_on(); return 0; } void read(void) { cin >> N >> X >> Y >> C, --X, --Y; } void soups_on(void) { long long low = 0, up = 0, mid; D[0] =...
10
#include <bits/stdc++.h> using namespace std; int toInt(string X) { int val; istringstream ss(X); ss >> val; return val; } int diff(string A, string B) { return abs(toInt(A) - toInt(B)); } int main() { int n, k; cin >> n >> k; vector<string> numbers(n); string num; for (int i = (0); i < (n); ++i) cin ...
6
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int mod = 1e9 + 7; using namespace std; vector<int> g[maxn]; int dist[maxn]; int n, x, not_ok, max_d; void dfs(int last_v, int curr_v, int _d) { dist[curr_v] = _d; for (auto _x : g[curr...
9
#include <bits/stdc++.h> using namespace std; long long n, x[100009], y[100009], j = 0, t1 = 0, t2 = 0; string second, s1, s2; bool isnum(string a) { if (a[0] == '0' && a.length() > 1) return 0; if (a.length() == 0) return 0; for (int(i) = 0; i < (a.length()); i++) { if (!(a[i] >= 48 && a[i] < 58)) return 0; ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long a, i, j, ans = 0, n, arr[4100], find[50000] = {}, sum = 0; string s; cin >> a >> s; n = s.size(); for (i = 0; i < n; i++) arr[i] = s[i] - '0'; for (i = 0; i < n; i++) { sum = 0; for (j = i; j < n; j++) { sum += arr[j]; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; deque<long long int> q; long long int id[n]; int cnt = 0; for (int i = 0; i < n; i++) { cin >> id[i]; } map<long long int, bool> mp; for (int i = 0; i < n; i++) { if (cnt == k) { break; } if (mp[i...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, a; cin >> n; int pos1[n + 2], pos2[n + 2]; for (int i = 0; i < n; i++) { cin >> a; pos1[a] = i; } for (int i = 0; i < n; i++) { cin >> a; pos2[a] = i; } int mx = 0, cnt; unordered...
6
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-7; const long double PI = 3.141592653589793; int main() { ios_base::sync_with_stdio(0); int n, m, a, b; cin >> n >> m >> a >> b; int aa = n * a; int bb = (n / m) * b + (n % m) * a; int cc = (n / m) * b + b; cout << (((aa) < ((((bb) <...
4
#include <bits/stdc++.h> int main() { int n, i, cnt = 0; scanf("%d", &n); for (i = 1; i <= n / 2; i++) { if (!((n - i) % i)) cnt++; } printf("%d", cnt); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1000 * 1000 * 1000 + 7; long long n, k, a, b, q, type, d, x, p, arr[200005], arrb[200005], tree[200005], treeb[200005], upd, updb; void update(int x, long long val) { while (x < 2...
9
// Created by Kshitij Anand NSIT #include <bits/stdc++.h> //#include <ext/numeric> //using namespace __gnu_cxx; using namespace std; #define int long long #define pb push_back #define P pair<int,int> #define F first #define S second #define vi vector<int> #define vc vector<char> #define vb vector<bool> #define vp v...
6
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long power(long long x, unsigned long long y) { long long res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } long long powermod(long long x, unsigned long long y, long...
11
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > G[100006]; bool visited[100006]; int parent[100006]; long long int n, m, p, q; vector<pair<long long int, long long int> > ans; long long int dfs(long long int u) { long long int sum = 0; visited[u] = true; for (long long in...
13
#include <bits/stdc++.h> using namespace std; inline int input() { int n; cin >> n; return n; } long long pw(long long a, long long b) { return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2))); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n, k; cin >> n >> k...
1
#include <cstdio> #include <cstring> #include <algorithm> #include <set> const int N = 300005; int t, n, a[N], b[N], fa[N]; int dfn[N], rks[N], siz[N], tt; struct Edge { int to, nxt; }E[N]; int head[N], tot; inline void add(int f, int t) { E[++tot] = (Edge){t, head[f]}, head[f] = tot; return; } void dfs1(int x) { r...
15
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 42, LIM = 130, inf = 1e9; int n; long long inp[nmax]; vector<int> seen[61], adj[nmax]; queue<pair<int, int> > q, idle; vector<pair<int, int> > edges; int dist[nmax]; bool eq(int a, int b, pair<int, int> c) { if (c == make_pair(a, b)) return 1; if ...
11
#include <bits/stdc++.h> using namespace std; void task(); int main() { srand(time(0)); ios_base::sync_with_stdio(0); task(); return 0; } const int INF = 0x3f3f3f3f; const int N = 1e6 + 10; const int M = 1e5 + 10; struct SufAutomaton { struct State { int len; int link; int cnt; unordered_map<c...
19
#include <bits/stdc++.h> using namespace std; const long long N = 100005; map<long long, long long> colors[N]; map<pair<long long, long long>, long long> done; long long par[N]; inline long long get(long long x) { return ((par[x] == x) ? (x) : (par[x] = get(par[x]))); } inline void unite(long long v, long long u) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { int k, b, n, t; cin >> k >> b >> n >> t; long long z = 1, ans = 0; while (z <= t) z = k * z + b, ++ans; cout << max(n - ans + 1, 0LL) << endl; return 0; }
9
#include <bits/stdc++.h> using namespace std; struct node { int hm, gs, zh; } a[101]; bool cmp(node aa, node bb) { if (aa.gs > bb.gs) return 1; if (aa.gs == bb.gs && aa.zh < bb.zh) return 1; return 0; } int main() { int n, k, m, aa; scanf("%d %d %d %d", &n, &k, &m, &aa); for (int i = 1; i <= n; i++) { ...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using ui = unsigned int; const ll amn = 2e5 + 5, mod = 1e9 + 7, an = 5e3 + 5; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll n, m; ll a[amn], b[amn]; map<ll, ll> mp; int main() { ll T = 1, cas = 1; while (T--) { cin ...
6
#include <bits/stdc++.h> using namespace std; int n; long long a[(100002)]; long long dp[(100002)][2]; long long sol(int i, bool t) { if (i == ((100002) - 1)) return 0; long long &tt = dp[i][t]; if (tt != -1) return tt; long long c1, c2 = 0; c1 = sol(i + 1, 0); if (t == 0) c2 = a[i] + sol(i + 1, 1); retur...
7
#include <bits/stdc++.h> using namespace std; int n, m; char grid[105][105]; int main() { bool x; string t; cin >> n >> m; for (int i = 0; i < n; i++) { if (i % 2 != 0) { x = false; } else { x = true; } cin >> t; for (int j = 0; j < m; j++) { if (t[j] == '.' && x == true) {...
4
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return (a >= b) ? b : a; } long long int max(long long int a, long long int b) { return (a <= b) ? b : a; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int tc; cin >> tc; while (...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; const int N = 500005; struct edge { int u, v, w, num; } e[N], c[N]; map<long long, int> mp; int n, m, q, s, sz[N], fa[N]; long long L[N], R[N]; bool vis[N]; int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; } bool comp(edge x, edge y) { return x.w < y.w; } int mai...
15
// HJB // PME #include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i, a, b) for(int i = a; i <= b; i++) #define FOD(i, a, b) for(int i = a; i >= b; i--) #define II pair <int, int> #define fi first #define se second const int N = 505; const int MOD = 998244353; void add(int &a, int b) { a...
14
#include <bits/stdc++.h> int main() { unsigned long long n; scanf("%I64u", &n); printf("%I64u\n", n / 2520); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n, p, q, ans, i, j; string str; while (scanf("%d%d%d\n", &n, &p, &q) != EOF) { int a = -1, b = -1; cin >> str; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { ans = i * p + j * q; if (ans == n) { a = i...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); vector<pair<long long, int> > seats; priority_queue<pair<long long, int> > extro; int n; cin >> n; for (int i = 0; i < n; i++) { long long w; cin >> w; seats.push_back(make_pair(w, i)); } sort(seats....
5
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 20; vector<int> adj[maxn], ver[maxn]; vector<pair<int, int> > mh[maxn]; int a[maxn], b[maxn]; int LazyAdd[maxn * 4], mn[maxn * 4]; void handle(int v) { sort(mh[v].begin(), mh[v].end()); while ((int)mh[v].size() > 2) mh[v].pop_back(); } void dfs(in...
22
#include <bits/stdc++.h> using namespace std; int n, m, k, u, v, y, w[200020], d[200020], f[200020][18], s[200020], L[200020], R[200020], ss; vector<int> a[200020]; int lca(int x, int y) { if (d[x] > d[y]) swap(x, y); for (int k = d[y] - d[x], i = 18; i--;) if (k >> i & 1) y = f[y][i]; if (x == y) return ...
21
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int q, n; scanf("%d", &q); while (q--) { scanf("%d", &n); if (n == 2 || (n % 2 != 0 && n <= 11 && n != 9)) printf("-1\n"); else { int ans = 0; if (n % 2) { n -= 9; ans++; } ans += n ...
5
#include <bits/stdc++.h> using namespace std; long long n, p; struct Cons { long long a; long long b; }; Cons cons[100010]; long long tot_p; long long tot_l; long long max_p; bool cmp(const Cons& x, const Cons& y) { return ((double)x.b / x.a) < ((double)y.b / y.a); } int main() { ios::sync_with_stdio(false); ...
10
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } struct custom...
4
#include<bits/stdc++.h> #define ll long long const int N = 1010; const ll mod = 998244353; char x[N],y[N]; int n,m; ll dp[N][N][2],ans; int main(){ scanf(" %s",x+1); scanf(" %s",y+1); n = strlen(x+1); m = strlen(y+1); for(int i = 0 ; i <= n ; ++i){ for(int j = 0 ; j <= m ;++j){ if(i>=1) dp[i][j][0]+=1; if(...
16
#include <bits/stdc++.h> using namespace std; int a, s, d[200004], f, g, h, j, k, l, i, n, m; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> d[i]; if (d[i] == -1) k++; else l++; } for (i = 0; i < m; i++) { cin >> a >> s; if ((s - a + 1) % 2 == 0 && k >= (s - a + 1) ...
0
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const int INF = (int)1e9; class Segmen...
20
#include <bits/stdc++.h> using namespace std; long long a[101000]; int n; bool cmp(long long a, long long b) { return a < b; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, cmp); int flag = true; for (int i = 0; i < n - 1; i++) if (a[i] != a[i + 1] && a[i + 1] < ...
6
#include <bits/stdc++.h> using namespace std; set<int> s; int pre[2000000 + 5] = {0}; vector<int> a; int main() { int ans = 0, n, p; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &p); if (s.find(p) == s.end()) a.push_back(p); s.insert(p); } a.push_back(2000000 + 5 - 1); sort((a).beg...
13
#include <bits/stdc++.h> using namespace std; void solve() { vector<string> v, v1; vector<long long> v2; string s; long long n, m, i = -1, j = 0; cin >> n >> m; for (long long x = 0; x < n; x++) { cin >> s; v.push_back(s); } for (long long x = 0; x < n; x++) { for (long long y = 0; y < m; y+...
0
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; namespace ywy { int ch[2111][2], fa[2111], gpt = 1, size[2111]; unsigned char bv[2111]; int tot = 0, zx; void afs(int pt) { if (bv[pt] || !pt) return; if (!ch[pt][0] && !ch[pt][1]) { tot++...
24
#include <bits/stdc++.h> using namespace std; long long n; priority_queue<pair<long long, pair<long long, long long>>> q; long long x = 0, y = 0; int main() { cin >> n; q.push({n, {0, 0}}); while (q.size() > 0) { long long e = q.top().first; long long d = q.top().second.first; long long l = q.top().se...
14
#include <bits/stdc++.h> using namespace std; int element[200010], marker[200010]; int main() { int n, t, k, a, x, maxval = 1, cut = 0; double sum = 0; cin >> n; while (n--) { cin >> t; if (t == 1) { cin >> a >> x; marker[a] += x; sum += a * x; } else if (t == 2) { cin >> k; ...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, l, r, Ql, Qr; cin >> n >> l >> r >> Ql >> Qr; vector<int> W(n); for (int &w : W) cin >> w; int leftsum = 0, rightsum = 0; for (int w : W)...
7
#include <bits/stdc++.h> const int MOD = 1000000007; using namespace std; string second[10]; int m[9][8]; int main() { for (int i = 0; i < 8; i++) getline(cin, second[i]); for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) if (second[i][j] == 'S') m[i][j] = -1; int k = 1; m[7][0] = k; for (int ...
7
#include <bits/stdc++.h> using namespace std; long long ful = 0; vector<pair<int, int> > v; long long ans = 111111111111; int l[111111]; int c[111111]; int n; int d[111111]; int max(int x, int y) { if (x < y) return y; return x; } int min(int x, int y) { if (x > y) return y; return x; } int main() { cin >> n;...
11
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int N = 105; const int mod = 998244353; char s[N]; int d[N], n; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } map<pair<int, int>, long long> dp[2][2][11][11]; int tot1[15], tot2[15]; template <typename T> void add(T &a, T b) { a += ...
19
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const double eps = 1e-9, Pi = 2 * acos(0.0); int main() { string s; cin >> s; vector<string> t; string cur = ""; for (int i = 0; i < s.length(); i++) if (s[i] == '.') t.push_back(cur), cur = ""; else cur += s[i]; t...
6
#include <bits/stdc++.h> using namespace std; int n, c, ans; int jc[710000]; int qpow(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = (long long)ret * x % 1000003; x = (long long)x * x % 1000003; y >>= 1; } return ret; } int main() { scanf("%d%d", &n, &c); jc[0] = 1; for (int i = 1; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 2, ctr = 0; string s, str; cin >> n; cin >> s; while (c <= n) { for (int i = 0; (i + c <= n) && i < (n - 1); i++) { str = s.substr(i, c); if (count(str.begin(), str.end(), 'R') == count(str.begin(), str.end(), ...
2
#include <bits/stdc++.h> int read() { register int x = 0; register char f = 1, ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0'); return f ? x : -x; } int n, m; char a[2005][2005], b[2005][2005], c[2005], tm...
13
#include <bits/stdc++.h> using namespace std; vector<bool> prime(1000000, 1); long long M = 1e9 + 7; long long powmodM(long long a, long long b, long long c = M) { long long res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b /= 2; } return res; } long long power(long long a, lon...
10
#include <bits/stdc++.h> using namespace std; int main() { int t, s, x; while (~scanf("%d%d%d", &t, &s, &x)) { if (x < t) { printf("NO\n"); continue; } if (x == t) { printf("YES\n"); continue; } if ((x - 1 - t) != 0 && (x - 1 - t) % s == 0) { printf("YES\n"); } ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); int alice[n], bob[m], i, j; for (i = 0; i < n; i++) { scanf("%d", &alice[i]); } for (i = 0; i < m; i++) { scanf("%d", &bob[i]); } i = n - 1; j = m - 1; bool flag = false; sort(alice, alice ...
8
#include <bits/stdc++.h> using namespace std; int in[1000100]; int n; int il[1000100]; long long re[1000100]; long long pre[1001000]; void test() { long long b; scanf("%lld", &b); int ans = 1000000000; long long sum = 0; int w2 = n - 1; il[n] = 0; re[n] = 0; for (int i = n - 1; i >= 0; i--) { sum +=...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct edge { int v; int Next; } Edge[maxn * 10]; int tot = 0; int head[maxn]; int ind[maxn]; int ans[maxn]; void init() { memset(head, -1, sizeof(head)); tot = 0; } void addedge(int u, int v) { Edge[tot].v = v; Edge[tot].Next = head[u...
15
#include <bits/stdc++.h> using namespace std; int n, i, f; string s; int main() { cin >> n >> s; for (; i < n - 1; i++) s[i] <= s[i + 1] || f ? cout << s[i], 0 : f = 1; if (f) cout << s[i]; }
4
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 10, LG = 15, inf = 1e9, Sink = 1, Source = 2; vector<pair<int, int> > v[maxn], g[maxn], cut; vector<int> idv[maxn], ans1, ans2; int refind[maxn]; int sp[LG][maxn], id[LG][maxn], C = 5; int arr[maxn], h[maxn], pt[maxn]; void add_edge(int a, int b, int ...
24
#include <bits/stdc++.h> using namespace std; template <typename T> void Chkmax(T &a, T b) { a = a > b ? a : b; } template <typename T> void Chkmin(T &a, T b) { a = a < b ? a : b; } template <typename T> void read(T &x) { int f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == ...
8
#include <bits/stdc++.h> using namespace std; inline int rd() { register int x = 0; register char c = getchar(); register bool f = false; while (!isdigit(c)) { f = (c == '-'), c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 48, c = getchar(); } return f ? -x : x; } int n, m, b, mod; int a...
10
#include <bits/stdc++.h> using namespace std; const int MAX = 500010; const int MOD = 998244353; const int G = 3; long long modpow(long long base, long long exp) { base %= MOD; long long result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % MOD; base = (base * base) % MOD; exp >>= 1; ...
18
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 20; long long n, k, x, y, x2, y2; pair<long long, long long> l[N], r[N], high[N], low[N]; bool mark[N]; long long solve(long long _k, long long p1, long long p2, long long p3, long long p4) { long long res = 0; while (mark[l[p1].secon...
15
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T, typename TT> inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { return os << t.first << " " << t.second; } template <typename T> inline ostream &operator<<(ostream &os, const vector<T> &t) { for (auto i : ...
14
#include <bits/stdc++.h> using namespace std; int n, a, want = 1; vector<int> ans; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a == want) { want++; ans.push_back(2001 + i); } } cout << want - 1 << '\n'; for (int num : ans) cout << num << ' '; }
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n][n]; 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++) { for (int j = 0; j < n; j++) { int f = 0; if (a[i][j] != 1) { f = 1; for (int ...
0
#include <bits/stdc++.h> using namespace std; int a[int(3e5 + 10)], team[int(3e5 + 10)][3]; bool b[int(3e5 + 10)]; int main() { int n; scanf("%d ", &n); for (int i = 0; i < 3 * n; i++) { int num; scanf("%d ", &num); a[num] = i; } for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) scanf("%...
12
#include <bits/stdc++.h> using namespace std; pair<int, int> tree[524288 * 2]; pair<int, int> lazy[524288 * 2]; pair<int, int> min(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return a; if ((a.first == b.first) && (a.second < b.second)) return a; return b; } void lazyShiftMax(long long node, long ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const long long inf = 2147483647; int n, m, k; long long ans, x, y, tmp, cnt; struct node { long long xl, yl, xr, yr; } a[maxn], aa, l[maxn], r[maxn]; bool jud(node aa) { if (aa.xl > aa.xr) return 0; if (aa.yl > aa.yr) return 0; else ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); pair<double, double> ara[n]; for (int i = 0; i < n; i++) { scanf("%lf %lf", &ara[i].first, &ara[i].second); } double mini = 100000000000009.0; for (int i = 0; i < n; i++) { int a = (i - 1 + n) % n; int b = (i + ...
10
#include <bits/stdc++.h> using namespace std; int main () { int q; cin >> q; while (q--) { long long a , b , aa , bb , x , y , ans = 0; cin >> a >> b; cin >> aa >> bb; cin >> x >> y; if ( bb == b ) { if ( (aa > x && x > a || aa < x && x < a ) && y == b) { ans = abs(aa-a) + 2; } else ans = abs...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long p, q; cin >> p >> q; if (p % q != 0) { cout << p << "\n"; } else { set<long long> ans; long long temp2 = q; for (int i = 2; i ...
7
#include <bits/stdc++.h> const int INF = 1000 * 1000 * 1000; using namespace std; int n, m; int imp[5005]; int nxt[5005]; vector<vector<int> > g(5005); int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; if (n == 1) { long long a; cin >> a; cout << min(a, k * m) << endl; return 0; } long long lowest_odd = 1e9; if (n % 2ll == 0) { cout << 0 << endl; return 0; } long long sum_odd = 0; ...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; const int MAXM = 1010; int n, m; int H[MAXN], E[MAXM], X[MAXM], B[MAXM], co = 0; inline void add(int x, int y) { E[++co] = y, B[co] = x, X[co] = H[x], H[x] = co; } bool del[MAXM], v[MAXN]; int lk[MAXN]; bool find(int x) { for (int p = H[x]; p; p = ...
14
#include <bits/stdc++.h> using namespace std; int n, s; int v[200010]; int f[200010]; int nxt[200010]; int getNxt(int cpoz, int spec) { int ans = nxt[cpoz]; if (spec <= cpoz && spec > ans) ans = spec; return ans; } int solve(int val) { int csum = s; int prv = s + 1; while (csum > 0) { int cr = getNxt(mi...
18
#include <bits/stdc++.h> using namespace std; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, 1, 0, -1}; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long expo(long long n, long long m, long long p) { long long r = 1; n = n % p; while (m > 0) {...
6
#include <bits/stdc++.h> void solve(const int n, const int m, const int cl, const int ce, const int v, const int *ll, const int *e) { int x, y, p, q; scanf("%d%d%d%d", &x, &y, &p, &q); if (x == p) { printf("%d\n", ((y - q) > (0) ? (y - q) : -(y - q))); return; } if (y > q) { int swap = ...
8
#include <bits/stdc++.h> using namespace std; long long fact[1000007] = {0}; long long spf[(long long)(1e6)]; bool prime[(long long)((1e7) + 20)]; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } void sp(long long n) { spf[1] = 1; for (long long i = 2; i < n; i++) spf[i] =...
7
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c *x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct deb { template <class c> deb &operator<<(const c &) {...
3
/** * 𝕬𝖚𝖙𝖍𝖔𝖗: 𝕽𝖊𝖉 𝕯𝖗𝖆𝖌𝖔𝖓 **/ #include <bits/stdc++.h> using namespace std; #define Fast_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr...
6
#include <bits/stdc++.h> using namespace std; long long n, m, t, x, y, c, d, a[5001], res[5001], cnt[5001]; bool f; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < n; ++i) { for (long long j =...
7
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int n, m; char s[5005][5005]; int dp[5005][5005]; int h[5005]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", s[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (s[i][j] == '1') { i...
8