solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long dp[4 * 100005]; bool vis[4 * 100005]; vector<pair<int, int> > g[4 * 100005]; int num[100005]; int n, q, s; int mx = 0; void build(int n, int s, int e) { mx = max(mx, n); if (s == e) num[s] = n; else { int mid = (s + e) / 2; build(n + n, s, mid); ...
15
#include <bits/stdc++.h> using namespace std; int inf = 1e9 + 10; multiset<int> mi; int h[505050]; vector<int> g[505050]; int am[505050]; int t[505050]; int mif[505050]; int miv = inf; vector<int> lol; int hi(int x, multiset<int>& s) { if (x >= inf) { x = inf - 1; } auto it = s.upper_bound(x); it--; retur...
22
#include <bits/stdc++.h> using namespace std; long long n, r, avg, a, b, g, ans; pair<long long, long long> arr[100010]; int32_t main() { cin >> n >> r >> avg; for (long long i = 0; i < n; i++) { cin >> a >> b; g += a; arr[i].first = b; arr[i].second = a; } if (g > avg * n) { cout << 0; ...
6
#include <bits/stdc++.h> using namespace std; int n, mx = 0, ans = 0, a[200010], cnt[200010], b[400010]; void sol1(int x, int y) { for (int i = 0; i <= 2 * n; i++) b[i] = -1; b[n] = 0; int cur = 0; bool flag = 0; for (int i = 1; i <= n; i++) { if (a[i] == x) cur++, flag = 1; else if (a[i] == y) ...
18
#include <bits/stdc++.h> using namespace std; struct edge { int u, v; bool active; }; int n; vector<int> b, c; vector<vector<int>> adjl; vector<edge> edges; map<int, int> compressed; vector<int> decompress; vector<int> circuit; vector<int> deg; int m; void compress() { vector<int> _b(b), _c(c); sort(_b.begin(),...
16
#include <bits/stdc++.h> using namespace std; int n, a[4][400005], ans, cnt; inline int read(int BASE = 10) { char ch = getchar(); int ret = 0, f = 1; while (ch > '9' || ch < '0') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') ret = ret * BASE + ch - '0', ch = getchar(); r...
7
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
8
#include <bits/stdc++.h> using namespace std; long long n, k; int a[124], ans; int dp[124][500024], maxN = 500024; long long get(long long nn, int ind) { if (!nn) { return 0; } if (ind == k) { return nn; } if (nn < maxN && dp[ind][nn] >= 0) { return dp[ind][nn]; } long long crr = get(nn, ind +...
18
#include <bits/stdc++.h> const int MaxN = 1e5 + 5; int n, m, cnt, pri[MaxN]; int tmp[MaxN], tmp_cnt; int ans[MaxN][2]; bool vis[MaxN]; inline void init(const int &n) { static bool bo[MaxN]; for (int i = 2; i <= n; ++i) { if (!bo[i]) pri[++cnt] = i; for (int j = 1; j <= cnt && i * pri[j] <= n; ++j) { b...
17
#include <bits/stdc++.h> using namespace std; int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; template <typename T> inline T BigMod(T A, T B) { T ret = 1; while (B) { if (B & 1) ret = (ret * A) % 1000000007; A = (A * A) % 1000000007; B = B >> 1; } return ret; } temp...
2
#include <bits/stdc++.h> using namespace std; struct POINT { double x, y, z; } P[10005], S; int n; double vp, vs; double Ts[10005], Tp[10005]; double dist(POINT a, POINT b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } POINT padd(POINT a, POINT b) ...
13
#include <bits/stdc++.h> using ll = long long; using ld = long double; using namespace std; const ll inf = 2e18; const ll mod = 1e9 + 7; const ll N = 3e5 + 5; int n, a[N]; void code() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; stack<int> s, st, s2, st2; vector<int> lge(n, -1), lle(n, -1), rge(n, -1), ...
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:22222222") using namespace std; long long used[300333], kol[300333]; vector<long long> pos[300333]; long long t[388888]; int n, q; void inc(int x) { while (x <= q) { t[x]++; x += x & -x; } } long long sum1(int x) { long long sum = 0; while (x) { ...
8
#include <bits/stdc++.h> using namespace std; int32_t main() { string a, b; cin >> a >> b; long long cnt = 0; map<char, long long> mp; if (a.length() != b.length()) { cout << "NO"; return 0; } for (long long i = 0; i < a.length(); i++) { mp[a[i]]++; mp[b[i]]--; } for (auto i : mp) { ...
3
#include <bits/stdc++.h> using namespace std; struct point { long long x, y; }; int n[3], N; point A[3][50010], B[150010]; int start[3], pos[3]; long long area(point &P, point &Q, point &R) { return (Q.x - P.x) * (R.y - P.y) - (Q.y - P.y) * (R.x - P.x); } long long inprod(point &O, point &P, point &Q) { return (P...
18
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int Num_Pixels; int Max_Size; cin >> Num_Pixels >> Max_Size; int* colors = new int[Num_Pixels]; int range_color[256]; memset(range_color, -2, sizeof(range_color)); for (int i = 0; i < Num_Pixels; i++) { cin >> colors[i]; ...
9
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const int MOD = 1e9 + 7; const long long oo = 1e9 + 7; long long GCD(long long a, long long b) { return !b ? a : GCD(b, a % b); } int main() { string str; cin >> str; int l, r; l = r = -1; for (long long i = 0; i < (int)str.size(...
5
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int inf = INT_MAX / 2; int n, m; bool check(int x) { int num1 = x / 2; int num2 = x / 3; int num3 = x / 6; if (num1 < n || num2 < m || num1 + num2 - num3 < m + n) return false; return true; } int main(void) { scanf("%d%d", &(n),...
8
#include <bits/stdc++.h> using namespace std; bool check1(string s) { if (s.length() >= 5) return true; return false; } bool check2(string s) { int m = 0; for (int i = 0; i < s.length(); i++) { m = int(s[i]); if (m >= 97 && m <= 122) return true; } return false; } bool check3(string s) { int m = 0...
0
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; else { for (long long int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } } long long int sum(l...
0
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 10000; string a, b = "metal", c = "heavy"; long long t, o, i, j, n, m; int main() { cin >> a; n = a.size(); for (i = 0; i + b.size() - 1 < n; i++) { if (a.substr(i, 5) == b) o += t; else if (a.substr(i, 5) == c)...
5
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int t; cin >> t; while (t--) { long long int l, r; cin >> l >> r; if (2 * l > r) cout << "-1" << " " << "-1" << endl; else cout << l << " " << 2 * l << endl; } }
0
#include <bits/stdc++.h> using namespace std; int len, p[750]; long long dp[750][750][3][3]; char s[750]; void match() { stack<int> stk; while (!stk.empty()) stk.pop(); for (int i = 0; i < len; i++) { if (stk.empty()) { stk.push(i); continue; } int t = stk.top(); if (s[i] == ')' && s[t...
11
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; const long long MOD = 998244353; long long mod(long long n) { if (n < 0) { return n % MOD + MOD; } else { if (n < MOD) return n; else if (n < 2 * MOD) return n - MOD; else return n % MOD; } } void add(long...
17
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int> > q; int n, m, k, s, t; int x[10005], y[10005]; int dis[10005]; void dij(int t) { dis[t] = 0; q.push(make_pair(0, t)); while (!q.empty()) { int xx = q.top().second; q.pop(); for (int i = 1; i <= k; ++i) { if (i == xx) co...
14
#include <bits/stdc++.h> using namespace std; long long n, k, ans = 2; long long phi[1000005]; void ph(long long n) { for (long long i = 2; i <= n; i++) phi[i] = i; for (long long i = 2; i <= n; i++) { if (phi[i] == i) { for (long long j = i; j <= n; j += i) phi[j] = (phi[j] / i) * (i - 1); } } } in...
20
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; vector<vector<int>> adj(2 * 100005); bool vis[2 * 100005]; int depth[2 * 100005], subtree[2 * 100005]; long long int ans = 0; int dfs(int u, int d) { vis[u] = true; int st = 0; for (int x : adj[u]) { if (!vis[x]) { st += dfs(x, ...
8
#include <bits/stdc++.h> using namespace std; const int Inf = 1000000000; const int Maxn = 82; const int Maxm = Maxn * Maxn; const int Maxd = 4; const int dy[Maxd] = {-1, 0, 1, 0}; const int dx[Maxd] = {0, -1, 0, 1}; struct edge { int a, b, f, c, cst; edge(int a = 0, int b = 0, int f = 0, int c = 0, int cst = 0) ...
15
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535; const double eps = 1e-6; int g[20]; int n, m, a, b, d[20], e[20]; long long k, f[20][100000]; long long dfs(int a, int opt) { if (f[a][opt] != -1) return f[a][opt]; if (a == n) { f[a][opt] = 1; return 1; } f[a][opt] = 0; for...
16
#include <bits/stdc++.h> using namespace std; const int MAXK = 1010; int main() { int n, k; string s; cin >> n >> k >> s; vector<bitset<MAXK * 2> > dp(n + 1); bitset<MAXK * 2> mask; for (int i = 0; i < k; i++) { mask.set(MAXK + i); mask.set(MAXK - i); } dp[0].set(MAXK); for (int i = 0; i < n; ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int n, temp; cin >> n; if (n % 7 == 6) cout << (n / 7) * 2 + 1 << " "; else cout << (n / 7) * 2 << " "; if (n % 7 >= 2) cout << (n / 7) * 2 + 2 << endl; else cout << (n / 7) * 2 + (n % 7) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> dp(n, -1); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i < n; i++) { vector<bool> buv(n, false); if (a[i] == -1) { dp[i] = max(min(i + k, n - 1) ...
6
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<long long> primes; b...
9
#include <bits/stdc++.h> using namespace std; struct node { int a, num; } s[109]; int x[1009], y[1009]; bool cmp(node p, node q) { return p.a > q.a; } int main() { int n, m; cin >> n >> m; int sum = 0; for (int i = 1; i <= n; i++) { cin >> s[i].a; sum += s[i].a; s[i].num = i; } sort(s + 1, s +...
6
#include <bits/stdc++.h> using namespace std; bool se[105][105]; int main() { ios_base::sync_with_stdio(0); long long n, k, i, j, l, z, sum = 0, yl, yr, ise, min1; cin >> n >> k; while (n--) { cin >> z; yl = 69696; ise = 69696; yr = 69696; min1 = 99999999; for (i = 1; i <= k; i++) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m; if (n == 1 and m == 1) { cout << 1 << " " << 1; return 0; } else if (n == 1) { y = 1; x = 1; while (y <= m - y + 1) { cout << x << " " << y << "\n"; if (y != m - y + 1) cout << x << " " << m...
10
#include <bits/stdc++.h> int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1}; using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; template <class T> T sq(T n) { return n * n; } template <cl...
10
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '.' && s[i - 1] == '9') cout << "GOTO Vasilisa." << endl; } for (int i = 0; i < s.length(); i++) if (s[i] == '.' && s[i - 1] != '9') { if (s[i + 1] < '5') for...
0
#include <bits/stdc++.h> int main() { int arr[100005]; int n, i, check = 0, f, j; scanf("%d", &n); for (i = 2; i <= n + 1; i++) { f = 0; for (j = 2; j * j <= i; j++) { if (i % j == 0) { f = 1; break; } } if (f == 0) arr[i - 1] = 1; else { check = 1; ...
4
#include <bits/stdc++.h> using namespace std; int n, cnt[8], num[8], t; int solve(int x) { int a = cnt[0], b = cnt[1], ab = cnt[2], c = cnt[3]; int na = x, nb = x, nc = c + ab - x; if (a == 0 && b == 0) return max(nb, nc); if (abs(nc - nb) >= b) { if (nc >= nb) nb += b; else nc += b; } els...
16
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0 ? a : 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 power(long long int x, long long int y) { long long int ans = 1; while (y...
10
#include <bits/stdc++.h> using namespace std; FILE *in; FILE *out; const int MAX = 10000002; bool prime[MAX]; bool isPal(int num) { char str[12]; sprintf(str, "%d", num); int len = (int)strlen(str); for (int i = 0; i * 2 < len; i++) if (str[i] != str[len - 1 - i]) return false; return true; } int main(voi...
8
#include <bits/stdc++.h> using namespace std; map<int, int> factor(int number) { map<int, int> fc; for (int i = 2; i * i <= number; ++i) { while (number % i == 0) { fc[i]++; number = number / i; } } if (number != 1) { fc[number]++; } return fc; } bool isDevider(int n) { return n == 2...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int mod = 1000000007; mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); class segment_tree { public: long long rmaxq[4 * 100000], rminq[4 * 100000], rsumq[4 * 100000]; void init() { for (int i = 0; i ...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 1505; vector<int> G[maxn]; int ans[maxn], subsz[maxn]; vector<pair<pair<int, int>, int> > A; bool cmp(const pair<pair<int, int>, int> &a, const pair<pair<int, int>, int> &b) { long long int x1 = a.first.first, y1 = a.first.second; long long int...
14
#include <bits/stdc++.h> using namespace std; struct edge { int u, v, w, id; edge(){}; edge(int u1, int v1, int w1, int id1) : u(u1), v(v1), w(w1), id(id1){}; bool operator<(const edge &a) const { return w < a.w; } } e[100010]; int fa[1010]; bool vis[100010]; int Find(int x) { return fa[x] == x ? x : fa[x] = Fi...
15
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void amax(X& x, const Y& y) { if (x < y) x = y; } template <class X, class Y> void amin(X& x, const Y& y) { if (x > y) x = y; } const int INF = 1e9 + 10; const long long INFL = (long long)1e18 + 10; const int MAX = 1e5 + 10; int n; int a[MAX]...
17
#include <bits/stdc++.h> using namespace std; int n, m; int c[21][1 << 20]; char buff[20][100005]; int main() { scanf("%d%d", &n, &m); gets(buff[0]); for (int i = 0; i < n; i++) gets(buff[i]); for (int j = 0; j < m; j++) { int x = 0; for (int i = 0; i < n; i++) x ^= (buff[i][j] == '1') << i; c[0][x]...
18
#include <bits/stdc++.h> using namespace std; struct reverse { bool operator()(const int &left, const int &right) { return (right < left); } }; struct custom { bool operator()(const pair<int, int> &left, const pair<int, int> &right) { return (left.first > right.first); } }; void solve() { int n, m, s, f; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 123; const int mod = 1e9 + 7; const int INF = 1e9 + 1; const double eps = 1e-9; const double pi = acos(-1.0); int n, dp[N]; bool used[N], w[N]; vector<int> g[N]; vector<int> ans; void go(int v = 1, int p = -1) { dp[v] = w[v]; used[v] = 1; for (auto...
8
#include <bits/stdc++.h> using namespace std; int mal[370], fem[370]; int main() { int n; cin >> n; char a[2]; int b, c; for (int i = 0; i < n; ++i) { cin >> a >> b >> c; if (a[0] == 'M') for (int j = b; j <= c; j++) { mal[j]++; } else { for (int j = b; j <= c; j++) { ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
24
#include <bits/stdc++.h> using namespace std; int di[8] = {1, -1, 0, 0, 1, 1, -1, -1}; int dj[8] = {0, 0, 1, -1, 1, -1, 1, -1}; const int N = 2e5 + 5, MOD = 998244353; const double PI = 3.141592653589793238; int n, i, j, sum; vector<int> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 128; int main() { bool f[MAXN] = {0}; int a[MAXN]; int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } int c = 0; int b = 0; for (int i = 0; i < n; ++i) { if (!f[a[i]]) { if (b + 1 > k) { ...
10
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(const T &a) { return a * a; } char s[2000]; int cnt[100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); gets(s); int n = strlen(s); for (int i = 0; i < (n); i++) { cnt[s[i] - 'a']++; } set<int> bigPrimes = {1}; for (in...
5
#include <bits/stdc++.h> using namespace std; map<long long, long long> eo[3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; long long sum = 0; long long res = 0; for (long long i = 0; i <= n; i++) { if (i > 0) { long long x; cin >> x; sum ^= x;...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1000000007; long long qp(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } struct mint { int n; mint(int n_ = 0) : n(n_) ...
12
#include <bits/stdc++.h> using namespace std; bool f(long long len, vector<long long> &v, long long h) { for (int i = 0; i < v.size() - 1; i++) { if (v[i] + len >= v[i + 1]) { h -= (v[i + 1] - v[i]); } else { h -= len; } if (h <= 0) return true; } return false; } void solve() { int n...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; template <typename T> inline bool isLeap(T y) { return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); } template <typename T> inline T GCD(T a, T b) { a = abs(a); b = abs(b); i...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, a[55], b[55], flag; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); } for (int i = 0; i < n; i++) { if (b[i] > a[i]) { flag = 1; for (int j = 0; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 2; const int MOD = 1e9 + 7; int n, p[N][N], g[N], last[N]; long long fac[N], inv[N]; char a[N]; long long quickmi(long long x, long long n) { if (n == 1) return x; long long t = quickmi(x, n / 2); t = t * t % MOD; return n & 1 ? t * x % MOD : t; ...
16
#include <bits/stdc++.h> using namespace std; struct G { int id, v, w; G() {} G(int ID, int V, int W) { id = ID; v = V; w = W; } } g[220]; inline bool cmp(const G& A, const G& B) { return A.w < B.w; } int n, ban[110], rv[4][4], cnt, vis[110], ans, sum, ph[20], num[20]; vector<G> to[5], e[20]; vector...
16
#include <bits/stdc++.h> using namespace std; long long n, i, x, ans; int main() { scanf("%lld", &n); for (i = 1; i <= n; i++) { scanf("%lld", &x); ans += x * i; } printf("%lld", ans); return 0; }
12
#include <bits/stdc++.h> using namespace std; int a[500005]; bool cmp(int x, int y) { return (a[x] < a[y]); } int main() { int n; scanf("%d", &n); vector<int> v; set<int> s; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); s.insert(i); v.push_back(i); } sort(v.begin(), v.end(), cmp); long l...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 3; int a[N][N], tym[N][N]; bool seen[N][N]; pair<int, int> e, s; void bfs(int n, int m) { queue<pair<int, int> > q; q.push(e); seen[e.first][e.second] = 1; while (!q.empty()) { pair<int, int> r = q.front(); q.pop(); int i = r.first; ...
7
#include <bits/stdc++.h> using namespace std; unsigned long long a[60][60 * 3]; int n, w[60], p1[60], p2[60]; unsigned long long mul(unsigned long long a, unsigned long long b, unsigned long long p) { return ((a * b - (unsigned long long)((long double)a * b / p) * p) + p) % p; } unsigned long l...
26
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int n, a[300000]; long long p[300000]; int binPow(long long b, int pow = MOD - 2) { long long res = 1; while (pow) { if (pow & 1) res = res * b % MOD; b = b * b % MOD; pow >>= 1; } return res; } long long get(int l, int r) { ...
18
#include <bits/stdc++.h> using namespace std; void solve(int test_number); void pre() { cout.setf(ios::fixed); cout.precision(20); cerr.setf(ios::fixed); cerr.precision(3); } void post() { fprintf(stderr, "\n"); fprintf(stderr, "Execution time: %Lf", (long double)clock()); } const int MAXN = 100100; vector<...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long int n, i, j; long long int arr[1000000]; cin >> n; for (i = 0; i < n; i++) { cin >> arr[i]; } long long int last = 0; long long int sum = 1; long long int ans = -1000; for (i = 1; i...
1
#include <bits/stdc++.h> using namespace std; int n, sz; long long int bit[100050][11]; long long int sum(int k, int j) { long long int s = 0; while (k > 0) { s += bit[k][j]; k -= k & -k; } return s; } void add(int k, int j, long long int x) { while (k <= n) { bit[k][j] += x; k += k & -k; } ...
11
#include <bits/stdc++.h> using namespace std; struct way { int f, t, v, nxt; } e[500010 * 2]; int ei; int head[500010]; void add_edge(int f, int t, int v) { e[++ei].f = f; e[ei].t = t; e[ei].v = v; e[ei].nxt = head[f]; head[f] = ei; } int Q, N, K; long long dp[500010][2]; void dfs(int x, int f) { long lon...
13
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 1e6 + 5; int32_t main() { long long a, m; cin >> a >> m; for (long long i = 0; pow(2, i) <= 100005; i++) { long long x = a * (pow(2, i)); if (x % m == 0) { cout << "Yes"; return 0; } } cout...
6
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t = 0; char ch = getchar(); int f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } do { (t *= 10) += ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); t *= f; } con...
16
#include <bits/stdc++.h> using namespace std; typedef long long ll; //int xrow[8]={0, 0, -1, 1, -1, 1, -1, 1}; //int xcol[8]={1, -1, 0, 0, 1, 1, -1, -1}; //ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;} //ll lcm(ll a, ll b){return a * b / gcd(a, b);} const int N = 1e5 + 9, M = 1e2 + 9, MOD = 1e9 + 7; int tc, n...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; vector<int> arr[101]; for (int i = 0; i < n; i++) { int p; scanf("%d", &p); a.push_back(p); arr[p].push_back(i + 1); } int cnt[101]; for (int i = 0; i < 101; i++) { cnt[i] = -1; } sort(a.be...
0
#include <bits/stdc++.h> using namespace std; int t; int n, m; int d2[1000005]; int d[1000005]; int to[1000005]; int c[1000005]; int u[1000005]; int cr[1000005]; int f(char c) { if (c == 'L') return 4; if (c == 'U') return 1; if (c == 'R') return 2; return 3; } void reset() { for (int i = 1; i <= n * m; i++) ...
14
#include <bits/stdc++.h> int n, m, k; char hor[1111][1111], ver[1111][1111]; int a[1111][1111]; int cnt(char s[]) { int res = 0; for (int i = 0; s[i]; i++) if (s[i] == 'E') res++; return res; } void fill_hor(int r) { a[r][0] = 1; for (int i = 0; i < m - 1; i++) if (hor[r][i] == 'E') a[r][i + 1] ...
17
#include <bits/stdc++.h> using namespace std; const int N = 505; int b[N][N]; struct node { int x, y, t; } a[N * N]; bool cmp(node a, node b) { return a.t < b.t; } int n, m, k; bool isok(int t) { memset(b, 0, sizeof(b)); for (int i = 1; i <= t; i++) { b[a[i].x][a[i].y] = 1; } for (int i = 1; i <= n; i++) ...
11
#include <bits/stdc++.h> using namespace std; long long power(long long _a, long long _b) { long long _r = 1; while (_b) { if (_b % 2 == 1) _r = (_r * _a); _b /= 2; _a = (_a * _a); } return _r; } int main() { ios::sync_with_stdio(0); long long n, m; cin >> n >> m; long long i, dp[1000000]; ...
1
#include <bits/stdc++.h> using namespace std; int apol[1000100]; int bpol[1000100]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, p, a = 0, b = 0; cin >> n >> m >> p; for (int i = 0; i < n; i++) cin >> apol[i]; for (int i = 0; i < m; i++) cin >> bpol[i]; n = max(m, n)...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, m, x, a[N], dp[N][3][3]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &x); a[x]++; } for (int i = 1; i <= m; i++) { for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) for...
14
#include <bits/stdc++.h> using namespace std; int n; struct coo { int x, y; } a[100005]; bool CCW(coo p1, coo p2, coo p3) { long long a1 = p2.x - p1.x; long long b1 = p2.y - p1.y; long long a2 = p3.x - p2.x; long long b2 = p3.y - p2.y; return a1 * b2 >= a2 * b1; } bool cmp0(coo p1, coo p2) { return CCW(a[1]...
17
#include <bits/stdc++.h> using namespace std; const long long int N = 1e3 + 5; long long int a[N]; long long int cache[N][N]; long long int n; long long int dp(long long int idx, long long int prev) { if (idx > n) return a[prev]; if (idx == n) return max(a[prev], a[idx]); long long int &ans = cache[idx][prev]; ...
12
#include <bits/stdc++.h> #define ff first #define ss second #define mp make_pair using namespace std; typedef long long ll; vector<pair<int,int>> G[100005]; int dist[100005][55]; int main(){ int n,m,a,b,w; scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) { scanf("%d%d%d", &a, &b, &w); ...
14
#include <bits/stdc++.h> using namespace std; const int N = 200000; const int MOD = (int)1e9 + 7; int n, k, x, y, c, cnt = 0, a[N]; vector<pair<int, int> > g[N]; bool dfs(int v, int col) { if (a[v] != -1) { return a[v] == col; } a[v] = col; for (int i = 0; i < (int)g[v].size(); i++) { if (!dfs(g[v][i].f...
14
#include <bits/stdc++.h> using namespace std; int main() { int t, n, MI; string a; cin >> t; for (int i = 0; i < t; i++) { int k = 0; MI = 105; cin >> n; cin >> a; for (int j = 0; j < n - 1; j++) { if (a[j] == '<' && a[j + 1] == '>') { k = min(j + 1, n - (j + 1)); if (M...
4
#include <bits/stdc++.h> using namespace std; set<string> ss; string inp; int n; string resve(string ans) { string ret = ""; int len = ans.length(); for (int i = len - 1; i > -1; --i) ret += ans[i]; return ret; } int main() { while (cin >> n) { ss.clear(); while (n--) { cin >> inp; int len...
7
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; vector<long long> primes; vector<long long> vis(1000001, 0); vector<long long> v(1000001, 0); void sieve(long long n) { primes.clear(); vis.clear(); for (long long i = 2; i * i <= n; i++) { if (!vis[i]) { for (long long j = i * i; j ...
8
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100500]; const long double EPS = 0.0000001; long long ans = 0; long long h, n = 1, k; long long sum(long long h) { long long ret = 0; for (long long i = 0; i < h; ++i) { ret += (1ll << i); } return ret; } void rec(long long l, long long r, long ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<vector<int> > adjacency(7); for (int i = 0; i < 7; ++i) { adjacency[i].resize(7); } map<string, int> m; m["Anka"] = 0; m["Chapay"] = 1; m["Troll"] = 2; m["Dracul"] = 3; m["Snowy"] = 4; m["Cleo"] = 5; m["Hexadecimal"] = ...
6
#include <bits/stdc++.h> using namespace std; long long const MOD = 1e9 + 7; long long const N = 1e3 + 10; long long ara[N + 1]; long long bra[N + 1]; int main() { (ios_base::sync_with_stdio(false), cin.tie(NULL)); long long n, m, q; cin >> n >> m >> q; string str, s; cin >> str >> s; for (long long i = 0; ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; int a[MAXN], res[MAXN]; bool vis[MAXN]; int main() { int n, m, i, j, tot = 0; scanf("%d", &n); for (i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); if (u > v) swap(u, v); a[i] = u; if (v == n) tot++; } if (tot != n...
11
#include <bits/stdc++.h> using namespace std; struct point { int X; int idx; bool operator<(const point& a) const { return X < a.X; } }; int N, M; point P[100 + 1]; int ans[100 + 1]; int main() { scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++) scanf("%d", &P[i].X), P[i].idx = i; sort(P + 1, P + 1 + N);...
8
#include <bits/stdc++.h> using namespace std; int X1[150000], X2[150000], Y1[150000], Y2[150000]; multiset<int> sX1, sX2, sY1, sY2; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i]; sX1.insert(X1[i]); ...
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return x == 0 ? y : gcd(y % x, x); } long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } char a[1000010], b[1000010]; int c1[1000010][27] = {0}, c2[1000010][26] = {0}; int main() { long long n, m, gc, i, j, la, l...
11
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int x, y, a, b; int main() { cin >> x >> y >> a >> b; for (int i = a; i <= x; i++) for (int j = b; j <= y; j++) if (i > j) v.push_back(make_pair(i, j)); cout << v.size() << endl; sort(v.begin(), v.end()); for (int i = 0; i < v....
3
#include <bits/stdc++.h> using namespace std; void read(vector<long long>& v) { int n = v.size(); for (int i = 0; i < n; i++) cin >> v[i]; } void display(vector<int>& v) { int n = v.size(); for (int i = 0; i < n; i++) cout << v[i] << " "; cout << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); ...
7
#include <bits/stdc++.h> const long long INF = 1e9 + 7, size = 1e5 + 100; using namespace std; int main() { ios::sync_with_stdio(0); long long n, a, ans = 1; cin >> n >> a; if (a % 2 == 0) { for (int i = n; i > a; i -= 2) { ans++; } } else { for (int i = 1; i < a; i += 2) { ans++; ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e6; char a[505][505]; int dp[505][26][26]; pair<int, int> steps[505][26][26]; int n, m; void trace(int i, int j, int k) { if (i == 0) return; trace(i - 1, steps[i][j][k].first, steps[i][j][k].second); for (int t = 1; t <= m; t++) { if (t & 1) ...
12
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; const long long int inf64 = 1e18 + 5; const int MAX = 5005; int dp[MAX][MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, i, j; cin >> n >> m; string second, t; cin >> second >> t; int ans = 0; for (int i = 0; i <...
10