solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int N = 200000; int a[N]; int b[N]; int posa[N]; int posb[N]; int main() { int n; scanf("%d", &n); vector<int> temp, temp1; 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; ...
5
#include <bits/stdc++.h> using namespace std; int gi() { char cc = getchar(); int cn = 0, flus = 1; while (cc < '0' || cc > '9') { if (cc == '-') flus = -flus; cc = getchar(); } while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar(); return cn * flus; } const int N = 1e5 + 5; int n, ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000002; inline void read(int &x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } x *= f; } in...
13
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << "," << p.second << ")"; } const double pi = acos(-1); const int inf = (1 << 30); const long long INF = (1LL << 62) - 1; const int mod = (int...
10
#include <bits/stdc++.h> const long long MOD = 1000000007; using namespace std; long long jcn_1 = 1, inv_jcn_1, n, f[100], s, ans = 0; long long pow(long long a, long long b) { long long ans = 1; a %= MOD; while (b) { if (b & 1) ans = (ans * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ans; } lo...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; long long arr[2001]; cin >> n >> a >> b; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n, greater<int>()); cout << arr[a - 1] - arr[n - b] << endl; }
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 200; const int MAXLG = 16; typedef double Mat[MAXN][MAXN]; typedef double Vec[MAXN]; struct P { int x, y; }; int n; P p[MAXN]; Mat pone; Mat pmany[MAXLG + 1]; Vec pok; void mml...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; char a[MAXN][MAXN]; char check(char a) { if (a == '<') { return '>'; } if (a == '>') { return '<'; } return a; } int main() { int n, x; cin >> n >> x; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j]...
17
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<vector<int>> v; stack<vector<int>> second; for (long long i = 0; i < n; i++) { vector<int> v1(5, 0); for (int j = 0; j < 5; j++) { cin >> v1[j]; ...
7
#include <bits/stdc++.h> using namespace std; int n, m, K, s[25], t[25]; int x[1000005], y[1000005], ans = -1, L = 0, R = 0; int build(int *bs, int *per) { int S = 0; for (int i = 0; i < K; i++) S |= bs[per[i]] << i; return S; } int per[25]; int mn[1100000], mx[1100000]; int main() { scanf("%d%d%d", &n, &m, &K)...
21
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 100100; const int MAXM = 2100100; long long int ned; long long int first[MAXN], dist[MAXN], work[MAXN]; long long int nxt[MAXM], to[MAXM], cap[MAXM]; void init() { memset(first, -1, sizeof first); ned = 0; } void add(int u, i...
16
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int rev[600500]; struct cd { double r, i; cd(double _r = 0.0, double _i = 0.0) { r = _r; i = _i; } cd operator-(const cd &b) const { return cd(r - b.r, i - b.i); } cd operator+(const cd &b) const { return cd(r + b.r, i + b.i);...
20
#include <bits/stdc++.h> using namespace std; int Read() { char c; while (c = getchar(), (c != '-') && (c < '0' || c > '9')) ; bool neg = (c == '-'); int ret = (neg ? 0 : c - 48); while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48; return neg ? -ret : ret; } const int MAXN = 200005; str...
21
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N]; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int e = 0, ans = 0; for (int i = 0; i < n; i++) { int diff = a[i + 1] - ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int ans[t]; for (int z = 0; z < t; z++) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int count = 0, mn = a[n - 1]; for (int i = n - 2; i >= 0; i--) { if (a[i] > mn) count++; m...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = (int)s.length(); const int NMX = 1 << 20; vector<int> dp(NMX, 0); for (int i = 0; i < n; i++) { int cur = 0; for (int j = i; j < min(n, i + 20); j++) { ...
14
#include <bits/stdc++.h> using namespace std; int n; vector<string> dict; vector<bool> u; string start, ans; char letter = '#'; void z_fun(string &s1, string &s2) { vector<int> z; string s = s1 + '#' + s2; int len = s.length(); z.resize(len); z[0] = 0; int l = 0, r = 0; for (int i = 1; i < len; i++) i...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 5e+5; const long long mod = 1e9 + 7; int a[maxn], n, m; struct Mat { long long v[2][2]; Mat() { memset(v, 0, sizeof(v)); } friend Mat operator*(Mat g, Mat b) { Mat c; for (int i = 0; i <= 1; i++) for (int j = 0; j <= 1; j++) for ...
15
#include <bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long #define inf INT_MAX #define llinf LLONG_MAX #define mod 1000000007 #define mxn 1000000001 ll q,x,y,br; int main() { ios; cin >> q; while ( q-- ) { cin >> ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, pos = 0; cin >> n; char ch[n]; cin >> ch; long long int aa[n]; for (i = 0; i < n; i++) scanf("%I64d", &aa[i]); map<int, int> mp; mp[0] = 1; while (1) { if (ch[pos] == '>') pos += aa[pos]; else pos -= aa[pos]; ...
2
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b, long long int m) { if (b == 0) return (1); long long int sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return sol; } long long int gcd(long long int a, long long int b) {...
9
#include <bits/stdc++.h> using namespace std; int i, n, m, ans, b[200005], x, y; map<int, int> mp; map<int, int>::iterator it; vector<int> v[200005]; void dfs(int x) { b[x] = 1; mp[x] = 1; for (int i = 0; i < v[x].size(); i++) if (!b[v[x][i]]) dfs(v[x][i]); } int main() { ios::sync_with_stdio(NULL); cin.t...
9
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int MAXN = 1e6 + 10; const long long MOD = 1e9 + 7; const long long MOD2 = 998244353; const long long INF = 8e18; const int LOG = 22; long long pw(long long a, long long b, long long mod) { return (!b ? 1 : (b & 1 ? (a * pw(a ...
13
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m; cin >> n >> m; vector<long long> arr(m); for (long long i = 0; i < m; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); long long ans = LLONG_MAX; for (long ...
1
#include <bits/stdc++.h> using namespace std; const int N = 105; const int SQRT_N = 32000; const long long LINF = (long long)4e18; int n; long long k; long long seq[N]; long long max_d; long long events[SQRT_N * N]; int esz; long long sum_x; void process(int l, int r) { sum_x -= r - l; long long left_d = events[l];...
15
#include <bits/stdc++.h> using namespace std; const int N = 200005; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * w; } i...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, c, i, j; cin >> n >> m >> c; long long int a[n], b[m]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < m; i++) cin >> b[i]; for (i = 0; i < n - m + 1; i++) { for (j = 0; j < m; j++) { a[i + j] = a[i + j] + b[j]; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1005; char s[N][N]; int ans, l[N], n, r; int main() { while (gets(s[n])) { l[n] = strlen(s[n]); if (l[n] > ans) ans = l[n]; n++; } for (int i = 0; i < ans + 2; i++) printf("*"); puts(""); for (int i = 0; i < n; i++) { printf("*"); ...
4
#include <bits/stdc++.h> using namespace std; const static long long inf = (long long)1e18; const static int mod = 1000000007; int n, u, r; int a[31], b[31], k[31], p[31]; inline long long calc(int* aa) { long long ans = 0; for (int i = 0; i < (int)(n); i++) { ans += (long long)(aa[i]) * k[i]; } return ans;...
12
#include <bits/stdc++.h> using namespace std; int ans; long long n, k, d1, d2, a, b, c; void gettin(long long x, long long y) { if (n % 3) return; long long aa, bb, cc; if ((k - x - y) < 0) return; if ((k - x - y) % 3) return; aa = (k - x - y) / 3; bb = aa + x; cc = aa + y; if (aa > n / 3) return; if ...
9
#include <bits/stdc++.h> using namespace std; int n, a[100], ans; int find(int x) { while (x > 0) { if (a[x % 10]) return true; x /= 10; } return false; } int main() { scanf("%d", &n); memset(a, 0, sizeof(a)); int tp = n; while (tp > 0) { a[tp % 10] = true; tp /= 10; } ans = 0; for (...
5
#include <bits/stdc++.h> using namespace std; char m[1001][1001]; int di[1001][1001], dx[5] = {0, 0, 0, 1, -1}, dy[5] = {0, 1, -1, 0, 0}, n, b, d, x, y, ans; int main() { cin >> n >> b; memset(di, -1, sizeof(di)); queue<pair<int, int> > q; for (int i = 1; i <= n; ++i) { for (int j = 1; j...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; struct Pair { int a, b; }; struct dsu { vector<int> par; dsu(int n = 0) { par.resize(n); for (int i = 0; i < n; ++i) par[i] = i; } int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); } void unite(int x, int y) { x...
16
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MAX_COUNT = 2e3 + 1; const int MOD = 1e9 + 7; int n; int d; vector<int> g[MAX_COUNT]; int val[MAX_COUNT]; long long ans; long long dfs(int u, int p, int root) { if (val[u] < val[root]) return 0; if (val[u] > val[root] + d) return 0; if (...
13
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int mod = 1e9 + 7; int n, sz[N], son[N], top[N], id[N], ty[N], f[N], o[N], val[N], tot; vector<int> g[N]; void dfs_1(int u, int fa) { sz[u]++; f[u] = fa; pair<int, int> mx = make_pair(0, 0); for (int i = 0; i < (int)g[u].size(); i++) { ...
18
#include <bits/stdc++.h> using namespace std; int i, n, ans; int f[10]; char ch; int main() { memset(f, 0, sizeof(f)); cin >> n; for (i = 1; i <= n; i++) { cin >> ch; f[ch - 48]++; } ans = min(n / 11, f[8]); cout << ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; class BinaryIndexedTree { int N; vector<int> tree; public: BinaryIndexedTree(int _N) : N(_N), tree(_N + 1) {} int query(int idx) { int res = 0; for (int i = idx; i > 0; i -= (i & -i)) { res += tree[i]; if (res >= MOD) r...
15
#include <bits/stdc++.h> using namespace std; template <class T> int chkmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int chkmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } template <class iterator> void output(iterator begin, iterator end, ostr...
18
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define ll long long #define pb push_back #define mkp make_pair #define si set < int > #define vi vector < int > #define pii pair < int, int > #define mii map < int, int > #define p_q priority_queue #define INF ((1 ...
27
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
9
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; const int N = 2e5 + 5; #define MOD 1000000007 int main() { ios_base::sync_with_stdio(false); int T; cin >> T; while(T--) { int n; cin >> n; map<int, int> mp; ...
0
#include <bits/stdc++.h> using namespace std; int main(void) { unsigned int n, top, i, j, found = 0, temp; signed int sum; cin >> n; top = 1; top = top << n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < top; i++) { sum = 0; temp = i; for (j = 0; j < n; j++) { ...
4
#include <bits/stdc++.h> using namespace std; string s; long long N; void change() { for (int i = 0; i < s.size(); ++i) { if (s[i] == 'L') { s[i] = 'R'; } else { s[i] = 'L'; } } } bool good(int p) { int curr = 0, step = 0, ma = 0, cnt = 1; bool v = 0; for (int i = 0; i < N; ++i) { ...
14
#include <bits/stdc++.h> using namespace std; vector<int> s[3005]; int dp[3005][3005]; multiset<pair<int, int> > d1[3005]; multiset<pair<int, int> > d2[3005]; int main(void) { int n, m; cin >> n >> m; while (m--) { int a, b; cin >> a >> b; s[a].push_back(b); } for (int i = 1; i <= n; ++i) for ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int num[maxn]; int main() { int n; while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) scanf("%d", &num[i]); int st = -1, ans = 0; for (int i = 0; i < n; i++) { if (num[i]) { st = i; break; } } if ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int r; if (k % (n - 1) == 0) r = k / (n - 1); else r = k / (n - 1) + 1; cout << r - 1 + k << endl; } }
4
#include <bits/stdc++.h> using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); long long int n, x; cin >> n >> x; lo...
2
#include <bits/stdc++.h> using namespace std; int n, a, b, p[101][101], cnt1, cnt2; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a >> b; cnt2 = 1; cnt1 = 2; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { if ((i + j) % 2 && cnt1 <= n) { p[i]...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; long long a[n]; long long sum = 0, m = 0; for (int i = 0; i < (n); ++i) { cin >> a[i]; m = max(m, a[i]); sum += a[i]; } if (sum % 2 != 0) { cout...
7
#include <bits/stdc++.h> using namespace std; int k, n, m, q; map<string, int> players[150], upgrade[70]; string s, name[70]; void solve() { cin >> k >> n >> m >> q; getline(cin, s); for (int i = 0; i < n; i++) getline(cin, s); for (int f = 0; f < m; f++) { getline(cin, s); int i = 0, l = ((int)(s).leng...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 16; long long n, m, head[200100], deep[200100], dep[200100], fa[200100][20], d[50][200100], num[200100], tot = 1, cnt, Q, ans; bool vis[200100], in[200100]; struct edge { long long to, next, w; } edges[200100 << 1]; struct node { long long dist, u; ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, oc = 0, ec = 0, t = 0; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] % 2 == 0) ec++; else oc++; t += arr[i]; } if (t % 2 == 0) cout << ec << endl; else cout << oc << endl; ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 200005, INF = 2000000000000000000; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>= 1; a = (a * a) % p; } return res; }...
8
#include <bits/stdc++.h> using namespace std; inline long long ceil(long long a, long long b) { return (a + b - 1) / b; } void func() { long long n; cin >> n; if (n == 2) { cout << "-1\n"; return; } long long sv[400]; for (long long i = 2; i < 400; i++) sv[i] = i; long long cnt = 0; vector<long ...
9
#include <bits/stdc++.h> const double eqs = 1e-6; int main() { int i, j, k; double s, a, h, p, q; scanf("%lf", &s); for (i = 1; i <= 10; i++) { for (j = 1; j <= 10; j++) { a = i / 2.0; h = j * 1.0; p = sqrt((a * a + h * h)); q = a * h / p; if (q <= s + eqs && q >= s - eqs) { ...
10
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class ...
11
#include <bits/stdc++.h> using namespace std; int main() { vector<int> x; int n, t; cin >> n; for (int i = 0; i < n; i++) { cin >> t; x.push_back(t); } for (int i = 0; i < x.size(); i++) { while (x[i] % 2 == 0 || x[i] % 3 == 0) { if (x[i] % 2 == 0) x[i] /= 2; else x[i...
5
#include <bits/stdc++.h> using namespace std; using namespace std; char s[15]; int main() { cin >> s; int ans = 6; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) for (int k = 0; k < 10; k++) for (int l = 0; l < 10; l++) for (int m = 0; m < 10; m++) for (int n = 0...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; long long d[maxn], c[maxn], sum[maxn], dp[maxn][101], t; int q[maxn], head, tail; long long getans(int i, int j, int k) { return dp[k][j - 1] + c[i] * (i - k) - (sum[i] - sum[k]); } long long Y(int k, int j) { return dp[k][j - 1] + sum[k]; } int m...
16
#include <bits/stdc++.h> using namespace std; int N, W; int a[110]; vector<int> ans; int in[110], out[110]; bool func(void) { int i, j, k; int sum = 0; for ((i) = 0; (i) < (int)(N); (i)++) sum += a[i]; if (W < 0 || W > sum) return false; if (N == 1) { if (W != a[0]) return false; for ((i) = 0; (i) < (...
16
#include <bits/stdc++.h> using namespace std; int Stack[110], top; int n, k, c; int a[110]; int doit(int x) { int ans = 0, nt = top; if (Stack[top] != x) { for (int i = top; i > 0; i--) { if (Stack[i] == Stack[top]) ans++, nt = i; else break; } } if (ans < 3) { Stack[++to...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, l, m; cin >> n >> m; char p[n + 1][m + 2]; int c = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> p[i][j]; if (p[i][j] == '*') c++; } } int fl = 0; for (i = 0; i < n; i++) { for (j = 0; j < ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, x, y, p = 0, sum, maax = 2147483648, q = 0; cin >> n >> m; for (long long int i = 0; i < m; i++) { cin >> x >> y; sum = y - x + 1; if (sum < maax) { maax = sum; } } cout << maax << endl; for (long long int i...
9
#include <bits/stdc++.h> using namespace std; long long const MAXN = 2e5 + 10; long long n, m, T; long long a[MAXN], is_fang[MAXN], no_fang[MAXN]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i]; long long cnt = 0; for (long long i = ...
8
#include <bits/stdc++.h> using namespace std; const int CONST = 998244353; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } int ans = 0; sort(A.begin(), A.end()); vector<vect...
17
#include <bits/stdc++.h> using namespace std; const int mxN = 1e4 + 3; const int INF = 1e9; const int modi = 1e8 + 7; struct point { int x, y; }; void solve() { int k; cin >> k; int copy = k; int bigboi = 0; int count = 1; while (bigboi <= k) { count *= 2; bigboi = (bigboi * 2) | 1; } bigboi =...
9
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, mod = 1000000007; const double pi = 3.1415926535897932, eps = 1e-6; void chmax(int &x, int y) { if (x < y) x = y; } void chmin(int &x, int y) { if (x > y) x = y; } int d[7], biao[4][4] = {{0, 1, 2, 3}, {0, 0, 4, 5}, {0, 0, 0, 6}, {0}}; double...
16
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 1e9 + 7; long long dp[1000 + 1][22]; int32_t main() { ios_base::sync_with_stdio(false); long long n, m; cin >> n >> m; m *= 2; dp[1][0] = 1; lon...
8
#include <bits/stdc++.h> using namespace std; namespace cyl { const long long inf = 1e18; int n; long long a[100005], dp[63][100005]; template <class T> bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]); sort(a + 1, a + n + 1)...
23
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> answer(n + 3, 0); vector<int> par(n + 3); vector<int> max1(n + 3, 0); vector<int> max2(n + 3, 0); int res = 1; for (int i = 2; i <= n + 1; ++i) { cin...
18
#include <bits/stdc++.h> int a[110]; int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); if (n % 2 != 0) { if (a[0] % 2 != 0 && a[n - 1] % 2 != 0) printf("YES\n"); else printf("NO\n"); } else printf("NO\n"); }
2
#include <bits/stdc++.h> using namespace std; long long int wari(long long int a, long long int b) { long long int res = (long long int)a / b; if (a % b != 0) res++; return res; } int main() { long long int n, m; long long int nx[501], ny[501], nz[501], mx[501], my[501], mz[501]; long long int cost = 100000...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 1000000007; const ll root = 62; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1;...
20
#include <bits/stdc++.h> using namespace std; using ll = long long; inline int read(); const int M = 400016, MOD = 1000000007; int save[M]; int main(void) { int t = read(); while (t--) { int n = read(); vector<int> psh; for (int i = 1; i <= n; ++i) { save[i] = read(); if (i == 1 || save[i] !...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void f(long long& x) { if (x < 0) { x %= mod; x += mod; } if (x >= mod) x %= mod; } long long g(long long x) { f(x); return x; } long long st(long long a, long long k) { if (k == 0) return 1; f(a); if (k == 1) return a;...
15
#include <bits/stdc++.h> using namespace std; long long ans, vis1[2000005], vis2[2000005], vis3[2000005], dp[2][2000005], sor[2][2000005], n, m, id, len[2000005], now, nex[2000005], dif; string s[2000005]; long long jug(long long x) { long long Las = vis2[x]; return s[id][Las] < s[id - 1][Las]; } long long add(...
24
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; else return gcd(b % a, a); } long long findGCD(vector<long long> arr, long long n) { long long result = arr[0]; for (long long i = 1; i < n; i++) result = gcd(arr[i], result); return result; }...
2
#include <bits/stdc++.h> long double pi = acos(-1.0); const int mod = 1e9 + 7; using namespace std; long long n, m, k; vector<vector<int>> r, c; long long cnt = 0; long long len = 1; void die() { cout << "No"; exit(0); } void go(int x, int y, int dir, int lx, int rx, int ly, int ry) { if (len == cnt) { return...
15
#include <bits/stdc++.h> using namespace std; const int c=3002; int n, m, pos[c], si[c]; vector<int> sz[c], s[c], sol; bool v[c], kim[c], h[c]; void dfs(int a) { v[a]=true; for (int i=0; i<si[a]; i++) { int x=sz[a][i], y=s[a][i]; if (!kim[y] && !v[x]) { dfs(x); } } } boo...
21
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ii = pair<int, int>; using vii = vector<ii>; using ll = long long; using ull = unsigned long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using pdd = pair<double, double>; using vpdd = vector<pdd>; template ...
10
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5050, mod = 1e9 + 7; int n, m, si[MAX_N], fi[MAX_N], hi[MAX_N], max_capacity[MAX_N]; int pre_bucket[MAX_N], suf_bucket[MAX_N]; vector<int> cows[MAX_N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &si[i]); for (int i =...
17
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); cout << fixed << setprecision(11); cerr << fixed << setprecision(6); long n, s, d, a; cin >> n; cin >> s >> d; n--; a = s; while (n--) { cin >> s >> d; long long m = 0LL; while ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; map<long long, int> mp[26]; char s[maxn]; int val[30]; int main() { for (int i = 0; i < 26; i++) scanf("%d", &val[i]); scanf("%s", s); int len = strlen(s); long long sum = 0; long long ans = 0; for (int i = 0; i < len; i++) { ans +...
10
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<long long> vl; typedef pair<long long, long long> pl; typedef vector<vector<long long>> matrix; #define F first #define S ...
1
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int N = 1000, K = 40; const int INF = 1 << 30; int R, C, k; int arr[N][N]; int dist[K][N][N]; vector<tuple<int, int>> pos[K]; void init(); void process(); int main() { ios::sync_with_stdio(false); cin.tie(0); init(); process(); cout...
18
#include <bits/stdc++.h> typedef struct punto { int x, y; } Punto; int main() { int n, i; long long j; scanf("%d%I64d", &n, &j); Punto A[2 * n]; Punto M[2 * n]; scanf("%d%d", &M[0].x, &M[0].y); for (i = 0; i < n; ++i) { scanf("%d%d", &A[i].x, &A[i].y); } for (i = 0; i < (2 * n); ++i) { M[i +...
10
#include <bits/stdc++.h> using namespace std; const int MAX = 6e5 + 5; long long n, m, ji, ou, resji, resou, needji, needou; long long a[MAX]; set<long long> sji, sou, ans; bool vis[MAX], ok[MAX]; vector<int> o, j; int main() { cin >> n >> m; if (m & 1) resou = m / 2, resji = resou + 1; else resou = resji...
11
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 1010, M = (1 << 8) + 10; int n, q[N], x, c[10], a[10][N], mn, f[N][M]; int cur[10]; int cal(int len) { int m = (1 << 8) - 1; for (int i = 1; i <= n + 1; i++) for (int j = 0; j <= m; j++) { f[i][j] = -INF; } f[1][...
14
#include <bits/stdc++.h> using namespace std; int s[500500]; struct node { int l; int r; }; struct cmp1 { bool operator()(const node &x, const node &y) const { if (x.r - x.l != y.r - y.l) { return (x.r - x.l) < (y.r - y.l); } else { return x.r > y.r; } } }; void solve() { priority_queu...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, f = 0, i, j, k, cnt = 0; string a; cin >> n; cin >> a; for (i = 0; i < n; i++) { if (a[i] == '*') { for (j = 1; j < n; j++) { for (k = i, cnt = 0; k < n;) { if (a[k] == '*') { cnt++; k += j; ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, w[maxn]; long long f[maxn][2]; vector<int> g[maxn]; void dfs(int u) { f[u][1] = -(0x3f3f3f3f3f3f3f); for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; dfs(v); long long fu0 = f[u][0]; long long fu1 = f[u][1]; ...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using iii = pair<int, ii>; using vi = vector<int>; using vii = vector<ii>; void solve() { ll rem, m; cin >> rem >> m; vector<int> boxes(m); ll sum = 0; for (int i = 0; i < m; i++) { cin >> boxes[i]; sum += b...
11
#include <bits/stdc++.h> using namespace std; int n, m; int x[4]; int check(int x[], int a) { for (int i = 0; i < 3; i++) if (x[i] <= a) return false; return true; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < 3; i++) x[i] = m; sort(x, x + 3); int ret = 0; while (!check(x, n)) { sort(x...
8
#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; int ctr1, ctr2, n1 = n, n2 = n; for (ctr1 = 0; n1 % 10 != 0; ctr1++) n1--; for (ctr2 = 0; n2 % 10 != 0; ctr2++) n2++; if (ctr1 <= ctr2) cout << n1 << endl; else ...
0
#include <bits/stdc++.h> using namespace std; const int oo = 1000000001, nn = 100010; struct edge { int k, f, next; } e[nn << 1]; int cq, size, sum, tot, limited; int n, L, R, ans = -1; int m = 1, now[nn]; int s[nn]; bool beused[nn]; pair<int, int> p[nn], f[nn], g[nn], tempe, res; int dl[nn]; void getsum(int i, int f...
22
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (!b) return a; return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return (a / gcd(a, b)) * b; } long long int modexp(long long int a, long long int b) { if (b == 0) return 1; if (b...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, M = 1e7 + 10; int n, m, k; int last[M]; struct node { int n; int t; } shop[N]; long long s[M]; int ans[N], nans; int maxt; int main() { ios::sync_with_stdio(false); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { int t; cin >> t;...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n, p; cin >> n >> p; long long int total = 0, a = 0; vector<string> ar; for (int i = 0; i < n; i++) { string s; cin >> s; ar.push_back(s); } for (int i = n - 1; i >= 0; i--) ...
4
#include <bits/stdc++.h> using namespace std; bool com(string a, string b) { if (a.size() > b.size()) return false; return true; } int main() { int n, m; cin >> n >> m; int b, g; cin >> b; int boys[n]; int ind; memset(boys, -1, sizeof boys); for (int i = 0; i < b; i++) { cin >> ind; boys[ind...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; const int inf = 0x3f3f3f3f; int main() { int n, k; cin >> n >> k; vector<long long> a(k + 1); for (int i = 1; i <= k; i++) cin >> a[i]; vector<bool> is_alive(n + 1, true); int alive = n; int leader = 1; for (int i = 1; i <= k; i++) ...
5