solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; char a[200010], b[200010]; int l[200010], r[200010]; int main() { scanf("%s%s", a, b); int la = strlen(a), lb = strlen(b); int ta = 0, tb = 0; while (tb != lb) { if (a[ta] == b[tb]) l[tb++] = ta; ta++; } ta = la - 1, tb = lb - 1; while (tb != -1) { ...
8
#include <bits/stdc++.h> using namespace std; int h, q; map<int, double> fuck; char str[100]; int x; double y, ans; double query(int id, int x, double Max) { if (fuck[id] < 1e-20) return 0.0; if (x == h) return fuck[id]; if (fuck[id] <= Max) return Max; double tmp = 0.0; if (max(Max, fuck[id] - fuck[id * 2]) ...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n; vector<pair<int, int> > all; for (int i = 0; i < n; i++) { scanf("%d%d", &b, &a); all.push_back(make_pair(a, b)); } sort(all.begin(), all.end()); int last = 0, res = 0; for (int i = 0; i < n; i++) { if (all[i]....
8
#include <bits/stdc++.h> using namespace std; int xr = 1124971; inline int R() { xr = (1ll * (xr ^ 1297131) * 182791 + 12987941) % 1000000007; return xr; } int n, m, Q, K, tot = 0, S, T, a[1006][1006], h[1000012], cnt = 0, h1[3311031], cn1 = 0, f[1000012], cn = 0, c[1006 << 3], num; bool vi[1000012]...
27
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; int n, t; int b[MAXN]; pair<int, int> _b[MAXN]; int ans[MAXN]; int ptr[MAXN]; void solve() { for (int i = 0; i < n; i++) { scanf("%d", &_b[i].first); _b[i].second = i; } sort(_b, _b + n); int maxc = 0; for (int i = 0; i < n; i++) {...
18
#include <bits/stdc++.h> int in() { int r = 0, c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') return -in(); for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar()) ; return r; } using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long res; l...
14
#include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &out, vector<long long int> const &a) { out << "< "; for (long long int i = 0; i < a.size(); i++) out << a[i] << " "; out << ">\n"; return out; } vector<long long int> operator-(vector<long long int> const &a, ...
12
#include <bits/stdc++.h> using namespace std; const int MAX_MEM = 1e8; int mpos = 0; char mem[MAX_MEM]; inline void *operator new(size_t n) { assert((mpos += n) <= MAX_MEM); return (void *)(mem + mpos - n); } inline void operator delete(void *) noexcept {} void write(pair<pair<int, int>, int> a) { cout << a.first...
14
#include <bits/stdc++.h> int main() { int n, d, count = 0, j; scanf("%d %d", &n, &d); int a[n], i, dif = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { dif = abs(a[i] - a[j]); if (dif <= d) { count++; } } ...
0
#include <bits/stdc++.h> int main() { int n, m, k; int i, j, tmp; int no_cr; int row[1005]; scanf("%d%d%d", &n, &m, &k); for (i = 1; i <= m; i++) row[i] = 10000000; for (i = 1; i <= n; i++) { scanf("%d %d", &j, &tmp); row[j] = (tmp < row[j] ? tmp : row[j]); } no_cr = 0; for (i = 1; (i <= m &...
4
#include <bits/stdc++.h> const int maxn = 3e5 + 5; using namespace std; int n, flag; long long k; long long a[maxn], b[maxn]; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); long long x = 0, y = 0; for (int i = 1; i <= n; ...
17
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") using namespace std; using ll = long long; using ld = long double; const int N = 51; int a[N][N], b[N][N]; int dp[N][N][N][N], dp1[N][N][N][N]; int kek; void print(int n) { cout << "!" << endl...
16
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long INF = 8e18; const int maxn = 5e3 + 5; const int mod = 998244353; int n; long long dp[maxn][maxn], fac[maxn], inv[maxn]; inline long long powmod(long long a, long long b) { long long res = 1; for (; b; b >>= 1) { if (b & 1) res = ...
23
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const int MOD = 1000000007; const int N = 400055; const int M = 511; void solve() { long long n; cin >> n; long long a = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120; long long b = a * (n - 5) / 6; long long c = b * (n - 6) / 7; cout << a...
5
#include <bits/stdc++.h> using namespace std; long long presum[200001]; int main() { int n; cin >> n; long long a[n]; for (int i = 0; i < n; i++) { scanf("%I64d", &a[i]); } sort(a, a + n); reverse(a, a + n); presum[0] = 0; long long ans2 = 0; for (int i = 1; i < n; i++) { presum[i] = a[i] + ...
11
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, s = 0; cin >> a >> b >> c >> d; s = a + b + c + d; if (s % 2) { cout << "NO"; return 0; } if (a == s / 2 || b == s / 2 || c == s / 2 || d == s / 2 || (a + b) == s / 2 || (a + c) == s / 2 || (a + d) == s / 2 || (b ...
0
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 1e5 + 5, inf = 1e9 + 7; long long t, n, d; long long Arr[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> t; while (t--) { cin >> n >> d; for (int i = 0; i < n; i++) cin >> Arr[i]; for (int i = 1; i < n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long x; cin >> x; long long z = x; long long y = x / 10; long long arr[10] = {11, 111, 1111, 11111, 111111, ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m, a, d; cin >> n >> m >> a >> d; vector<long long> line(m); for (auto& t : line) cin >> t; line.push_back(LINF); lon...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct edge { int fro, to, co; } e[N << 1]; int m, n, tot = 0; int a[N], b[N], fa[N]; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } void merge(int u, int v) { u = find(u), v = find(v); if (u == v) return; fa[u]...
16
#include <bits/stdc++.h> using namespace std; const int Inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fll; double ksmii(double a, int b) { if (!b) return 1; double x = ksmii(a, b >> 1); x *= x; if (b & 1) x *= a; return x; } int n, T; double dp[5005][5005]; int p[5005], t[5005]; int main() { scan...
16
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 2; long long inf = 1ll << 60; void solve() { long long n; cin >> n; long long x[n]; for (long long i = 0; i < n; i++) { cin >> x[i]; } long long ma = 0, ans = 0; for (long long i = 0; i < n; i++) { if (x[i] >= ma) { if (i and ...
4
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); size_t n, s; std::cin >> n >> s; std::priority_queue<std::pair<size_t, size_t>> pq; for (size_t i = 1; i <= n; ++i) { size_t cnt; std::cin >> cnt; if (cnt != 0) { pq.emplace(cnt, i); } } ...
14
#include <bits/stdc++.h> using namespace std; long long inf = pow(10, 18); long long modulo = pow(10, 9) + 7; double eps = 1e-6; const long long int mod = 1000000007; int a, n; string str, ptr; int arr[2001]; long long dp[2001][2001]; long long finddp(int i, int j) { if (i >= (int)(str.size())) { if (j < 1) ...
14
#include <bits/stdc++.h> using namespace std; using cap_t = int; const cap_t cap_inf = 0x3f3f3f3f; namespace flow { struct edge { int to, rev; cap_t cap; edge(int t, cap_t c, int r) { to = t; cap = c; rev = r; } }; vector<vector<edge>> adj; vector<int> cur, dist; int n, source, sink; cap_t ans; void...
0
#include <bits/stdc++.h> using namespace std; long long n, m, i; int main() { cin >> n; for (i = 2; i <= pow(n, 0.5); i++) if (n % i == 0) { m = 1 + (n - i) / 2; cout << m; return 0; } cout << 1; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 10; const int Inf = 0x7f7f7f7f; const long long Inf_ll = 1ll * Inf * Inf; const int Mod = 1e9 + 7; const double eps = 1e-7; int a[110][110]; bool vis[110][110]; bool check(int x, int y) { bool flag = false; for (int i = 1; i <= a[y][0]; i++) i...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, cnt; int c[maxn], f[maxn], g[maxn], has[maxn], pre[maxn], suf[maxn], ff[maxn]; vector<int> G[maxn]; void dfs1(int u, int fa) { ff[u] = fa; for (auto v : G[u]) if (v != fa) dfs1(v, u); f[u] = 1; for (auto v : G[u]) if (v != fa ...
8
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, d; cin >> n >> d; string s; cin >> s; vector<long long> dp(n, 1e9); dp[0] = 0; for (long long i = 1; i <= d; i++) { if (s[i] == '1') { dp[i] = 1; } } f...
0
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/stack:200000000") using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } long long n,...
8
#include<bits/stdc++.h> //#include<bits/extc++.h> #define fr first #define sc second using namespace std; //using namespace __gnu_pbds; typedef long long ll; //template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T>void umin(T &a,T b){if(b<a)a=b;} te...
4
#include <bits/stdc++.h> using namespace std; const int N = 55; template <typename T> void pfill(T* pst, const T* ped, T val) { for (; pst != ped; *(pst++) = val) ; } int n; int sz[N]; long double f[N][N]; long double C[N][N]; vector<int> g[N]; inline void init() { scanf("%d", &n); for (int i = 1, u, v; i < n...
21
#include <bits/stdc++.h> int MATRIX[111][10010], CLOSEST1[111][10010][2]; int N, M; int colMinShifts(int col) { int sum = 0, left, right; for (int i = 0; i < N; i++) { if (MATRIX[i][col] == 1) { continue; } left = CLOSEST1[i][col][0]; right = CLOSEST1[i][col][1]; if (left == -1) { le...
7
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; const int delta = (int)1e9 + 7; int n, m; vector<int> a[(int)2e5 + 23], g[(int)2e5 + 23], ans; bool f1[(int)2e5 + 23], f2[(int)2e5 + 23]; bool color[(int)2e5 + 23]; void dfs(int u) { color[u] = true; for (int i = 0; i < g[u].size(); i++) { ...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; pair<int, pair<int, int> > a[N]; vector<int> ans; int n, k, h, m[N], v[N]; bool check(long double t) { ans.clear(); int cnt = 1; for (int i = 0; i < n; i++) { int curv = a[i].second.first; int curin = a[i].second.second; if (1.0 * c...
12
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, cnt, ans[N], a[N], b[N]; int main() { scanf("%d", &n); for (int i = 1, x, y; i <= n; i++) { scanf("%d%d", &x, &y); a[i] = x, b[i] = y; } while (cnt == 0 || cnt == n) { cnt = 0; for (int i = 1, x, y; i <= n; i++) { x =...
15
#include <bits/stdc++.h> using namespace std; const int mo = 998244353; int n, a, b, ans, d[200005], fac[200005]; int main() { scanf("%d", &n); fac[0] = 1; for (int i = 1; i < n; i++) { scanf("%d%d", &a, &b); d[a]++; d[b]++; fac[i] = (long long)fac[i - 1] * i % mo; } int ans = n; for (int i ...
11
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define db long double #define ll long long int #define el '\n' #define pb push_back #define mp make_pair #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define F first #define S second #define debug(x) cout << "["...
0
#include <bits/stdc++.h> char str[300]; int main() { gets(str); int flag = 0, len = strlen(str); for (int i = 0; i < len; ++i) { if (str[i] == ',') { printf(","); if (i < len - 1) { printf(" "); } flag = 1; } if (str[i] == '.') { if (i != 0) { if (flag) ...
9
#include <bits/stdc++.h> using namespace std; string s; bool judge(string c) { int len = c.size(); for (int i = 0; i < len; i++) { if (c[i] != c[len - 1 - i]) return false; } return true; } int main() { string c; int k; cin >> s; int len = s.size(); for (int i = 0; i <= len; i++) { for (int j ...
22
#include <bits/stdc++.h> using namespace std; int N, W, K; signed long long A[202020]; signed long long T[202020]; signed long long SA[202020]; int type[202020]; set<pair<int, int>> H, F; signed long long TT; void add(int id) { type[id] = 1; TT += (T[id] + 1) / 2; H.insert({T[id], id}); if (H.size() > W) { ...
14
#include <bits/stdc++.h> using namespace std; int readint() { char c; while (c = getchar(), (c < '0' || c > '9') && c != '-') ; bool flag = (c == '-'); if (flag) c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - 48; c = getchar(); } return flag ? -x : x; } inline stri...
12
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (1 << 29) + 5; const long long int LLINF = (1ll << 59) + 5; const int MOD = 1000 * 1000 * 1000 + 7; const int MAX_N = 1000 * 1000 + 5; struct node { int value; int size; int y; node *l; node *r; node(in...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string str; cin >> str; long long x, y, val, val1, i; x = str.length(); vector<pair<char, long long>> v; char c = str[0]; y = 1; for (i = 1; i < x; i++) { if (str[i] == c) { ...
1
#include <bits/stdc++.h> using namespace std; int A[5000010]; int main() { for (int i = 1; i <= 5000005; i++) A[i] = 1; for (int i = 2; i * i <= 5000005; i++) if (A[i]) for (int j = i * i; j <= 5000005; j += i) A[j] = 0; for (int i = 2; i * i <= 5000005; i++) if (A[i * i] == 0) for (int j = i ...
9
#include <bits/stdc++.h> using namespace std; bool fr[100010]; int main() { int n, m; cin >> n >> m; int i, a[n], l[m], sol[n]; for (i = 0; i < n; i++) cin >> a[i]; sol[n - 1] = 1; fr[a[n - 1]] = 1; for (i = n - 2; i >= 0; i--) { sol[i] = sol[i + 1]; if (fr[a[i]] == 0) sol[i]++; fr[a[i]] = 1; ...
3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 9; vector<long long> v[N]; vector<pair<long long, long long> > ans; long long vis[N], f = 0, d; set<long long> con; void dfs(long long ver, long long par = 1) { ans.push_back({par, ver}); vis[ver] = 1; if (con.count(ver)) con.erase(con.find(v...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double eps = 1e-7; int w, l, a[MAXN], sum[MAXN]; int main() { scanf("%d %d", &w, &l); for (int i = 1; i < w; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i]; int ans = INF; for ...
11
#include <bits/stdc++.h> using namespace std; int n, m, x[15], y[15]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = 1; i <= m; i++) cin >> y[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (x[i] == y[j]) cout << x[i] << " "; } }
0
#include <bits/stdc++.h> using namespace std; long long int arr[200006]; long long int size1[200006]; long long int sum = 0; long long int solve(long long int x) { long long int c = ((x) * (x - 1)) / 2; return c; } long long int root(long long int i) { while (arr[i] != i) { arr[i] = arr[arr[i]]; i = arr[i...
11
#include <bits/stdc++.h> using namespace std; int main() { int prev, cur; string a = "", b = ""; for (int i = 0; i < 300; i++) a += 'a', b += 'b'; cout << a << endl; cin >> prev; if (prev == 0) return 0; cout << b << endl; cin >> cur; if (cur == 0) return 0; int l = 600 - prev - cur; string s = ""...
15
#include <bits/stdc++.h> using namespace std; int n, d, z = -1, a[100]; int main() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (a[j] - a[i] <= d) if (j - i > z) z = j - i; } } cout << n - z - 1...
4
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; int **p = new int *[x]; for (int i = 0; i < x; i++) { p[i] = new int[3]; } for (int i = 0; i < x; i++) { cin >> p[i][0]; cin >> p[i][1]; cin >> p[i][2]; } for (int i = 0; i < x; i++) { int times = 0; whil...
0
#include <bits/stdc++.h> using namespace std; int n, m, a[2003][2003], pn, lux, luy, d[2003][2003]; struct Point { int x, y; Point(int _x = 0, int _y = 0) : x(_x), y(_y) {} } p[2003 * 2003]; int cs, used[2003 * 2003]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector<int> e[2003]; int get(int x1, int y1,...
15
#include <bits/stdc++.h> using namespace std; int nxt[2010], dp[2010][2010]; int main() { int n, m, i, j; string s, p; cin >> s >> p; n = s.size(), m = p.size(); s = " " + s; for (i = 0; i < n; i++) { int cur = 0; for (j = i + 1; j <= n; j++) { if (s[j] == p[cur]) cur++; if (cur == m) br...
14
#include <bits/stdc++.h> const int mo = 998244353, N = 2005; int n, a[N][N], ia[N][N], i, j, f[N][N], bi[N], mi[N], fac[N], ans; inline void add(int x, int v = 1) { for (; x <= n; x += x & -x) bi[x] += v; } inline int ask(int x) { int ans = 0; for (; x; x -= x & -x) ans += bi[x]; return ans; } int main() { fo...
21
#include <bits/stdc++.h> using namespace std; int main() { int n; string s, a, b; int res = 0, count1 = 0, count2 = 0; cin >> n; while (n--) { cin >> s; res++; if (res == 1) { a = s; } if (s != a) { count2++; b = s; } else count1++; } if (count1 > count2) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { char c[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> c[i][j]; } } puts((c[0][0] == c[2][2] && c[0][1] == c[2][1] && c[0][2] == c[2][0] && c[1][0] == c[1][2]) ? "YES" : "NO"); retu...
0
#include<bits/stdc++.h> #define all(x) x.begin(),x.end() #define sc(x) scanf("%d",&x) #define scl(x) scanf("%lld",&x) #define LL long long #define LD long double #define pb push_back #define F first #define S second const double PI=3.1415926535897932384626433; const int KL=1e6; const LL MOD=1e9+7; using namespace std...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, m, a, b, c, d; cin >> n >> m >> a >> b >> c >> d; long long ans = 0; long long ans1 = 0; if (a == c || b == d) { cout << 0 << endl; } else { if (d < b) { ans = (m - d)...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, m; cin >> n >> m; if (n == 9 && m == 1) cout << "99 100" << endl; else if (m < n || m > n + 1) cout << "-1" << endl; else { if (n == m) cout << n...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long b, long long s) { return (s != 0) ? gcd(s, b % s) : b; } long long Pow(long long a, long long b, long long c) { if (b == 0) return 1 % c; else if (b == 1) return a % c; else { long long A = Pow(a, b / 2, c); A = (A * A) % c; ...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 2e5 + 10; const double PI = acos(-1.0); long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } void exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; } else ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, low = 1, high; bool x = false; cin >> n; high = n; while (high >= low) { if (x) cout << high-- << ' '; else cout << low++ << ' '; x = !x; } return 0; }
4
#include <bits/stdc++.h> using namespace std; int a[200001]; vector<int> v; vector<pair<int, int> > v1; int main() { int n, k, cnt = 0; scanf("%d%d", &n, &k); int naive = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] < 0) { cnt++; if (i > 0 && a[i - 1] >= 0) { naive++...
10
#include <bits/stdc++.h> using namespace std; string a, b; int n, p, d[30][30]; char x, y; int main() { cin >> a >> b; scanf("%d", &n); for (int i = 0; i < 30; ++i) { for (int j = 0; j < 30; ++j) { if (i == j) d[i][j] = 0; else d[i][j] = 1000000007; } } for (int i = 0; i < ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; vector<pair<long long, char> > s1; vector<pair<long long, char> > s2; for (long long i = 0; i < n; i++) { int len; char let; scanf("%d-%c", &len, &let); if (s1.size() > 0 && s1.back().second == let) ...
13
#include <bits/stdc++.h> using namespace std; inline long long cal(long long n, long long m) { long long res = 0; if (m % 2 == 0) res += cal(n, m + 1); for (long long cnt = 1; m <= n; m <<= 1, cnt <<= 1) res += min(m + cnt - 1, n) - m + 1; return res; } int main() { long long n, k, res = 1; cin >> n >> ...
13
#include <bits/stdc++.h> using namespace std; char s[300]; int main() { int sign1 = 0, sign2 = 0, len = 0, i, n; char ch; while (scanf("%c", &ch) && ch != '=') { if (ch == '+') sign1++; else if (ch == '-') sign2++; s[len++] = ch; } sign1++; scanf("%d", &n); if (sign1 > n + sign2) {...
10
#include <bits/stdc++.h> using namespace std; template <typename T> bool vmin(T& a, T b) { return (a > b) ? (a = b, true) : (false); } template <typename T> bool vmax(T& a, T b) { return (a < b) ? (a = b, true) : (false); } template <typename T> T smax(T x) { return x; } template <typename T, typename... K> T sma...
27
#include <bits/stdc++.h> using namespace std; const int mn = 2 * (1e5 + 10); int a[mn]; int c[mn]; long long int sum = 0; int ch[mn]; int go(int sh, int po) { int apo = a[po]; if (ch[apo] == -1) { ch[apo] = sh; return go(sh, apo); } if (ch[apo] < sh) { return 0; } if (ch[apo] == sh) { int mi...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1e3 + 7, L = 1e6; int n, m; struct OP { int x, y, t; }; vector<OP> v; int c[N]; void add(int x, int v) { while (x <= L) c[x] += v, x += x & -x; } int qry(int x) { int ret = 0; while (x) ret += c[x], x -= x & -x; return ret; } bool cmp(OP a, OP ...
16
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << '(' << p.first << ", " << p.second << ')'; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { long long l = v.size(); for (long...
15
#include <bits/stdc++.h> using ll = long long; const int C = 331, M = 1000000007; int dp[C][C]; ll fac[C]; int main() { int n, m, x, i, a, b; fac[0] = 1; for (i = 1; i < C; i++) fac[i] = (fac[i - 1] * i) % M; scanf("%d %d %d", &n, &m, &x); dp[0][0] = 1; if (n > m) { printf("0\n"); return 0; } fo...
19
#include <bits/stdc++.h> using namespace std; int cnt[3005]; char ans[3005]; vector<int> vis1[105], vis2[105]; vector<string> edge1[105], edge2[105], edge3[105]; void solve(int n) { cout << "?" << " " << 1 << " " << n << endl; cout.flush(); for (int i = 1; i <= ((1 + n) * n / 2); i++) { string s; c...
20
#include <bits/stdc++.h> using namespace std; int DB(int a, int s, int e) { int y = s, ret = 0; while ((1 << y) <= a && y < e) { if ((a & (1 << y)) != 0) ret++; y++; } return ret; } int main() { cin.sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> v(n), v2(n); for (int i = 0;...
16
#include <bits/stdc++.h> using namespace std; long long t, w, h, k, xxa[2], xa[2], yya[2], ya[2], x, y, z; string s; vector<long long> e; bool p[10005]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cin >> t; for (long long ca = 1; ca <= t; ++ca) { cin >> w >> h >> k; cin >> xa[0]...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 128; int ar[MAXN], N, M, id; char command[30]; void alloc() { int k, bos = 0; cin >> k; for (int i = 1; i <= M; i++) { if (!ar[i]) bos++; else bos = 0; if (bos == k) { id++; for (int j = i - bos + 1; j <= i; j++) ar...
8
#include <bits/stdc++.h> using namespace std; void read() { freopen("pudge.in", "r", stdin); freopen("pudge.out", "w", stdout); } void faster() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void pudge() { int n, m, c; cin >> n >> m >> c; int a[n], b[m]; for (int i = 0; i < n; i++) cin...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 15; const int pos = 67; bitset<maxn> a[pos]; long long c, sxor; int n, d[pos]; int bb[maxn]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%I64d", &c); sxor ^= c; for (int j = 0; j < 63; j++) a[62 - j][i] = (c &...
19
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long n, m, a, b, c, k, temp, x, y; const int MAXN = 1e5 + 11, mod = 1e9 + 7; inline long long max(long long a, long long b) { return ((a > b) ? a : b); } inline ...
11
#include <bits/stdc++.h> using namespace std; const int N = 100005 + 10; long long fa[N][36]; long long son[N][36]; long long minn[N][36]; long long n, k; void sovle(long long u) { long long ans = 0, Min = 1e18; long long K = k; for (long long i = 35; i >= 0; i--) { if ((1ll << i) <= K) { ans += fa[u][i...
13
#include <bits/stdc++.h> using namespace std; long long int n, m, p[100005], c[100005], e; long long int find(long long int v) { long long int t = 1, w; if (p[v] == v) { return v; } w = p[v]; p[v] = find(p[v]); c[v] ^= c[w]; return p[v]; } void un(long long int v1, long long int v2, long long int xx) ...
14
#include <bits/stdc++.h> using namespace std; long long n, x, a[300010], lleft[300010], sum1[300010], sum2[300010], rright[300010]; signed main() { ios::sync_with_stdio(false); cin >> n >> x; for (long long i = 1; i <= n; i++) cin >> a[i]; long long minv1 = 0; for (long long i = 1; i <= n; i++) { sum1...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct E { int a, b, c; bool operator<(const E t) const { return c < t.c; } } edgs[N]; int p[N]; int find(int x) { if (x != p[x]) return p[x] = find(p[x]); return p[x]; } int main() { int n, m; cin >> n >> m; int x, y, z; cin >> x >> ...
11
#include <bits/stdc++.h> using namespace std; const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1}; const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1}; const int inf = 1e9 + 5; const long long linf = 1e18; const double PI = acos(-1.0); const int MAXN = 2e5 + 5; const int N = 1e6 + 5; int n, m, k, cnt = 0; int mx[N * 4], ad...
18
#include <bits/stdc++.h> using namespace std; int n, arr[100001]; bool solve() { sort(arr, arr + n); n = unique(arr, arr + n) - arr; if (n != 3) return n < 3; return 2 * arr[1] == arr[0] + arr[2]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) cin >...
4
#include <bits/stdc++.h> short n, x, i, j; short a, b; int main() { scanf("%hd %hd", &n, &x); for (i = 0; i < n; ++i) { scanf("%hd %hd", &a, &b); if (x == a || x == 7 - a || x == b || x == 7 - b) break; } if (i < n) puts("NO"); else puts("YES"); return 0; }
3
#include <bits/stdc++.h> int q; int main() { scanf("%d", &q); while (q--) { int x; scanf("%d", &x); if (x <= 3 || x == 5 || x == 7 || x == 11) printf("-1"); else { if (x % 4 == 0) printf("%d", x / 4); if (x % 4 == 1) printf("%d", (x - 9) / 4 + 1); if (x % 4 == 2) printf("%d",...
5
#include <bits/stdc++.h> #define rep(i,e) for(int i = 0; i < e; i++) #define reps(i,s,e) for(ll i = s; i <= e; i++) #define rev(i,s) for(ll i = s; ~i; i--) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x.size()) #define pb push_back #define ff first #define ss second using namespace std; typedef long long...
17
#include <bits/stdc++.h> using namespace std; long long n, m, t, res, mod = 998244353, x, y, power[300300], w, q, now; vector<vector<long long> > my(300005); long long color[300300]; bool vis[300300]; long long bipartite(long long u) { x = 1, y = 0; queue<long long> q; color[u] = 1; q.push(u); while (!q.empty...
9
#include <bits/stdc++.h> using namespace std; const double PI = atan2(1, 0) * 2; const double TAU = atan2(1, 0) * 4; const int MAXN = 1.1e5; int N; int M; pair<double, double> pts[MAXN]; int nxt[MAXN]; pair<double, double> ranges[MAXN * 3]; pair<double, int> right_pts[MAXN + 20]; int numBarriers(double dist) { for (i...
23
// In The Name Of God /* ki oomade?! */ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <l...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, ans = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); } return f * ans; } const long l...
21
#include <bits/stdc++.h> using namespace std; int dp[42][1 << 20], a[42][42]; char s[22][22]; int n; int dfs(int step, int sta) { int i, num = 0; if (dp[step][sta] != 1e9) return dp[step][sta]; for (i = 0; i < n; i++) { if (sta & (1 << i)) { if (s[step - i][i] == 'a') num++; else if (s[ste...
16
#include <bits/stdc++.h> using namespace std; int t; struct odc { long long x1, y1, x2, y2; }; long long mini(long long a, long long b) { if (a < b) return a; return b; } long long maxi(long long a, long long b) { if (a > b) return a; return b; } long long Dl(odc a) { return (a.x1 - a.x2) * (a.x1 - a.x2) + ...
12
#include <bits/stdc++.h> using namespace std; int main() { int x11, x12, x13, x21, x22, x23, x31, x32, x33; cin >> x11 >> x12 >> x13 >> x21 >> x22 >> x23 >> x31 >> x32 >> x33; int sum = (x12 + x13 + x21 + x23 + x31 + x32) / 2; x11 = sum - x12 - x13; x22 = sum - x21 - x23; x33 = sum - x31 - x32; cout << x1...
3
#include <bits/stdc++.h> int l[100009], r[100009], t[100009]; int main() { int n, m, s, f; int i, j; while (scanf("%d%d%d%d", &n, &m, &s, &f) != -1) { t[0] = 0; for (i = 1; i <= m; i++) { scanf("%d%d%d", &t[i], &l[i], &r[i]); } int pos = s; if (s < f) { int time = 1, d = 1; f...
7
#include <bits/stdc++.h> using namespace std; const int MAXK = 30; const int MAXN = 200005; int T, N, Cnt1[MAXK], Cnt2[MAXK], Len; char c1[MAXN], c2[MAXN]; char s[MAXN], r[MAXN]; long long Get(int L, int R) { if (L == R) return 0; int mid = (L + R) >> 1; long long ret = 0; ret += Get(L, mid) + Get(mid + 1, R); ...
12
#include <bits/stdc++.h> using namespace std; const int MAX = 1000001; int F[MAX], G[MAX], T[10][2 * MAX + 1]; void calculate_F() { for (int i = 1; i < 10; i++) F[i] = i; for (int i = 10; i < MAX; i++) { int last_digit = i % 10; F[i] = F[i / 10]; if (last_digit != 0) F[i] *= last_digit; } } void calcu...
5