solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int it(string s) { int ans = 0; for (int i = 0; i < s.size(); i++) { ans += int(s[i] - '0'); if (i != s.size() - 1) ans *= 10; } return ans; } int main() { int n, m, ar[10], ar2[10]; cin >> n >> m; string s[10]; for (int i = 0; i < n; i++) { cin ...
6
#include <bits/stdc++.h> using namespace std; long long int prod(long long int a, long long int b) { long long int x, d; if (b == 0) return 1; else { d = prod(a, b / 2); x = (d * d) % 1000000007; if (b % 2 == 0) return x; else return (x * (a % 1000000007)) % 1000000007; } } int m...
6
#include <bits/stdc++.h> using namespace std; long long int lft[500005], rgt[500005], a[500005], d[500005]; stack<pair<long long int, long long int> > q; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, m, l, r, ans; cin >> n >> m; for (long long int i = 1; i <= n;...
13
#include <bits/stdc++.h> using namespace std; const int N = 1005; double f[N][N]; bool vis[N][N]; int n, m; double dfs(int n, int m) { if (vis[n][m]) return f[n][m]; vis[n][m] = true; if (!m) return f[n][m] = 1; double inv = 1.0 / (m + 1); if (!n) return f[n][m] = inv; double a = 1 - dfs(m, n - 1), b = 1, d...
19
#include <bits/stdc++.h> using namespace std; const int N = 100005; set<int> se[N]; int st[105][4 * N], a[N], bs = 1000, prevv[N]; int pre(int x) { int ele = a[x]; auto it = se[ele].lower_bound(x); if (it == se[ele].begin()) return prevv[x] = -1; it--; return prevv[x] = *it; } int nex(int x) { int ele = a[x...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 2; i <= n; i++) { cout << i << " "; } cout << 1 << endl; }
9
#include <bits/stdc++.h> using namespace std; int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1}; int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const long long oo = 1e18; const long long maxN = 1e6; const long long MOD = 1e9 + 7; void maximize(int &a, int b) { a = max(a, b); } ...
9
#include <bits/stdc++.h> using namespace std; struct subj { long long a, b; int c, id, d; bool operator<(const subj &other) const { return c < other.c; } }; long long f[55][55][111]; subj p[55]; pair<int, int> tr[55][55][111]; int n, m, k; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = (1), _b = (m); ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const long long inf = (1LL << 30 - 1); long long a[maxn], c[maxn]; int main() { int n; long long k; scanf("%d%I64d", &n, &k); for (int i = 0; i <= n; i++) { scanf("%I64d", &a[i]); c[i] = a[i]; } for (int i = 0; i < n; i++) { ...
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; int nomalDay[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int leapDay[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int ARRSIZE = 100100; const int STRSIZE = 100100; const int TEMPSIZE = 1010; const int...
8
#include <bits/stdc++.h> using namespace std; int main() { (ios_base::sync_with_stdio(false), cin.tie(nullptr)); int t; t = 1; while (t--) { int n, m; string s; cin >> n >> m >> ws; map<string, int> mp; for (int i = 0; i < n; i++) { getline(cin, s); mp[s]++; } int common ...
3
#include <bits/stdc++.h> using namespace std; using LL = long long; using db = double; using Point = complex<db>; using Vector = Point; const int mo1 = 1000000007; const int mo2 = 998244353; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int maxn = 200005; int n, a[maxn], p[maxn]; int main() { ...
7
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, a[22], b[1 << 18]; long long f[1 << 18][18], g[1 << 18]; char s[22][22]; void rec(int sum, int x, int mask) { if (sum == 0) { for (i = 0; i < (1 << n); i++) for (j = 0; j < n; j++) f[i][j] = 0; for (i = 0; i < n; i++) f[1 << i][i] = 1; ...
18
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } long long int fexp(long long int a, long long int b) { long long int ans = 1; whil...
10
#include <bits/stdc++.h> using namespace std; int n; vector<int> q[100005]; vector<long long> g[100005]; vector<int> num[100005]; long long a[100005]; long long ans, mod = 1e9 + 7; long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } void dfs(int x, int pr) { long long last = -1; ...
12
#include <bits/stdc++.h> using namespace std; long maxval(long a, long b) { return a > b ? a : b; } long minval(long a, long b) { return a < b ? a : b; } int main() { long n, m, a, b, i; long long count = 0; scanf("%li %li", &n, &m); a = maxval(m, n); b = minval(m, n); for (i = 1; i <= b; i++) { count =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m; k = (n * m) / 2; cout << k; return 0; }
0
#include <bits/stdc++.h> using namespace std; map<vector<int>, int> mp; vector<int> v[1000]; int cnt; int hsh(int i, int j) { return (i - 1) * cnt + j; } int sta[1000000], C[1000000], out[1000000]; vector<int> ed[1000000]; int main() { for (int a = 0; a <= 8; a++) { for (int b = 0; a + b <= 8; b++) { for (i...
18
#include <bits/stdc++.h> using namespace std; int main() { int a[4]; cin >> a[0] >> a[1] >> a[2] >> a[3]; int ini = a[0] + a[1] + a[2] + a[3]; if (ini & 1) { cout << "NO"; return 0; } int i, j; for (i = 0; i < 3; i++) { for (j = i + 1; j < 4; j++) { int put = a[i] + a[j]; if (ini /...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string second; cin >> second; long long ans = 0; long long fc = 1, lc = 1; for (int i = 1; i < n; i++) { if (second[i] == second[i - 1]) fc++; else break; } for (int i = n - 2; i >= 0; i--) { if (second...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, y = -1, ai = 0; cin >> n >> m; vector<long long> coordinate(n + m), riders(n + m), ans(m, 0); for (i = 0; i < n + m; i++) cin >> coordinate[i]; for (i = 0; i < n + m; i++) cin >> riders[i]; for (i = 0; i < n + m; i++) { if (ri...
4
#include <bits/stdc++.h> using namespace std; long long arr[100010]; int pwr(int base, long long exp) { if (exp == 0) return 1; if (exp == 1) return base; int res = (1LL * base * base) % 1000000007; return (1LL * pwr(res, exp >> 1) * pwr(base, exp & 1)) % 1000000007; } int main() { int k, res = 2; bool even...
12
#include <bits/stdc++.h> using namespace std; const int N = 505; int MOD; int NN; long long dp[N][N], cnp[N][N], ma[N][N], c[N]; void NchooseK() { for (int i = 0; i < N; ++i) { cnp[i][0] = cnp[i][i] = 1; for (int j = 1; j < i; ++j) { cnp[i][j] = cnp[i - 1][j - 1] + cnp[i - 1][j]; } } } long long d...
13
#include <bits/stdc++.h> using namespace std; class coor { public: int x; int y; bool equ(coor p) { if (p.x == x && p.y == y) return 1; return 0; } }; int n; coor obelisk[1001], clue[1001], result[1001][1001]; bool tree(int len, coor m) { if (len == n) return 1; for (int i = 0; i < n; i++) { if...
4
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long int arr[n]; for (long long int i = 0; i < n; ++i) { cin >> arr[i]; } long long int cnt = 0; for (long long int j = 0; j < n; ++j) { long long int cur_sum = arr[0]; long long int start = 0; lon...
7
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9, PI = acos(-1.); const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; const int N = 1e5 + 5, M = 1e6 + 5; int n, m, k, d[N], f[N], t[N], c[N], o[N]; int mi, ma; int vis[N]; int cc[N], cs[N]; long long tvis, sum; long long first[4 * M]; void update(int p, ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y; cin >> n >> x >> y; if (n > y) cout << "-1"; else if (n >= x) { for (int i = 1; i < n; ++i) cout << "1\n"; cout << "1"; } else if (y * y >= x) { long long t = y - n + 1; if (t * t + n - 1 < x) cout << "-1";...
6
#include <bits/stdc++.h> using namespace std; const int N = 50005; int n; int a[N]; struct Queue { long long cnt; long long num; } d[N]; int tot; long long num[2 * N]; long long sum[N * 20], sumcnt[N * 20]; int gcd(int x, int y) { if (y == 0) return x; else return gcd(y, x % y); } struct data { long l...
26
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, tim = 0; cin >> n >> m; vector<vector<int>> g(n); vector<int> a(n), tin(n), tout(n), depth(n); vector<vector<int>> BIT(2, vector<int>(n + 1)); for (int i = 0; i < n; i++) cin >> a[i]; for (int...
12
#include <bits/stdc++.h> using namespace std; namespace F { const int N = 600, M = 400050, inf = ~0u >> 2; struct edge { int t, f, c; edge *n, *d; } eb[M * 2], *ec = eb, *e[N]; int n, s, t, flow, cost; inline void add_edge(int s, int t, int f, int c) { *ec = (edge){t, f, c, e[s], ec + 1}; e[s] = ec++; *ec = (...
19
#include <bits/stdc++.h> using namespace std; vector<int> primes; void buildSieve(int n) { vector<int> spf; spf.resize(n + 1, 0); spf[0] = spf[1] = 1; for (int i = 2; i <= n; ++i) { if (spf[i] == 0) { primes.push_back(i); spf[i] = i; } for (int j = 0; j < int(primes.size()) && p...
7
#include <bits/stdc++.h> using namespace std; const long long int M = 2e5 + 10; const long long int mod = 1e9 + 7; const long long int infi = LLONG_MAX; long long int ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b, c, z, sum; vector<long long int> v[M]; vector<long long in...
11
#include <bits/stdc++.h> using namespace std; template <typename T> string tos(T a) { stringstream ss; string ret; ss << a; ss >> ret; return ret; } struct pnt { int v[32]; }; pnt orig; int vl(char ch) { if (ch == '?') return 0; return (ch - 'a') + 1; } string s, p; int ls, lp, ret; int match(pnt a, pnt...
7
#include <bits/stdc++.h> using namespace std; long long n, m, mod; long long gp(long long lo, long long hi, long long br) { if (lo > hi) return 0; if (br & 1) return ((((lo + hi) / 2) % mod) * (br % mod)) % mod; else return (((lo + hi) % mod) * ((br / 2) % mod)) % mod; } long long sum(long long beg, long ...
17
#include <bits/stdc++.h> using namespace std; string s; long long int n; double arr[26]; int main() { cin >> s; memset(arr, 0, sizeof(arr)); n = s.size(); double prob = 0; vector<vector<int>> v; v.resize(26); for (int i = 0; i < n; i++) { v[s[i] - 97].push_back(i); } for (int c = 0; c < 26; c++) {...
8
#include <bits/stdc++.h> #ifdef _SWET #include "DEBUG.h" #else #define debug(...) using namespace std; #endif #define int long long #define endl '\n' #define sz(x) (int)((x).size()) #define all(x) (x).begin(),(x).end() #define allr(x) (x).rbegin(),(x).rend() #define mem0(x) memset(x, 0, sizeof(x)) #define mem1(x) mem...
11
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10, oo = 1000 * 1000 * 1000; int n; double ans = oo; vector<pair<int, int> > ch; pair<int, int> p[N], o; long long operator*(pair<int, int> p, pair<int, int> q) { return 1ll * p.first * q.second - 1ll * p.second * q.first; } pair<int, int> operator-...
16
#include <bits/stdc++.h> using namespace std; class dop { public: string s, t; vector<long long int> a, b; long long int be, c, d, n, p; void get(); }; bool col(string p, string q) { if (p.length() == q.length()) { for (long long int i = 0; i < p.length(); i++) { if (p[i] != q[i]) { return ...
6
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
9
#include <bits/stdc++.h> using namespace std; int N, M, xc, yc, zc; int a[1005]; int main() { scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++) scanf("%d", &a[i]); double ans = 0; for (int i = 1; i <= M; i++) { scanf("%d %d %d", &xc, &yc, &zc); ans = max(ans, (a[xc] + a[yc]) / double(zc)); } prin...
8
#include <bits/stdc++.h> using namespace std; long long n, ans; long long cal(long long x) { long long ret; if (n >= x) ret = (x - 1) / 2; else ret = ((n - (x - n) + 1) / 2); return max(0ll, ret); } int main() { long long i, j, k; cin >> n; for (i = 9; i <= 999999999; i = i * 10 + 9) if (n + n...
10
#include <bits/stdc++.h> using namespace std; string second; int m, n; string ans = ""; int dp[100011][26]; int inc[100011]; int main() { cin >> m; cin >> second; char cp = 'a'; cp--; int n = second.size(); for (char c = 'a'; c <= 'z'; c++) { int cnt = 0; for (int i = 0; i < m - 1; i++) { cnt ...
11
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int INF = 9999999; const int MAXN = 1000100; const int MAXM = 20001...
24
#include <bits/stdc++.h> using namespace std; int main() { int n, min = 10000000, m, sum = 0, k; cin >> n; int a[n], i; for (i = 0; i < n; i++) cin >> a[i]; i = 0; while (n--) { sum = 0; k = a[i]; while (k--) { cin >> m; sum = sum + m * 5; } sum = sum + a[i] * 15; if (min...
1
#include <bits/stdc++.h> using namespace std; long long head[200100], nxt[200100 << 1], ver[200100 << 1], tot; inline void addedge(long long a, long long b) { nxt[++tot] = head[a]; ver[tot] = b; head[a] = tot; nxt[++tot] = head[b]; ver[tot] = a; head[b] = tot; } long long f[200100][5], s[200100]; long long ...
13
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<deque> #include<set> #include<map> #include<bitset> #include<string> #include<cstdio> #include<cstring> #include<cmath> #include<numeric> #include<cstdlib> #include<ctime> #include<iomanip> #define fi first #define se seco...
16
#include <bits/stdc++.h> using namespace std; int paintTheFence(vector<vector<int>>& ranges, int n, int q) { vector<int> wall(n + 2, 0); vector<int> single(n + 1, 0); vector<int> double1(n + 1, 0); for (int i = 0; i < q; i++) { wall[ranges[i][0]]++; wall[ranges[i][1] + 1]--; } for (int i = 1; i <= n...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, hom[31], guest[31], count = 0; cin >> a; for (int i = 0; i < a; i++) { cin >> hom[i] >> guest[i]; } for (int i = 0; i < a; i++) { for (int j = 0; j < a; j++) { if (hom[i] == guest[j]) { count++; } } } cout <<...
0
#include <bits/stdc++.h> using namespace std; int d[100001]; long long r[100001], b[100001]; int q[100001]; pair<long long, long long> ln[100001]; long long pd[2][100001]; bool pop(pair<long long, long long>& l1, pair<long long, long long>& l2, pair<long long, long long>& l3) { return (l1.first - l3.first) *...
16
#include <bits/stdc++.h> using namespace std; int n; long long ans; priority_queue<int, vector<int>, greater<int> > pq; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0, x; i < n; i++) { cin >> x; if (!pq.empty() && x > pq.top()) { ans += x - pq.top(); pq.pop();...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int d, n; while (cin >> d >> n) { vector<int> a(n); for (int i = (0); i < ((n)); ++i) cin >> a[i]; int res = 0; for (int i = (0); i < ((n - 1)); ++i) res += (d - a[i]); cout << res << endl; } return 0;...
2
#include <bits/stdc++.h> using namespace std; int n, k, p; struct Inf { int ai, bi, ii, bbii; } inf1[101000], inf2[101000]; bool cmp2(struct Inf a, struct Inf b) { if (a.ai != b.ai) return a.ai > b.ai; return a.bi > b.bi; } bool cmp1(struct Inf a, struct Inf b) { if (a.bi != b.bi) return a.bi > b.bi; return a...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int m, n, k; long long int ref = 0; cin >> m >> n >> k; if (k > m + n - 2) { cout << "-1"; return 0; } long long int c1, c2; int ctr = 0; while (ctr < 2) { if (ctr == 1) { long long int temp = m; m = n; n ...
9
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { return (b == 0 ? a : GCD(b, a % b)); } int LCM(int a, int b) { return a * (b / GCD(a, b)); } int dx4[] = {-1, 0, 0, 1}; int dy4[] = {0, -1, 1, 0}; int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1}; string s; long long P...
12
#include <bits/stdc++.h> using namespace std; struct SegTree { pair<int, int> seg[(1 << 18) * 2 - 1]; SegTree() { for (int i = 0; i < (1 << 18) * 2 - 1; i++) seg[i] = pair<int, int>(0, 0); } void update(int i, pair<int, int> x) { i += (1 << 18) - 1; seg[i] = x; while (i > 0) { i = (i - 1) ...
15
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; for (int tt = 0; tt < test; tt++) { int h, w, a, b; cin >> h >> w >> a >> b; if (h * a != w * b) { cout << "NO" << endl; continue; } vector<vector<int>> result(h, vector<int>(w, 0)); int shift = 0...
11
#include <bits/stdc++.h> const double Pi = acos(-1.0); using namespace std; const int maxN = 1010; const int maxM = 10010; long long n, m, L, s, t; long long u[maxM], v[maxM]; vector<int> G[maxN]; long long adj[maxN][maxN]; long long pre[maxN]; long long dijk(int id) { long long dist[maxN]; for (int i = 0; i < n; i...
15
#include <bits/stdc++.h> using namespace std; int const N = 200001; int n, w[N], h[N], hh[N], fr[N]; vector<int> mx; int main() { scanf("%d", &n); int W = 0; int m = 0; for (int i = 0; i < n; ++i) { scanf("%d%d", w + i, h + i); W += w[i]; m = max(m, h[i]); hh[i] = h[i]; ++fr[h[i]]; } sor...
3
#include <bits/stdc++.h> using namespace std; int a[26], b[26], x, y, i, p, q, j, z, alp, tt, k; vector<pair<int, int> > vec; int main() { string s, t, temp; cin >> s >> t; temp = s; for (i = 0; i < s.length(); i++) a[s[i] - 97]++; for (i = 0; i < t.length(); i++) b[t[i] - 97]++; for (i = 0; i < 26; i++) ...
12
#include <bits/stdc++.h> using namespace std; string t, p; vector<int> a; bool check(int m) { string current; vector<bool> used(t.length(), true); for (int i = 0; i < m; i++) { used[a[i] - 1] = false; } for (int i = 0; i < t.length(); i++) { if (!used[i]) { current += t[i]; } } int it = ...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int o = 0, e = 0; long long int n = s.size(); for (long long int i = 0; i < n; i++) { if (s[i] == '1') { e++; } else { o++; } } int x = min(o,...
1
#include <bits/stdc++.h> using namespace std; pair<int, int> x[2020]; int main() { int n; scanf("%d", &n); for (int i = (0); i < ((n)); ++i) scanf("%d", &x[i].first), x[i].second = i + 1; sort(x, x + n); x[n] = make_pair(2020, -1); int c = 1, c2 = 0, i1 = 0; for (int i = (0); i < ((n)); ++i) { if ...
5
#include <bits/stdc++.h> using namespace std; int pos[201]; int m[201], cd; void inp() { cin >> cd; cd = cd * 2; for (int i = 1; i <= cd; i++) { cin >> m[i]; pos[m[i]] = i; } } void calc() { int kq = 0; for (int i = 1; i <= cd; i += 2) { int h = 0; for (int e = pos[m[i]] - 1; e >= i + 1; e--...
6
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T& x) { return x * x; } template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; const long double EPS = 1e-11; char T...
13
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; void chk(int &ans) { if (ans < 0) ans += p; if (ans >= p) ans -= p; } int main() { long long m; cin >> m; int ans = 0, mp = m % p, inv2 = (p + 1) / 2, inv3 = (p + 1) / 3, inv5 = (2 * p + 1) / 5; int inv6 = 1LL * inv2 * inv3 % p, i...
21
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
9
#include <bits/stdc++.h> using namespace std; int a, b; char s[1005]; char c[3005]; bool Rome; void getb() { b = 0; int len = strlen(s); if (s[0] >= '0' && s[0] <= '9') { for (int i = 0; i < len; i++) b = b * 10 + s[i] - '0'; } else Rome = 1; } int count(char c) { if (c >= '0' && c <= '9') return c - ...
12
#include <bits/stdc++.h> int main() { int n, x; int i; int a[3][6] = {{1, 1, 2, 2, 0, 0}, {0, 2, 1, 0, 2, 1}, {2, 0, 0, 1, 1, 2}}; while (scanf("%d%d", &n, &x) != EOF) { if (n % 6 == 0) printf("%d\n", a[x][5]); else printf("%d\n", a[x][n % 6 - 1]); } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int dp[maxn][maxn], l[maxn], ans[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; string s, p; cin >> s >> p; int n = s.size(), m = p.size(); for (int i = 0; i < n; i++) { int j = i, k = m - 1; if ...
14
#include <bits/stdc++.h> const int sent = -99999999; using namespace std; int goodFailFunction[51][26], badFailFunction[51][26]; int goodPrefixLen, badPrefixLen; int dp[1001][51][51]; string text, good, bad; int go(int textInd, int goodInd, int badInd) { if (goodInd == good.length()) return 1 + go(textInd, goodPrefix...
13
#include <bits/stdc++.h> using namespace std; string s[500005]; int x[500005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, i, j, k, l1, l2, flag; cin >> n; for (i = 1; i <= n; i++) { cin >> s[i]; x[i] = s[i].length(); } for (i = n - 1; i >= 1; i--) { l1 = x[i]; ...
10
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; int a, b, c, n, ans; int bn[300006]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> a >> b >> c >> n; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; if (tmp > b && tmp < c) ans++; } cout << ans...
0
#include <bits/stdc++.h> using namespace std; struct yts { int x, y; int a[110][110]; } M[110], ans; int n, x; char s[110]; int pre[110]; void mul(yts &a, yts &b, yts &c) { memset(ans.a, 0, sizeof(ans.a)); ans.x = ans.y = n + 1; for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) for (...
16
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > dp[200100]; int val[200100]; vector<vector<int> > g; int res; void ds(int v, int p) { vector<pair<int, int> > ch; for (int i = 0; i < g[v].size(); i++) { if (g[v][i] == p) { continue; } ds(g[v][i], v); for (int j = 0;...
16
#include <bits/stdc++.h> using namespace std; long long a1[5000001] = {}, sum[5000001] = {}; bool prime[5000001] = {}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a, b; cin >> b >> a; long long r = a - b; if (r >= 10) { cout << 0 << endl; return 0; } long long f = a; ...
3
#include <bits/stdc++.h> using namespace std; bool judge(int x) { int t = (int)sqrt(x); if (t * t == x) return true; else return false; } int main() { int a, b, flag = 0; cin >> a >> b; int max_num = max(a, b); int min_num = min(a, b); int ans_x1, ans_y1, ans_x2, ans_y2; for (int i = 1; i < mi...
8
#include <bits/stdc++.h> using namespace std; long long a[500010], b[500010]; long long inf = 1e13; int main() { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); int n = 0, k = 0; scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { scanf("%I64d", &a[i]); } for (int i = 1; i <= n; ++i) { scanf("...
21
#include <bits/stdc++.h> using namespace std; inline void upi(int& a, const int& b) { a > b ? a = b : 0; } inline void upa(int& a, const int& b) { a < b ? a = b : 0; } const int N = 1e5 + 5, BS = 355, BL = 305; int n, W, q, i, k, a[N], ans[N]; pair<int, int> qu[N]; inline void operator+=(pair<int, int>& a, const pair<i...
26
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long h[N], p[N], n, m; inline bool canVisit(long long head, long long start, long long end, long long time) { if (start > head) start = head; if (end < head) end = head; long long toLeft = head - start; long long toRi...
11
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; int t; cin >> t; while (t--) { cin >> n >> m; map<int, int> s; map<int, int> s1; vector<vector<int>> aa; vector<vector<int>> aa1; vector<int> d(n * m + 1); ...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; const long long INF = 1e18 + 10; int n, k; vector<pair<int, int>> e[MAX]; vector<pair<int, int>> cir; pair<int, int> par[MAX]; long long d[MAX], pre_diam[MAX], pre_far[MAX], suf_diam[MAX], suf_far[MAX], part_len[MAX]; bool visit[MAX]; int cir_s...
17
#include <bits/stdc++.h> int main() { long long N, K; std::cin >> N >> K; long long one = N / 2 / (K + 1); std::cout << one << " " << one * K << " " << N - one * (K + 1) << std::endl; }
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long t, n, k; void solve() { cin >> n >> k; long long a[n]; for (long long i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); if (k == n) { cout << a[n - 1] << endl; } else if (k == 0) { if (a[0] == 1) { cou...
4
#include <bits/stdc++.h> int n; int f[11][200001][11]; int sum[11]; void check(int i, int j, int q) { int stk[11]; stk[0] = 0; for (int k = 1; k < i; k++) if (f[i - 1][j][k] == k) stk[++stk[0]] = k; stk[++stk[0]] = i; if (q) for (int k = 1; k <= stk[0]; k++) { sum[i]++; for (int l = 1; l <...
15
#include "bits/stdc++.h" #define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define endl '\n' #define all(V) (V).begin(), (V).end() using namespace std; typedef long long ll; template <class T> struct bit1D { vector <T> bit; int N; bit1D(int _N) { N = _N; bit.resize(N); ...
14
#include <bits/stdc++.h> using namespace std; ofstream file("debug.txt"); template <typename Int> ostream &operator<<(ostream &s, const vector<Int> &v) { s << '['; for (auto i = v.begin(); i != v.end(); i++) { s << *i; if (i != prev(v.end())) s << ", "; } s << ']'; return s; } template <typename Int, ...
8
#include <bits/stdc++.h> using namespace std; template <typename T> void showArr(T *arr, int n) { for (int i = 0; i < n; i++) cout << arr[i] << ' '; puts(""); } const int MAXN = 1000007; const int MOD = 1000000007; const int SZ = 21; char s[2][MAXN]; int p[MAXN][SZ]; int bk[MAXN], dis[MAXN]; int main() { memset(p...
18
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx") using namespace std; const int mod = 1e9 + 7; vector<int> g[505]; vector<int> used(505); vector<int> mt(505); bool is[505][505]; int comp; bool dfs(int v) { if (used[v] == comp) return 0; used[v] = comp; for (int to : g[v]) { ...
14
#include <bits/stdc++.h> using namespace std; int n, arr[100]; bool hitung(int x, int val) { if (x == n) { if (val == 0) return true; else return false; } else { int kanan = (val + arr[x]) % 360; int kiri = (val - arr[x]) % 360; return ((hitung(x + 1, kanan)) or (hitung(x + 1, kiri))...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int n, s; int a[N], b[N]; int in[N], out[N]; int main() { cin >> n >> s; for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); in[u]++; out[v]++; in[v]++; out[u]++; } int cnt = 0; for (int i = 1; i <= n; i++) ...
9
#include <bits/stdc++.h> using namespace std; const int N = 600 + 15; const int inf = 1e9 + 7; int v, e, n, k; int dis[N][N], pos[N], match[N], mp[N][N], vis[N]; inline int read() { char ch = getchar(); int s = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch...
13
#include <bits/stdc++.h> using namespace std; template <typename T> void rd(T& x) { long long f = 0, c; while (!isdigit(c = getchar())) f ^= !(c ^ 45); x = (c & 15); while (isdigit(c = getchar())) x = x * 10 + (c & 15); if (f) x = -x; } template <typename T> void pt(T x, long long c = -1) { if (x < 0) putch...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; long long tot = 0; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } sort(a, a + n); for (int i = 0; i < n; ++i) { tot += a[n - i - 1] * 1LL * floor(((log10(n / (i + 1))) / log10(4)) + 1); } cout << tot <...
6
#include <bits/stdc++.h> using namespace std; int a[20], i = 0; int b[20]; int main() { int n, ans = 0; cin >> n; while (n) { a[++i] = n % 10; n /= 10; } int mx = a[1]; for (int j = 2; j <= i; ++j) { mx = max(mx * a[j], int(pow(9, j - 1)) * (a[j] - 1)); } cout << max(mx, int(pow(9, i - 1)));...
4
#include <bits/stdc++.h> using namespace std; vector<int> vertices[10001]; int find2P(int start) { int next; int count = 0; for (int i = 0; i < vertices[start].size(); i++) { next = vertices[start][i]; count += vertices[next].size() - 1; } return count; } int main() { int n, x, y; cin >> n; for ...
5
#include <bits/stdc++.h> using namespace std; const long long INF = std::numeric_limits<long long>::max(); const long long MOD = 1e9 + 7; const long double PI = 3.141592653589793; long long k, a, b, idx, idy, A[5][5], B[5][5], sa[1000], sb[1000]; map<pair<int, int>, int> m; bool scount(int x, int y) { return (x == y + ...
10
#include <bits/stdc++.h> using namespace std; int dp1[100005], dp2[100005]; int main() { string s; cin >> s; int l = 0, u = 0, n = s.length(); if (islower(s[0])) l = dp1[0] = 1; else u = dp2[0] = isupper(s[0]); for (int i = 1; i < n; i++) { if (islower(s[i])) l++; else u++; i...
6
#include <bits/stdc++.h> using namespace std; template <class T> void test(T a) { cout << a << endl; } template <class T, class T2> void test(T a, T2 b) { cout << a << " " << b << endl; } template <class T, class T2, class T3> void test(T a, T2 b, T3 c) { cout << a << " " << b << " " << c << endl; } template <cla...
13
#include <bits/stdc++.h> using namespace std; int p[110], q[110]; long long dp[110][40]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &p[i]); for (int i = 0; i < m; ++i) scanf("%d", &q[i]); long long pt = 0; sort(q, q + m); int e = 0; vector<long long> f, s; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m; int a[N]; int pr[N]; long long sum[N]; stack<pair<int, int> > st; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } for...
9