solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long long INF64 = (long long)1e18; const long double eps = 1e-9; const long double pi = 3.14159265358979323846; int nu[200]; int loc[200]; int main() { int i, j; int cnt; int n, qn; int q, a, b; while (cin >> n) { for (i = 1; i ...
9
#include <bits/stdc++.h> using namespace std; struct team { long long t; long long w; }; bool operator<(const team &a, const team &b) { return a.t > b.t; } int main() { int n; cin >> n; vector<team> t(n - 1); team d; cin >> d.t >> d.w; for (int i = 0; i < n - 1; ++i) cin >> t[i].t >> t[i].w; sort((t)....
10
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const long long MOD = 1e9 + 7; long long n_bits(long long n) { long long x = __builtin_popcount(n); return x; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long n, m...
6
#include <bits/stdc++.h> class SegmentTree { static const int64_t inf = 1LL << 61; size_t n; std::vector<int64_t> tree, oft, num; auto pow2_least(size_t n) -> size_t { size_t m; for (m = 1; m <= n; m <<= 1) { } return m; } void modify(size_t l, size_t r, int64_t x, size_t i, size_t a, size_t...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test; test = 1; while (test--) { int n, m; cin >> m >> n; ; char pres; cin >> pres; int count = 0; bool arr[26]; for (int i = 0; i < 26; i++) { arr[i] = 0; ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/stack:30000000") using namespace std; long long i, j, k, n, m, t, l, r, ans; long long s1, l1, s2, l2; int main() { long long h1, a1, h2, y2, y1, x2, x1, a2; cin >> m; cin >> h1 >> a1; cin >> x1 >> y1; cin >> h2 >> a2; cin >> x2 >> y2; for (i = 1; i < 2 *...
14
#include <bits/stdc++.h> using namespace std; const int inf = 1000000001; const int MOD = 1000000007; int n; vector<int> g[3039], gt[3039]; vector<bool> used; vector<int> order, comp; void dfs1(int v) { used[v] = true; for (size_t i = 0; i < g[v].size(); ++i) { int to = g[v][i]; if (!used[to]) dfs1(to); }...
22
#include <bits/stdc++.h> #define loc(x, y) ((x - 1) * m + y) #define lowbit(x) (x & -x) using namespace std; const int N = 6e5 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7; typedef long long ll; namespace fast_IO { ll read() { ll num = 0; char c; bool tag = false; while ((c = getchar()) != '...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, s, x, y, min = -1; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> x >> y; if ((x < s && 100 - y > min) || (x == s && y == 0)) if (y != 0) min = 100 - y; else if (min == -1) min = 0; } cout << min; retu...
4
#include <bits/stdc++.h> using namespace std; const int N = 510; int n, m; char tile[N][N]; bool possible() { int xmin = N, xmax = 0, ymin = N, ymax = 0; for (int x = 0; x < n; ++x) { for (int y = 0; y < m; ++y) { if (tile[x][y] == 'X') { xmin = min(xmin, x); xmax = max(xmax, x); y...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 300000000 + 5; bitset<maxn> vis; int main() { int a, b; scanf("%d%d", &a, &b); if (b < 2) return puts("0"); else { int ans = 0; if (a <= 2) ans = 1; int lim = sqrt(b); for (int i = 3; i <= lim; i += 2) if (!vis[i]) { ...
14
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using vpii = vector<pii>; using unt = unsigned int; int popc(unt a) { return __builtin_popcount(a); } int popc(int a) { return __builtin_popcount(a); } int popc(ll a) {...
22
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, w, x, c; scanf("%lld%lld%lld%lld%lld", &a, &b, &w, &x, &c); if (c <= a) printf("0\n"); else { long long cha = c - a; long long p1 = (cha - b / x) * x - b % x; long long p2 = w - x; long long p; if (p1 % p2 == 0) ...
12
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 300300; in...
12
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); int a, b; for (; t > 0; t--) { scanf("%d %d", &a, &b); if (a < b) { if ((b - a) % 2 > 0) printf("1\n"); else printf("2\n"); } else if (a > b) { if ((a - b) % 2 > 0) printf("2\n"); else ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1;; i++) { if (n - m * i < i) { puts("-1"); return 0; } if (__builtin_popcount(n - m * i) <= i) { printf("%d\n", i); return 0; } } return 0; }
8
#include <bits/stdc++.h> using namespace std; int n, len = 0, flen = 0; string a[100001]; char temp[100001], ans[100001]; void init() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", &temp); a[i] = temp; len = a[i].size(); if (len > flen) flen = len; for (int j = 0; j < len; j++) { ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 1000 + 10; int a[MAXN]; long long int mod = 1000 * 1000 * 1000 + 7; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int q; cin >> q; for (int i = 0; i < q; i++) { int a, b, c; cin >> a >> b >> c; int ans = ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n; cin >> n; if (n == 0) { cout << "1" << endl; } else { long long ans = n % 4; if (ans == 0) { cout << "6" << endl; } if (ans == 1) { cout << "8" << endl...
2
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; vector<long long> g[N]; long long n, m; bool vis[N]; void bfs(long long node) { queue<long long> q; q.push(node); vis[node] = 1; while (!q.empty()) { long long top = q.front(); q.pop(); for (long long i = 0; i < g[top].size()...
8
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
1
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } struct HLDecomposition { vector<set<int>> g; vector<int> vid, head, heavy, parent, depth, inv; HLDecomposition() {} HLDecomposition(int n) { init(n); } ...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int a[206]; void win() { int n, x, y; cin >> n >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; } if (x > y) { cout << n << endl; return; } sort(a, a + n); int sum = 0; for (int i = 0; i < n; i++) { if (a[i] <= x) { ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; int n, m; const int N = 1e5 + 5; vector<pair<long long, long long> > items; vector<pair<pair<long long, long long>, int> > person; ; long long dp[N][2][2]; map<int, int> mp; map<int, int> mp2; long long solve(int idx = 0, bool p1 = 0, bool p2 = 0...
17
#include <bits/stdc++.h> using namespace std; const int MaxN = 2e5 + 7; long long arr[MaxN], cum[MaxN]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 0; i < n; ++i) arr[i] += i; sort(arr, arr + n); for (int i = 0; i < n; ++i) arr[i] -= ...
14
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; vector<string> v; for (int i = 0; i < T; i++) { string s; cin >> s; v.push_back(s); } for (int i = 0; i < T; i++) { if (v[i].substr(v[i].size() - 2, 2) == "po") cout << "FILIPINO" << endl; else if (v[i].sub...
0
#include <bits/stdc++.h> using namespace std; struct node { int s, k, w; }; vector<node> q[3010]; int n, m, Q, x, y, z, head[3010], nex[3010], vet[3010], pre[3010], ans[400010], num, f[13][3010], u, t, id; void add(int x, int y) { vet[++num] = y; nex[num] = head[x]; head[x] = num; } void dfs(int v, int fa) ...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, m; double w; cin >> n >> w >> m; vector<double> v(n, w); vector<int> u(n, 0); double t = double(n) / m * w; vector<vector<pair<int, double>>> a(m); vector<double> b(m, 0); int j = 0; for (int i = 0; i < m; i++) { while (b[i] < t -...
11
#include <bits/stdc++.h> using namespace std; vector<int> v[100000]; map<int, bool> mp[100000][4]; bool dfs(int x, int y, int z) { int i; if (mp[x][z].count(y)) return mp[x][z][y]; if (v[x].size() == 1) return mp[x][z][y] = true; if (z <= 1) { int c = 0; for (i = 0; i < v[x].size(); i++) { if (v[x...
15
#include <bits/stdc++.h> using namespace std; int main() { printf("Karen"); }
3
#include <bits/stdc++.h> int n, m; int x[1000]; int main() { while (scanf("%d%d", &n, &m) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", x + i); double ans = 0; for (int j = 0; j < m; j++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); double v = x[a] + x[b]; if (v / c > ans) ans ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, ans = -1; cin >> n; vector<vector<int> > v(6); while (n--) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= 5; i++) { if (v[i].size() >= 3 || v[i].size() <= 1) { ans = 1; break; ...
5
#include <bits/stdc++.h> using namespace std; inline int mul(int a, int b) { return int(a * 1ll * b % 1000000007); } inline int norm(int a) { if (a >= 1000000007) a -= 1000000007; if (a < 0) a += 1000000007; return a; } inline int binPow(int a, int k) { int ans = 1; while (k > 0) { if (k & 1) ans = mul(an...
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, N = 105; int m, c[N], x, y, ans; int main() { scanf("%d", &m); int s = 0, sum = 0; for (int i = 0; i < m; i++) { scanf("%d", &c[i]); sum += c[i]; } scanf("%d%d", &x, &y); ans = 0; for (int i = 0; i < m; i++) { s += c[i];...
2
#include <bits/stdc++.h> using namespace std; const long long SZ = 2e5 + 4; const long long inf = 2e9; long long n, m; string s; void read() { cin >> n >> m >> s; } void solve() { long long curx = 0, cury = 0; long long mnx = 0, mxx = 0, mny = 0, mxy = 0; for (long long i = 0; i < s.size(); ++i) { if (s[i] ==...
8
#include <bits/stdc++.h> using namespace std; long long jp[70]; bool Query(long long x) { cout << "? " << x << endl; int t; cin >> t; return t; } int main() { int T; long long n; cin >> T; while (T--) { cin >> n; long long L = 1, R = n - 1, S = 1; int cnt = 0; while (L <= R) { S = ...
19
#include <bits/stdc++.h> inline long long read() { long long x = 0; char c = getchar(), f = 1; for (; c < '0' || '9' < c; c = getchar()) if (c == '-') f = -1; for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; return x * f; } inline void write(long long x) { static char buf[20]; int len...
22
#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...
13
#include <bits/stdc++.h> using namespace std; int main() { long long t1, t2, x1, x2, t0; cin >> t1 >> t2 >> x1 >> x2 >> t0; int A = 1, B = 1; double ans = 100000000000000007, a; if (t2 == t1 && t1 >= t0) { ans = t2; A = x1; B = x2; } if (t2 >= t0 && t1 < ans) { ans = t2; A = 0; B =...
11
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() #define sz(v) ((int)(v).size()) #define compress(v) sort(all(v)), (v).erase(unique(all(v)), (v).end()) #define MEM(v, x) memset(v,x,sizeof(v)) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = ...
0
#include <bits/stdc++.h> using namespace std; int main() { int* arr = new int[4]; for (int i = 0; i < 4; i++) cin >> arr[i]; string n; cin >> n; int count = 0; int j = n.length() - 1; while (j >= 0) { char cop = n[j]; int z = (int)cop - 48; count += arr[z - 1]; j--; } cout << count; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i, j, k, p, t; cin >> t; vector<long long int> vec; vector<pair<long long int, long long int>> ans; for (i = 0; i < t; i++) { cin >> n; for (j = 0; j < n; j++) { cin >...
4
#include <bits/stdc++.h> using namespace std; void solve(); int main() { srand(time(0)); cout.setf(ios::fixed); cout.precision(10); int tn = 1; for (int i = 0; i < tn; ++i) solve(); } int to[200001][26]; bool ok[200001][2]; const int root = 1; int nodes = 2; char s[1000001]; void dfs(int u) { bool term = tr...
11
#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...
7
#include <bits/stdc++.h> using namespace std; long long C, hr, hb, wr, wb; long long ans, cur; inline int Gcd(const int &x, const int &y) { return !y ? x : Gcd(y, x % y); } int main() { cin >> C >> hr >> hb >> wr >> wb; long long temp = (long long)wr * wb / Gcd(wr, wb); long long num = C / temp; C %= temp; if...
12
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9); int n; vector<vector<int>> g; bool dfs(int u, int p, int to, vector<int> &path) { if (u == to) return true; for (int v : g[u]) if (v != p) if (dfs(v, u, to, path)) { path.emplace_back(v); return true; } return ...
12
#include <bits/stdc++.h> using namespace std; void solve(long long cno) { long long n, k, i, j, l; cin >> n >> k; long long arr[n]; map<long long, long long> make_pair; set<long long> st; long long maxfreq = -1; long long min = 1000000007; long long max = -1; for (i = 0; i < n; i++) { cin >> arr[i...
6
#include <bits/stdc++.h> using namespace std; int R, C, r; int M[502][502], F[502], I[502], AC[502][502]; int S[502][502], MXI[502][502], MXD[502][502], CMXI[502][502], CMXD[502][502]; bool ISeg(pair<int, int> a, pair<int, int> b) { return (a.first - b.first) * (a.second - b.first) <= 0 || (b.first - a.secon...
17
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2,fma,sse2,sse3,ssse3,sse4,tune=native") using namespace std; const long long mod = 1000000007; mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); const int mxN = 2550; struct PT { lo...
17
#include <bits/stdc++.h> const int INF = 2147483647; const int MOD = 1000000007; const long long INF64 = 9223372036854775807; const long double EPS = 1e-7; using namespace std; int ans1[1000001], ans2[1000001]; int main() { int n, q, t, val; scanf("%d%d", &n, &q); int q0 = 0, q1 = 0; for (int i = 0; i < q; i++)...
10
#include <bits/stdc++.h> using namespace std; struct node { long long id; long long money; } a[3010]; long long r[3010][3010]; struct node2 { long long id; long long num; long long minn; long long p; } poi[3010]; bool cmp(const node &a, const node &b) { return a.money < b.money; } struct CMP { bool operat...
9
#include <bits/stdc++.h> using namespace std; int n, cnt; double ans, sum; int main() { while (scanf("%d", &n) != EOF) { cnt = 0; ans = 1e10; sum = 0.0; for (int i = 1; i <= 2 * n; i++) { double a; scanf("%lf", &a); if (a == (int)a) cnt++; else sum += a - floor(...
10
#include <bits/stdc++.h> using namespace std; int main() { string s1; string s2; cin >> s1; cin >> s2; int a[26] = {0}; int b[26] = {0}; for (int i = 0; i < s1.size(); i++) { a[s1[i] - 'a'] += 1; } for (int i = 0; i < s2.size(); i++) { b[s2[i] - 'a'] += 1; } int ans = 0; for (int i = 0; ...
4
#include <bits/stdc++.h> using namespace std; template <typename T> void printV(vector<T> A) { if (A.empty()) cerr << "EMTPY\n"; else { cerr << "["; for (int i = 0; i < A.size() - 1; ++i) { cerr << A[i] << ", "; } if (A.size()) cerr << A.back() << "]\n"; } } template <typename T> void pr...
8
#include <bits/stdc++.h> using namespace std; int n, k; char s[505]; int t[1000005][26] = {}, cnt[1000005] = {}, p[1000005], pind[1000005], dpos[1000005], mul[1000005]; bool used[1000005]; int sz = 1, dsz = 0; int d[5005][2005]; int f[2005], g[2005]; int main() { scanf("%d%d", &n, &k); cnt[0] = n; for (int i ...
17
#include <bits/stdc++.h> using namespace std; int nt; int n; string s; vector<int> a; vector<int> b; vector<int> ans; inline void init() { cin >> n; cin >> s; a.resize(n); for (int i = 0; i < n; ++i) { a[i] = static_cast<int>(s[i] - '0'); } } inline int check(int t, vector<int>& ans) { vector<int> b(2, ...
7
#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; int MOD = 1e9 + 7; const int N = 600000; int ss[N]; int sd[N][20]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; ...
14
#include <bits/stdc++.h> using namespace std; void printline(vector<int> v) { for (int i = 0; i < v.size(); i++) { if (i) cout << " "; cout << v[i]; } cout << endl; } void printcol(vector<int> v) { for (auto x : v) cout << x << endl; } string s; void build(int idx, int k, string base, string &ans, bool ...
3
#include <bits/stdc++.h> using namespace std; bool isprime(long long n) { if (n < 2) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0) return false; if (n % 3 == 0) return false; for (long long i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return tru...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; long long a[maxn], b[maxn]; long long l[maxn], r[maxn]; int main() { int n, k, ll, rr; while (scanf("%d%d", &n, &k) != EOF) { for (int i = 0; i < n; i++) { scanf("%I64d", &a[i]); } for (int i = 1; i < n; i++) { b[i - 1] =...
13
#include <bits/stdc++.h> using namespace std; long long X1, Y1, X2, Y2; long long V, T; long long VX, VY, WX, WY; long long DX, DY; double getpos(double tm) { double px = DX - min((double)T, tm) * VX - max(0.0, tm - T) * WX; double py = DY - min((double)T, tm) * VY - max(0.0, tm - T) * WY; return sqrt(px * px + p...
13
#include <bits/stdc++.h> using namespace std; int main() { char x[1000]; cin >> x; x[0] = toupper(x[0]); cout << x << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; char str[1005]; int main() { scanf("%s", str); int len = strlen(str); int prev = 0; int ans = 0; int temp; for (int i = 0; i < len; i++) { temp = abs((str[i] - 'a') - prev); if (temp > 13) temp = 26 - temp; ans += temp; prev = (str[i] - 'a'); }...
0
#include <bits/stdc++.h> using namespace std; vector<char> s; int main() { int n, c = 0, x; char a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; s.push_back(a); } x = 0; for (size_t i = 0; i < s.size(); i++) { if (s[i] == 'x') { x++; } while (x == 3) { for (size_t j = ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; string s, t; int q; int trailingS[maxn], trailingT[maxn], bS[maxn], bT[maxn], trailingCnt = 0, bCnt = 0; int main() { cin >> s >> t >> q; for (int i = 0; i < s.size(); i++) { if (s[...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; const int mod = 1e9 + 7; const int inf = 1e9 + 7; pair<int, int> t[N * 4]; void upd(int v, int l, int r, int pos, int val) { if (l == r) { t[v] = make_pair(val, l); return; } int mid = (l + r) / 2; if (pos <= mid) upd(v * 2, l, mid...
18
#include <bits/stdc++.h> using namespace std; void hora() { time_t t; time(&t); struct tm* petm = localtime(&t); FILE* pfile; pfile = fopen("compilaciones.txt", "a"); fprintf(pfile, " \n"); fprintf(pfile, "compil�: %s\n", asctime(petm)); fclose(pfile); } int a[20][20]; int b[20]; int used[1001]; int act...
15
#include <bits/stdc++.h> using namespace std; long long n, m, minWt = 0, par[200005], siz[200005]; vector<pair<pair<long long, long long>, pair<long long, long long> > > edg; vector<pair<long long, long long> > myTree[200005]; bool vis[200005], pres[200005]; long long dep[200005], dp1[200005][20], dp2[200005][20], best...
13
#include <bits/stdc++.h> using namespace std; template <typename T1> void print_list(const T1& a) { cerr << a << endl; } template <typename T1, typename T2> void print_list(const T1& a, const T2& b) { cerr << a << " " << b << endl; } template <typename T1, typename T2, typename T3> void print_list(const T1& a, cons...
12
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; register char ch; register bool fl = 0; while (ch = getchar(), ch < 48 || 57 < ch) fl ^= ch == '-'; x = (ch & 15); while (ch = getchar(), 47 < ch && ch < 58) x = (x << 1) + (x << 3) + (ch & 15); if (fl) x = -x; } template <...
8
#include <bits/stdc++.h> using namespace std; inline int read() { register int s = 0, t = 0; register char ch = getchar(); while (ch > '9' || ch < '0') t |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return t ? -s : s; } long long n, m, f...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, ans = 1; cin >> n >> m; set<long long int> s[m]; for (long long int i = 0; i < n; i++) { string a; cin >> a; for (long long int j = 0; j < m; j++) { s[j].insert(a[j]); } } for (long long int i = 0; i < m; i+...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0xFFFFFFF; int n; int a[3005], b[3005], c[3005]; int dp[3005][2] = {0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i...
10
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); const double EPS = 1E-5; const int INF = 2 * (1e+9) + 1; const int NMAX = 32000; const int MOD = (1e+9) + 7; int n; string s; long long dp[1000100][5]; int main() { cin >> s; int n = (long long)(s).size(); if (s[0] == '0') dp[0][...
11
#include <bits/stdc++.h> int n, m, ttt = 0, tb; int a[10]; bool b[10]; int ans = 0; void dfs(int x) { if (x > ttt) { int i = tb; int tt = 1, t2 = 0; for (int j = i; j >= 1; j--) { t2 = t2 + a[j] * tt; tt *= 7; } if (t2 >= n) return; tt = 1, t2 = 0; for (int j = ttt; j > i; j--)...
9
#include <bits/stdc++.h> using namespace std; int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; char dc[4] = {'N', 'S', 'W', 'E'}; int main() { string s; int n; cin >> s; n = s.size(); cout << "3\n"; cout << "R " << n - 1 << endl; cout << "L " << n << endl; cout << "L 2\n"; }
6
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > e[100005]; long long dis[100005]; int dfn[100005], ed[100005], dfs_cnt; void dfs1(int x) { dfn[x] = ++dfs_cnt; for (int i = 0; i < e[x].size(); i++) { int u = e[x][i].first; dis[u] = dis[x] + e[x][i].second; dfs1(u); } ...
23
#include <bits/stdc++.h> using namespace std; vector<long long> G[100001]; int chk[100001]; bool bfs(long long start) { queue<long long> q; q.push(start); chk[start] = 0; while (!q.empty()) { long long top = q.front(); q.pop(); for (int i = 0; i < G[top].size(); i++) { if (chk[G[top][i]] == -1...
7
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int count = 1, val = s[0], flag = 0; for (int i = 1; i < s.size(); i++) { if (s[i] != val) { val = s[i]; if (count >= 7) { flag = 1; } count = 0; } count++; } if (flag || count >= 7) ...
1
#include <bits/stdc++.h> using namespace std; int num[100100]; string str; int zimu[30]; int res[30]; int main() { memset(num, 0, sizeof(num)); memset(zimu, 0, sizeof(zimu)); cin >> str; int len = str.length(); int end = -1; for (int i = 26; i >= 1; --i) { for (int j = 0; j < len; ++j) if (str[j] ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int lft, rght, n, n2, sz, p, p2, tmp, q, k, cnt[30], c[330][30], t[330], a[N]; char ch; void cntSort(int lft, int rght) { int c[30]; for (int x = 0; x < 26; x++) c[x] = 0; for (int i = lft; i <= rght; i++) { c[a[i]]++; } for (int i = lf...
15
#include<bits/stdc++.h> using namespace std; typedef pair<long long int,long long int> pi; int n; vector<pi> lstProducts; void print() { for (int i = 0; i < lstProducts.size(); i++) { cout << lstProducts[i].first << " "; } cout << "\n"; for (int j = 0; j < lstProducts.size(); j++) { cout << lstProducts[j].se...
8
#include <bits/stdc++.h> clock_t t_; using namespace std; template <class T> void print(T s) { cout << s << "\n"; } template <class T> void emax(T &a, T b) { a = (a < b ? b : a); }; template <class T> void emin(T &a, T b) { a = (a > b ? b : a); } template <class T> void printC(T s) { for (auto &x : s) { cou...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int u, v, t, d, i, j, ans, s; while (cin >> s >> v) { u = s; cin >> t >> d; if (d == 0) { printf("%lld\n", u * t); continue; } long long int xx[t + 1], yy[t + 1]; for (i = 1; i <= t; i++) { xx[i] = u; ...
6
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point() { x = y = 0.0; } point(double _x, double _y) : x(_x), y(_y) {} bool operator<(point other) const { if (fabs(x - other.x) > 1e-9) return x < other.x; return y < other.y; } bool operator>(point other) const { if (fab...
10
#include <bits/stdc++.h> long long n, k, m; long long dp[1010][110][2], pw[1010], PW[1010]; long long Solve(long long p, long long r, int f) { if (p <= 0) return f; if (~dp[p][r][f]) return dp[p][r][f]; if (f) return (9LL * PW[p - 1]) % m; long long res = 0; for (int i = ((p == 1) ? 1 : 0); i <= (9); ++i) { ...
14
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t;ll len; cin>>t; while(t--) { string s; cin>>s; len=s.size(); cout<<len<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t = 1, n; string s; cin >> t; while (t--) { cin >> n; vector<long long> v(n); map<long long, long long> mp; for (int i = 0; i < n; ++i) { cin >> v[i]; mp[v...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 1e5 + 5; long long powermodm(long long x, long long n, long long M) { long long result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } long ...
6
#include <bits/stdc++.h> using namespace std; int ans = 0; bool found[6667] = {0}; int Turn(int tt) { found[tt] = true; return (tt % 1000) * 10 + tt / 1000; } int main() { int n; scanf("%d", &n); char s[10]; for (int i = 0; i < n; i++) { if (i > 0) scanf("%s", s); int now = 0; scanf("%s", s); ...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int mod = 1e9 + 7; const int modp = 1999999973; int t, n, a[200005], tu[200005]; int32_t main() { ios_base::sync_with_stdio(false);...
5
#include <bits/stdc++.h> using namespace std; const int kNmax = 3e5 + 5; int n, m; int bcc[kNmax]; int num_bcc; int use[kNmax]; vector<int> g[kNmax]; vector<pair<int, int>> gt[kNmax]; int l[kNmax], r[kNmax], z[kNmax]; int depth[kNmax], lowlink[kNmax]; bool artifact[kNmax]; stack<int> s; void dfs_bcc(int x, int f = 0) {...
15
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, ara[26] = {0}, ar[26] = {0}, c = 1, l1, l2, l3; string s, si, sii; cin >> s >> si >> sii; l1 = s.size(); l2 = si.size(); l3 = sii.size(); if (l1 + l2 != l3) printf("NO"); else { for (i = 0; i < l1; i++) { ara[s[i] - 'A...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 7; vector<pair<int, int> > v[maxn]; long long dist[maxn], ver[2][maxn]; int n, q, ss, tme; set<pair<long long, int> > s; int build(int y, int l, int r, int x) { if (l == r) return ver[x][y] = l; ver[x][y] = ++tme; int mid = (l + r) / 2; int cl...
15
#include <bits/stdc++.h> using namespace std; int lenA, lenB; int A[1000004]; int B[1000004]; int idxB[1000004]; int lenP = 0, idxP = 0; long long P[1000004 * 2]; int main() { scanf("%d %d", &lenA, &lenB); for (int i = 0, _n = (lenA); i < _n; ++i) scanf("%d", A + i); memset(idxB, -1, sizeof(idxB)); for (int j =...
12
#include <bits/stdc++.h> using namespace std; long long a, b, n; inline long long getint() { long long ret = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret * f; } inlin...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ar[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> ar[i][j]; long long b = sqrt((ar[0][1] * ar[1][2]) / ar[0][2]); for (long long k = 0; k < n; k++) { if (k == 1) cout << b << " ";...
5
#include <bits/stdc++.h> using std::cin; using std::cout; using std::string; using std::vector; const int maxn = 200200; struct name { int id; inline name() {} inline name(string s) { s.resize(4); id = *(int *)s.data(); } }; inline int operator<(const name &x, const name &y) { return x.id < y.id; } inli...
19
#include <bits/stdc++.h> using namespace std; const int MAXK = 15; int k; vector<int> a[MAXK]; map<long long, int> ma[MAXK]; long long sum[MAXK]; vector<pair<int, int> > target[MAXK]; vector<pair<int, int> > cyc[1 << MAXK]; bool dp[1 << MAXK]; int trace[1 << MAXK]; pair<int, int> ans[MAXK]; int main() { long long req...
16