solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; using ll = long long; ll fmax(ll a, ll b) { return a > b ? a : b; } ll fmin(ll a, ll b) { return a < b ? a : b; } ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); while (a % b) { ll t = a % b; a = b; b = t; } return b; } bool isPrime(ll n) { if (n <= ...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string a[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int n, b; cin >> n; for (int i = 0...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool p = false; for (int i = 1; i < s.size() - 1; ++i) { if (s[i - 1] == '.' || s[i] == '.' || s[i + 1] == '.') continue; if (s[i - 1] != s[i] && s[i] != s[i + 1] && s[i - 1] != s[i + 1]) { p = true; } } if (p) ...
1
#include <bits/stdc++.h> using namespace std; int n, m, cc = 1; vector<int> c, cur, z; vector<vector<int>> adj1, adj2; void dfs(int s, int p) { for (auto i : adj1[s]) { if (c[i] != -1) cur.push_back(c[i]); else z.push_back(i); } sort(cur.begin(), cur.end()); int x = 0, pos = 0; while (z.si...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; long long int po(long long int a, long long int b, long long int mod) { if (b == 0) { return 1; } long long int x = po(a, b / 2, mod); x = (x * x) % mod; ...
11
#include <bits/stdc++.h> using namespace std; struct F { int b; int p; int mx; bool operator<(const F &o) const { return p < o.p || (p == o.p && b < o.b); } }; int get_mxb(const F *a, int n, int r) { int f = 0, t = n; while (f < t) { int m = f + (t - f) / 2; if (a[m].p <= r) f = m + 1; els...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:267386880") using namespace std; vector<int> d[1005]; int count(int wh, int to) { int ans(lower_bound((d[wh]).begin(), (d[wh]).end(), to) - d[wh].begin()); if (binary_search((d[wh]).begin(), (d[wh]).end(), to)) ++ans; return ans; } int count(int wh, int fro...
9
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define endl '\n' #define lli long long int #define ld long double #define p_b push_back #define m_p make_pair #define fs first #define sc second #define sz(x) ((lli)x.size()) #define all(x) x.beg...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; long long second, first; cin >> n >> first >> second; pair<long long, long long> segs[n]; for (int i = 0; i < n; i++) { cin >> segs[i].first >> segs[i].second; } sort(segs, segs + n); priority_queue<long long, vector<long long>, great...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int clr[MAXN + 5], n; vector<int> v[MAXN + 5]; int d[10][MAXN + 5]; bool tag[10]; void get_dist(int x) { queue<int> que; for (int i = 0; i < 8; i++) tag[i] = false; for (int i = 1; i <= n; i++) d[x][i] = MAXN + 5; for (int i = 0; i < v[x].si...
25
#include <bits/stdc++.h> using namespace std; int a[100500]; vector<int> gr[100500]; char res[100500]; int p[100500]; char x[100500]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; p[a[i]] = i; } for (int i = 1; i <= n; i++) { int d = a[i]; for (int j = i; j >= 1; j ...
8
#include <bits/stdc++.h> using namespace std; int n, k, i, j, a[35005], dp[51][35005], pre[35005], last[35005]; int aint[132000], lazy[132000], pos[35005]; unordered_set<int> S; void update(int k) { aint[k] = max(aint[k << 1], aint[(k << 1) + 1]) + lazy[k]; if (k > 1) update(k >> 1); } void update_lazy(int k, int x...
14
#include <bits/stdc++.h> using namespace std; const int MN = 100004; int sum, n, aux; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &aux); sum += aux; } printf("%d\n", n - 1 + (sum % n == 0)); }
5
#include <bits/stdc++.h> using namespace std; vector<long long int> fac((long long int)(1e2 + 5), 1); long long int exp(long long int a, long long int b) { if (!b) return 1; if (b & 1) return a * exp(a, b - 1) % (long long int)(1e9 + 7); long long int t = exp(a, b / 2); return t * t % (long long int)(1e9 + 7); ...
11
#include <bits/stdc++.h> using namespace std; int main() { int u, n, k, x, ans = 0; scanf("%d%d%d", &n, &k, &x); for (int i = 0; i < n - k; ++i) { scanf("%d", &u); ans += u; } ans += k * x; printf("%d\n", ans); return 0; }
0
#include <bits/stdc++.h> const long long md = 1e9 + 7; const int Inf = 1e9; const long long Inf64 = 1e18; const long long MaxN = 1e5 + 10; const long long LogN = 25; const long long MaxM = 5e5 + 10; const long double eps = 1e-7; const long long dx[4] = {0, 1, 0, -1}; const long long dy[4] = {1, 0, -1, 0}; const long lo...
12
#include <bits/stdc++.h> using namespace std; bool cmp(char a[2][2], char b[2][2]) { if (a[0][0] == b[0][0] && a[0][1] == b[0][1] && a[1][0] == b[1][0] && a[1][1] == b[1][1]) return true; else return false; } int main() { char a[2][2], b[2][2], ans[2][2]; int k, i, j, x, y; for (i = 0; i < 2; i+...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e4; const int INF = 1e8; int n, P, M; int rt, son[N][2], size[N], val[N]; int dp_max[N][200], dp_min[N][200]; char s[N]; void process() { rt = 0; n = strlen(s); stack<int> st; for (int i = 0; i < n; i++) { if (s[i] == ')') { ++rt; son[...
15
#include <bits/stdc++.h> using namespace std; using LL = long long; void FindAnsAB(const string& s, const string& t, vector<pair<int, int>>& ans) { bool rv = false; int n = s.size(), m = t.size(); for (int i = n - 1, j = m - 1;;) { if (rv) { while (i >= 0 && s[i] == 'b') --i; while (j >= 0 && t[j]...
20
#include <bits/stdc++.h> using namespace std; const int N = 30 + 5; int n, L; long long a[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> L; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) a[i] = min(a[i], a[i - 1] * 2); for (int i = n; i <= 30; i++) a[...
8
#include <bits/stdc++.h> using namespace std; multiset<pair<pair<long long, int>, long long> > ms; int dfs(int i, int p, vector<vector<pair<int, pair<long long, int> > > > &adj) { int cnt = 0; if (adj[i].size() == 1 && adj[i][0].first == p) { return 1; } for (auto ch : adj[i]) { if (ch.first != p) { ...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 41, M = 1 << 7; int dp[MAXN][M][M], n, m; bool can[MAXN][M][M]; bool ch(int l, int mid, int r) { for (int i = 0; i < m; i++) { if (((l >> i) & 1) || ((mid >> i) & 1) || ((r >> i) & 1)) continue; if (i > 0 && ((mid >> (i - 1)) & 1)) continue; i...
13
#include <bits/stdc++.h> using namespace std; int main() { char str[100010], str1[100010]; vector<char> vec; vector<char> vec1; vector<char>::iterator it; long i, j, k; while (gets(str)) { gets(str1); vec.assign(str, str + strlen(str)); vec1.assign(str1, str1 + strlen(str1)); sort(vec1.begin...
3
#include <bits/stdc++.h> using namespace std; char second[1009]; int n, l, i, j, k, n_pr, n_t, maxi, max_n; int a[1009], pr[1009], d[1009]; pair<char, int> c[1009]; bool p[1009], u[1009]; bool cmp(pair<char, int> a, pair<char, int> b) { return a.second > b.second; } int find() { for (int i = 1; i <= n_t; i++) if ...
5
#include <bits/stdc++.h> using namespace std; const long long M = 3e5 + 1000, N = 3e5 + 1000; vector<pair<int, int> > so[M], sol[M]; set<int> s; long long n, w, h, q = 1e5, r[N], o, p, t[M], x[N], y[N], xp[N], yp[N], l, e = 0, d = 0, rd[N], pd[N]; int main() { ios::sync_with_stdio(false), cin.tie(0...
11
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long ans = (n / 5) * (m / 5); for (int i = 1; i <= 4; i++) { long long k1 = (n + 5 - i) / 5; long long k2 = (m + i) / 5; ans += 1ll * k1 * k2; } cout << ans; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int maxn = 20; double pi = 3.1415926535897; double dp[1 << maxn]; int n, L, R; int lp[maxn], rp[maxn]; int ang[maxn]; int main() { cin >> n >> L >> R; for (int i = 0; i < n; i++) { cin >> lp[i] >> rp[i] >> ang[i]; } double ans = L; int sN = (1 << n); f...
14
#include <bits/stdc++.h> using namespace std; int n; struct bit { int v[200000]; bit() { memset(v, 0, sizeof v); } int query(int p) { int resp = 0; for (int i = p; i > 0; i -= (i & (-i))) resp = max(resp, v[i]); return resp; } void set(int p, int val) { for (int i = p; i < 200000; i += (i & (-...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 2; int a[maxn], b[maxn * maxn], c[maxn * maxn], dem = 0, ans = 0; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { for (i...
4
#include <bits/stdc++.h> using namespace std; struct point { int x; int y; }; point dates[500005]; bool cmp(point a, point b) { if (a.y < b.y) { return true; } if (a.y == b.y) { return a.x < b.x; } return false; } int main() { cin.sync_with_stdio(false); int n; cin >> n; for (int i = 0; i ...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int INF = 0x3f3f3f3f; const long long mod = 998244353; const double PI = acos(-1.0); int main() { std::ios::sync_with_stdio(false); int T; while (cin >> T) { while (T--) { int n; cin >> n; n = n * 2; int ans...
8
#include <bits/stdc++.h> using namespace std; int arr1[107], arr2[107]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n, m; cin >> n >> m; for (int i = 0; i <= n; i++) cin >> arr1[i]; for (int i = 0; i <= m; i++) cin >> arr2[i]; int a = arr1[0], b = arr2[0]; if (...
6
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define dd double #define ld long double #define sl(n) scanf("%lld", &n) #define si(n) scanf("%d", &n) #define sd(n) scanf("%lf", &n) #d...
14
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long a[n + 1][n + 1]; long long cost[n + 1][n + 1]; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= n; j++) { cin >> a[i][j];...
11
#include <bits/stdc++.h> using namespace std; struct arr { int a[9]; arr() { memset(a, 0, sizeof a); } void out(int k) { if (k > 1000) return; printf("%d =", k); for (int i = 0; i < 9; i++) printf(" %d", a[i]); puts(""); } bool chk() { if (a[0] == 3 && a[1] == 0 && a[2] == 2 && a[3] == 3 &...
17
#include <bits/stdc++.h> namespace solution { class SolutionInterface { public: virtual int run() = 0; protected: virtual void pre_calc() {} virtual bool action() = 0; virtual void init(){}; virtual bool input() { return false; }; virtual void output(){}; SolutionInterface() {} private: }; } // name...
12
#include <bits/stdc++.h> using namespace std; void test() { int n, it; long long int w; cin >> n >> w; long long int half = (w + 1) / 2; vector<pair<int, int>> item; item.resize(n); for (int i = 0; i < n; ++i) { cin >> it; item[i] = make_pair(it, i + 1); } sort(item.rbegin(), item.rend()); l...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; string s; cin >> n >> s; int x = count(s.begin(), s.end(), '('); if (x != n - x) { cout << "-1\n"; return 0; } vector<int> l, r; int ans = 0; for (int i = 0; i < n; i++) { i...
5
#include <bits/stdc++.h> using namespace std; long long dp[1009][109][2]; long long mod10n[1009]; long long m, n, k; long long f(int digitCount, int modk, int suff, int digit) { if (digitCount == n) { if (digit == 0) return 0; return suff; } if (dp[digitCount][modk][suff] != -1) return dp[digitCount][modk...
14
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int n; double a, d; double t[111111], v[111111]; double get_time(double v) { double x = v * v / (2 * a); if (x >= d) return sqrt(2 * d / a); else return v / a + (d - x) / v; } int main() { scanf("%d%lf%lf", &n, &a, &d); for (int i ...
8
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 55; long long sum[N << 2]; long long cnt[N << 2]; void PushUp(long long rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; cnt[rt] = cnt[rt << 1] + cnt[rt << 1 | 1]; } void upedit(long long L, long long R, long long c, long long l, long long r, ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int arr[122] = {0}, x; while (a--) { cin >> x; arr[x] = 1; } while (b--) { cin >> x; } for (int i = 1; i <= n; i++) { if (arr[i] == 1) { cout << "1 "; } else { cout << "2 "; } ...
0
#include <bits/stdc++.h> using namespace std; struct s { int id; long long int x; } a[200005]; int pos[200005]; int cmp(const s &a, const s &b) { return a.x > b.x; } int main() { int t; scanf("%d", &t); while (t--) { int n; long long int w; int cnt = 0; scanf("%d %lld", &n, &w); for (int i...
5
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; void fast() { std::ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } char grid[100][100]; vector<pair<int, int>> edg; bool vis[50][50]; int n, m; void dfs(int x, int...
9
#include <bits/stdc++.h> using namespace std; inline void update(int64_t &A, int64_t B) { if (A > B) A = B; } int64_t dp[2][500][500][2]; vector<pair<int, int>> robot[500][500]; bitset<500000> good[4]; int d[500000], e[500000]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >>...
18
#include <bits/stdc++.h> using namespace std; int cnt[150]; int main() { int v1, v2; cin >> v1 >> v2; int t, d; cin >> t >> d; int ans = v1; int temp = v2; for (int i = t - 1; i >= 2; i--) { temp = temp + d; int temp1 = v1 + d * (i - 1); int best = min(temp, temp1); ans += best; } cout...
6
#include <bits/stdc++.h> using namespace std; long long fast_pow(long long x, long long p, long long P) { if (p == 0) return 1; long long res = fast_pow(x, p / 2, P); if (p & 1) return (res * res * x) % P; else return (res * res) % P; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.t...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 10; const long long INF = 1e18; long long n; int m; long long a[MAXN]; long long v[100]; long long cnt[100]; bool vis[100]; map<long long, int> mpa; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int ...
11
#include <bits/stdc++.h> using namespace std; int s[6]; int main(void) { int i, x, ans; for (i = 1; i <= 5; i++) { scanf("%d", &x); s[i] = 500 * i * (250 - x) / 250; } ans = 0; for (i = 1; i <= 5; i++) { scanf("%d", &x); s[i] -= 50 * x; s[i] = max(150 * i, s[i]); ans += s[i]; } sca...
2
#include <bits/stdc++.h> using namespace std; const int MX = 2750131; int a[MX + 111], grdiv[MX + 110], isp[MX + 111], cnt[MX + 111]; int pr[MX + 111]; bool P(int n) { return !isp[n]; } int Gr(int n) { vector<int> v; for (long long i = 2; i * i <= n; i++) { while (n % i == 0) { n /= i; v.push_back(i...
10
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } const int MAXN = 2e5 + 5; cons...
13
#include <bits/stdc++.h> using namespace std; const int maxp = 7, maxpm = 2 * 3 * 5 * 7 * 11 * 13 * 17, maxx = 5e6; int phi[maxpm + 1][maxp + 1], p[maxp + 1], sp[maxx], cachepi[maxx], primes[maxx], sz = 0; int sqrt2(long long x) { long long r = (long long)sqrt(x - 0.1); while (r * r <= x) ++r; return int(r - ...
16
#include <bits/stdc++.h> int main() { long long m, b, y; long long max = 0; scanf("%lld%lld", &m, &b); for (y = b; y >= 0; y--) { long long sum = 0; sum += m * (b - y) * (m * (b - y) + 1) * (y + 1) / 2 + y * (y + 1) * (m * (b - y) + 1) / 2; if (sum > max) max = sum; } printf("%lld", m...
5
#include <bits/stdc++.h> using namespace std; int n, m; long long v[3005]; basic_string<int> e[3005]; vector<pair<int, long long>> dfs(int x, int p) { vector<pair<int, long long>> dp = {{0, v[x]}}; for (int y : e[x]) { if (y == p) continue; auto v = dfs(y, x); vector<pair<int, long long>> tmp(dp.size() ...
17
#include <bits/stdc++.h> using namespace std; vector<int> G[300005]; int state[300005] = {}; int dp[300005][27] = {}; char a[300005]; bool check(int now) { state[now] = 2; for (int x : G[now]) { if (state[x] == 2) return 0; if (state[x] == 0 && !check(x)) return 0; } state[now] = 1; return 1; } void d...
9
#include <bits/stdc++.h> using namespace std; int totCost = 0; int P[2003], target[2003], posInTarget[2003], n; int best[2003], ansLen, ans1[2003 * 2003 / 2], ans2[2003 * 2003 / 2]; int getBest(int i, int j) { if (P[i] > P[j]) return i; return j; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_std...
15
#include <bits/stdc++.h> const int mo = 1000000007; const int inf = 0x3f3f3f3f; double pi = 3.14159265358979323846; double e = 2.71828182845904523536; using namespace std; int main() { int arr[1005]; int n, a, b, c, t; cin >> n >> a >> b >> c >> t; long long sum = 0; for (int i = 0; i < n; i++) { cin >> a...
5
#include <bits/stdc++.h> using namespace std; int val[100010], vl[100010], vr[100010], res, far[100010], n, dl[100010], tag[2][400010], sum[2][400010]; int tdl[2][100010]; map<int, int> mp; int read() { int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fh = -1; c = ge...
27
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); long long read_long() { long long ans = 0; char c; bool started = false; bool is_negative = false; while (true) { c = getchar(); if ((c < '0' || c > '...
6
#include <bits/stdc++.h> using namespace std; long long int b, q, l, m, a[100100], cnt; map<long long int, long long int> is; int main() { cin >> b >> q >> l >> m; for (int i = 1; i <= m; i++) { scanf("%I64d", &a[i]); is[a[i]] = 1; } if (b == 0) { if (is[0]) cout << "0\n"; else cout ...
9
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9, maxn = (int)1e5 + 1; const double eps = (double)1e-8; int main() { bool f; string a; int b[20], j, t, o; cin >> t; while (t > 0) { o = 0; t--; cin >> a; for (int i = 1; i <= 12; i++) if (12 % i == 0) { f = 0;...
2
#include <bits/stdc++.h> using namespace std; long long n, m; long long ar[200005], tmp[200005]; long long lowest = 0; pair<long long, long long> br[200005]; bool can(long long cur) { long long mn = 0; long long ind = m - 1; for (long long i = 0; i < m; i++) { if (br[i].first > cur) { ind = i - 1; ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; const int maxlen = 1005; char temp[maxlen]; int a[maxlen], b[maxn][maxlen]; int n, c[maxn], f[2][maxn], lena, len[maxn], cur, sz[10], lenmax; int rk[2][maxn], pos[2][maxn]; int main() { int i, j, ans, num, jinwei; scanf("%s%d", temp, &n); for (i...
22
#include <bits/stdc++.h> using namespace std; template <typename T> void takearray(vector<T> &a, long long int n) { T y; for (long long int i = 0; i < n; i++) { cin >> y; a.push_back(y); } } template <typename T> void print1d(vector<T> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i...
5
#include <bits/stdc++.h> using namespace std; template <class T> struct rge { T b, e; }; template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; } struct debug { template <class T> debug& operator<<(const T&) { return *this; } }; using ll = long long; template <typename T> void min_self(T& a, T b...
12
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } void factors(long long n, vector<long long> &v) { for (long long i = 1; i * i <= n; i++) { if (n % i == ...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") const int maxn = 100010; int n, m, a[maxn]; void print(int x) { if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i...
23
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9, M = 50 + 9; long long bit[M][N]; long long query(int rem, long long val) { long long total = 0; while (val) { total += bit[rem][val]; val -= (val & (-val)); } return total; } void update(int rem, int val, long long nw) { while (val <...
11
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 3; const char* inf[] = {"none", "any", "at least one"}; int f[N], dfn[N], low[N]; int n, m, idx; int res[N]; vector<pair<int, int> > p[N]; struct Tuple { int x, y, d, idx; bool operator<(const Tuple& t) const { return d < t.d; } } msg[N]; void ini...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 510; int n, m; bool mark[maxn][maxn], a[maxn][maxn]; pair<int, int> par[maxn][maxn]; vector<string> v; void dfs1(int x, int y) { mark[x][y] = 1; if (!a[x][y]) v.push_back("1"); a[x][y] = 1; for (int i = x + 1; i < n; i++) if (a[i][y] == 1 && !ma...
16
#include<bits/stdc++.h> using namespace std; int a[26]; int b[26]; int main(){ int t; cin>>t; while(t--){ for(int i=0;i<26;i++)a[i]=0; for(int i=0;i<26;i++)b[i]=-1; string s; cin>>s; string ans=""; for(int i=0;i<s.length();i++){ b[s[i]-'a']=i; } for(int i=0;i<s.length();i++){ ...
12
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; char ch = getchar(), w = 1; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * w; } void write(...
13
#include <bits/stdc++.h> using namespace std; long long int i, j, k, n, m, s, sa, l, a, b, t[3], kk; bool f(long long t1, long long t2, long long t3, long long n, long long m) { long long int t[3] = {t1, t2, t3}; sort(t, t + 3); m -= t[0] + t[1] + t[2]; if (t[0] < 0) m += t[0] * 3; if (m < 0 || (m > 0 && (m %...
9
#include <bits/stdc++.h> using namespace std; long long int arr[11111], ans = 1e18; bool vis[10001][1001]; struct inf { long long int c, x, k; }; int main(void) { long long int n, m, f1, f2; scanf("%lld%lld", &n, &m); for (int e = 0; e < m; e++) scanf("%lld", &arr[e]); sort(arr, arr + m); scanf("%lld%lld", ...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int dp[MAXN], type[MAXN]; int n, k; bool flag[MAXN]; vector<int> G[MAXN]; int dp_dfs(int x) { if (!flag[x]) return dp[x] = 1; int temp; if (type[x] == 1) { temp = 1 << 30; for (int i = 0; i < G[x].size(); ++i) { temp = min(temp, ...
11
#include <bits/stdc++.h> int main() { int a, b, c, d, e; scanf("%1d%1d%1d%1d%1d", &a, &b, &c, &d, &e); long long int n = 10000 * a + 1000 * c + 100 * e + 10 * d + b, ret = 1; for (int i = 0; i < 5; i++) ret = (ret * n) % 100000; printf("%05lld\n", ret); return 0; }
6
#include <bits/stdc++.h> using namespace std; const int N = 500005; int ne[N << 1], fi[N], zz[N << 1], a[N], x, y, fa[N][20], n, tot; long long ans; void jb(int x, int y) { ne[++tot] = fi[x]; fi[x] = tot; zz[tot] = y; } void dfs(int x, int y) { fa[x][0] = y; for (int i = fi[x]; i; i = ne[i]) if (zz[i] != ...
20
#include <bits/stdc++.h> using namespace std; bool compare(const pair<long long, long long>& lhs, const pair<long long, long long>& rhs) { return lhs.first < rhs.first; } int main() { ios::sync_with_stdio(0); long long n; cin >> n; long long a[3]; map<pair<long long, long long>, vector<pair<lon...
8
#include<bits/stdc++.h> using namespace std; #define N 200005 #define mod 1000000007 #define mod1 998244353 //#define int long long typedef long long LL; typedef unsigned long long ULL; int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int a[N]={0,1}; void slove() { int in,k,n,t=1;LL ans=1; cin>>n; for(int i=2;i...
8
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7; const long long INF = 1e18; int n, m, a[N][5]; bool check(int i, int j) { int cnt = 0; for (int q = 0; q < m; q++) cnt += (a[i][q] <= a[j][q]); return cnt >= 3; } void solve() { scanf("%d", &n); m = 5; for ...
7
#include <bits/stdc++.h> using namespace std; const int BufferSize = 1 << 16; char buffer[BufferSize], *front_head, *front_tail; inline char GET_CHAR() { if (front_head == front_tail) { int l = fread(buffer, 1, BufferSize, stdin); front_tail = (front_head = buffer) + l; if (front_head == front_tail) retur...
18
#include <bits/stdc++.h> using namespace std; long long d[111][3000]; void pre(void) { for (long long i = 0; i < 3000; ++i) d[1][i] = 0; for (long long i = 0; i < 26; ++i) d[1][i] = 1; for (long long l = 2; l < 101; ++l) for (long long s = 0; s < 3000; ++s) { d[l][s] = 0; for (long long j = 0; j <...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50; int n, m, final[N], nex[N], to[N], tot, T; void link(int x, int y) { to[++tot] = y, nex[tot] = final[x], final[x] = tot; } int ans[N], sum[N], sp[N], dep[N]; int ins[N], vis[N], god; void dfs(int x) { ins[x] = vis[x] = 1; for (int i = final[x]; i...
22
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; int T = 0; vector<vector<int>> adj; vector<int> in, up, down, siz, par, depth; void init(int n) { adj.resize(n); in.resize(n); siz.resize(n); up.resize(n); par.resize...
22
#include <bits/stdc++.h> using namespace std; char str[101000]; vector<int> vt[2][30]; long long cnt[30], l; void init(int cur) { int i, j; for (i = 0; i < 26; i++) { vt[cur][i].clear(); cnt[i] = 0; } } int main() { int i, j, k, cur, flag, it, jt; string res; long long sum; while (scanf("%s", str)...
13
#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); } ...
14
#include <bits/stdc++.h> using namespace std; const long long maxx = 1e9 + 7; bool compare(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.first > b.first; } long long inline power(long long a, long long b, long long p) { a %= p; long long ans = 1; while (b > 0)...
5
//Have A Good Day Traveller:) //Author: Saksham Goel #include<bits/stdc++.h> #include<queue> #include<vector> #define MOD 1000000007 #define endl "\n" #define fastio ios_base::sync_with_stdio(false);cin.tie(0); #define int long long int #define lli long long int #define mp(x,y) make_pair(x,y) using namespace std; void...
1
#include <bits/stdc++.h> using namespace std; int neigh[5][2] = {{0, 0}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int best, m, n; int a[50][50]; void search(int x) { int i, j, k, b1, x1, y1, xx, yy, x2, y2; vector<pair<int, int> > tmp; b1 = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (a[i][j] ==...
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); signed t; cin >> t; string str; for (signed i = 0; i < t; ++i) { cin >> str; signed cnt = 0; while (true) { string nw = ""; signed t1, t2; if (str.size() == 0) { break; } for (...
1
#include <bits/stdc++.h> using namespace std; struct Rec { int x1, y1, x2, y2; } r1, r2; Rec u(Rec a, Rec b) { Rec c; c.x2 = max(min(a.x1, a.x2), min(b.x1, b.x2)); c.x1 = min(max(a.x1, a.x2), max(b.x1, b.x2)); c.y2 = max(min(a.y1, a.y2), min(b.y1, b.y2)); c.y1 = min(max(a.y1, a.y2), max(b.y1, b.y2)); retu...
10
#include <bits/stdc++.h> using namespace std; long long popcount(long long l, long long r) { long long ans = 0; while (1) { if (l == r) { ans += l; break; } else { long long temp1 = log2(r); temp1 = pow(2, temp1); long long temp3 = temp1 * 2 - 1; if (temp3 == r) { ...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; struct edge { int v, nx; long long w; } E[201000 * 2 + 101000 * 2]; int head[101000], EN; void init_edge() { EN = 0; memset(head, -1, sizeof(head)); } void add_edge(int u, int v, long long w) { E[EN] = (edge){v, head[u], w}; head[u] =...
18
#include <bits/stdc++.h> using namespace std; int arr1[1000007]; int arr2[1000007]; int arr3[1000007]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr1[i]; arr2[i] = arr1[i]; } sort(arr2, arr2 + n); int mini = arr2[0]; int cnt = 0, counter = 0; for (int i = 0; i < n; i++) ...
4
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1)...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int inf = 1e9 + 10; const long long INF = 1e18; const long double EPS = 1e-10; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> bool chmax(T &a, const T &b) { if (a < b...
19
#include <bits/stdc++.h> using namespace std; const int maxN = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), b(n); for (auto& it : a) cin >> it; for (auto& it : b) cin >> it; sort(begin(a), end(a...
0
#include <bits/stdc++.h> using namespace std; int n; string s; vector<int> a; bool check(int k) { bool f = true; for (int i = 0; i < k; ++i) { int sum = 0; for (int j = i; j < a.size(); j += k) sum += a[j]; if (sum % 2 == 1) f = false; } return f; } vector<int> primes; vector<int> pows; vector<int> ...
13
#include <bits/stdc++.h> using namespace std; int N, i, j, k, A[500001], ans = 0; int main() { scanf("%d", &N); for (int l = 0; l < N; l++) scanf("%d", &A[l]); i = 1; while (i < N - 1) { j = k = i; while (j < N - 1 && A[j] != A[j - 1] && A[j] != A[j + 1]) j++; if ((j - i) % 2 == 0) { while (k ...
9
#include <bits/stdc++.h> using namespace std; const int MAX = 210000; const long long base = 1e9 + 7; struct Node { int l, r; }; void solve() { long long result = 0; int n, s, m, k; cin >> n >> s >> m >> k; vector<int> za(n); int maxa = -1; for (int i = 0; i < n; ++i) { cin >> za[i]; maxa = max(za...
17