solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> int main() { int t, k, l, i; scanf("%d", &t); for (k = 0; k < t; k++) { int n, c = 0, a = 0, o = 0; scanf("%d", &n); char s[n]; scanf("%s", s); int ans = n; for (l = 0; l < n; l++) { if (s[l] == '>') c++; else if (s[l] == '<') { a++; ...
4
#include <bits/stdc++.h> using namespace std; int delta[4][2] = {{-1, -0}, {0, 1}, {1, 0}, {0, -1}}; long long calc_pow(long long a, long long p, long long m = 1000000007) { long long res = 1; while (p > 0) { if (p & 1) res = (res * a) % m; a = (a * a) % m; p >>= 1; } return res; } long long calc_po...
8
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, k, a[N]; double b[N], v[N]; long long s[N]; double f[N][51]; struct line { long long a; double b; line(long long a = 0, double b = 0) : a(a), b(b) {} }; bool bad(line l1, line l2, line l3) { return (double)(l1.b - l3.b) / (l3.a - l1.a) <...
16
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int n; int arr[N]; vector<int> v[N]; multiset<int> ms; int ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", arr + i); ms.insert(arr[i]); } for (int i = 1; i < n; ++i) { int a, b; scanf("%d %d", &a, ...
11
#include <bits/stdc++.h> using std::max; using std::min; const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template <typename _Tp> _Tp gcd(const _Tp &a, const _Tp &b) { return (!b) ? a : gcd(b, a % b);...
25
#include <bits/stdc++.h> using namespace std; void solve() { string input; cin >> input; long long count = 0; int len = 0; vector<vector<int>> dp(input.size(), vector<int>(2, 0)); for(size_t i = 0; i < input.length(); ++i) { if(i == 0) { if(input[i] == '?'){ ...
6
#include <bits/stdc++.h> using pii = pair<int, int>; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } template <class T, class V> ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long int min_num = -5; long long int n; cin >> n; stack<long long int> num_stack; for (long long int i = 0; i < n; i++) { long long int x; ...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n, p, k; cin >> n >> p >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); vector<vector<int>> g(k, vector<int>()); for (int i = 0; i < n; i++) g[i % k].push_back(v[i]); vector<vector<int>> ps(k, vect...
6
#include <bits/stdc++.h> using namespace std; const int Max = 500500; int n, a[Max], q, cnt[Max], outp[Max], belong[Max]; char vis[Max]; vector<int> ans; struct node { int l, r, id; } que[Max]; int cmp(const node& a, const node& b) { if (belong[a.l] == belong[b.l]) { if (belong[a.l] & 1) { return belong[a...
16
#include <bits/stdc++.h> using namespace std; int n; char str[600010]; int prefix[600010]; int ans, ansl, ansr; int main() { cin >> n; cin >> str; for (int i = 1; i <= n; ++i) { prefix[i] = prefix[i - 1] + (str[i - 1] == '(' ? 1 : -1); prefix[i + n] = prefix[i]; } if (prefix[n] != 0) { printf("0\n...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; struct edge { int nxt, to; } e[maxn << 1]; int cnt, head[maxn]; int deg[maxn]; int siz[maxn]; int mx[maxn]; int fl[maxn]; vector<int> zx; void adde(int u, int v) { e[cnt].to = v; e[cnt].nxt = head[u]; head[u] = cnt++; } void dfs(int...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; int fa[100001]; inline int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); } struct Edge { int x, y, v; } e[200001]; int el = 0; bool cmp(Edge a, Edge b) { return a.v > b.v; } int main() { int m, n; cin >> m >> ...
16
#include <bits/stdc++.h> using namespace std; int n, k, h; struct Node { int m, v; int id; bool operator<(const Node &x) const { if (m != x.m) return m < x.m; return v < x.v; } } q[100005]; bool ok(double times) { int i, j; for (j = 1, i = 0; i < n; i++) { if (q[i].v * times >= (double)j * h + 1...
12
#include <bits/stdc++.h> using namespace std; using LL = int64_t; int main() { LL n, k, ans = 1e18; cin >> n >> k; for (LL i = 1; i * i <= n; i++) { if (n % i == 0) { LL tans = i * k + n / i; if ((tans / k) * (tans % k) == n) ans = min(ans, tans); tans = (n / i) * k + i; if ((tans / k)...
3
#include <bits/stdc++.h> using namespace std; int a[100005]; bool solve(); int finds(int); int n, length, x, y; int main() { scanf("%d%d%d%d", &n, &length, &x, &y); memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) scanf("%d", &a[i]); solve(); return 0; } bool solve() { int r1, r2, r3, r4; r1 = finds(x...
9
#include <bits/stdc++.h> using namespace std; long long mod_exp(long long a, long long b, long long m) { long long tmp = 1; while (b > 1) { if (b % 2 == 0) { a = (a * a) % m; b /= 2; } else { tmp = tmp * a % m; b--; } } return a * tmp % m; } int main() { long long n; whil...
5
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int dp[30][30], N; string s; const int oo = 1000000000; int main() { while (cin >> N) { for (int i = 0; i < 30; i++) { for (int j = 0; j < 30; j++) { dp[i][j] = -oo; } } for (int i = 0; i < N; i++) { cin ...
7
#include <bits/stdc++.h> using namespace std; long long ar[2000016 + 5], br[2000016 + 5], BIT[2][2000016 + 5]; long long add(int p, long long v, long long *BIT) { for (int i = p; i <= 2000016; i += i & -i) BIT[i] += v; } long long read(int p, long long *BIT) { long long ret = 0; for (int i = p; i > 0; i -= i & -i...
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; char s[N]; int n, m, t[N]; int a[N * 4], b[N * 4], ab[N * 4], ba[N * 4], aba[N * 4], tag[N * 4]; void pushup(int now) { a[now] = max(a[(now << 1)], a[(now << 1 | 1)]); b[now] = min(b[(now << 1)], b[(now << 1 | 1)]); ab[now] = max(ab[(now << 1)...
19
/* I will never forget it. */ // 392699 #include <bits/stdc++.h> #define int long long using namespace std; void fr(int &a, bool f = 0, char ch = getchar()) { for (a = 0; ch < '0' || ch > '9'; ch = getchar()) ch == '-' ? f = 1 : 0; for (; ch >= '0' && ch <= '9'; ch = getchar()) a = a * 10 + ch - '0'; ...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 200005; int n, m, a, b, vis[MAXN], rnd, l; bool toa, tob; vector<int> G[MAXN]; void dfs(int id) { l++; vis[id] = rnd; for (auto x : G[id]) { if (x == a) toa = true; else if (x == b) tob = true; if (x == a ...
11
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; template <class T> int sgn(T x) { return (x > 0) - (x < 0); } template <class T> struct Point { T x, y; explicit Poi...
8
#include <bits/stdc++.h> const int maxn = +10; const double eps = 10e-7; using namespace std; int a[5]; int main() { while (~scanf("%d%d%d", &a[0], &a[1], &a[2])) { sort(a, a + 3); int ans = 0; ans += a[1] * a[2]; ans += (a[1] + a[2] - 1) * (a[0] - 1); printf("%d\n", ans); } return 0; }
4
#include <bits/stdc++.h> using namespace std; vector<pair<long long, char>> greenRed; vector<pair<long long, char>> greenBlue; vector<pair<long long, char>> all; vector<long long> green; vector<long long> red; vector<long long> blue; tuple<long long, long long, long long, long long> getll(long long lastred, ...
16
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; pair<double, int> p[N]; pair<double, double> ans[N]; pair<double, double> wall[N]; int n, v; const double g = 9.8; inline pair<double, double> st(int i, int j) { double t = wall[j].first / v / cos(p[i].first); return make_pair(wall[j].first,...
14
#include <bits/stdc++.h> using namespace std; int y[110], x[110]; int main() { int n, a, b, s = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; if (x[i] != y[i]) { s = 1; } else if (i != 1 && x[i - 1] < x[i] && s != 1) { s = 2; } } if (s == 1) cout << "rated\n"...
1
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long int, long long int> p1, pair<long long int, long long int> p2) { if (p1.first != p2.first) return p1.first < p2.first; else return p1.second < p2.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:60000000") using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x * x; } char a[10][1...
7
#include <bits/stdc++.h> int main() { int n; int n1, n2; scanf("%d", &n); if (n % 2) { n1 = n - 9; n2 = 9; } else { n1 = n - 4; n2 = 4; } printf("%d %d\n", n1, n2); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n; cin >> n; long long x; cin >> x; long long sum = 0; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1010; int sum; int n, m; int a[N][N]; bool res[N][N]; int ssum[N * N]; bool cmp(int a, int b) { return a > b; } void dfs(int i, int j) { if (i > n || j > m || i <= 0 || j <= 0) return; sum++; res[i][j] = 1; if (!res[i - 1][j] && (8 & a[i][j])) dfs(i - ...
6
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T = 1; while (T--) { long long n, m; cin >> n >> m; std::vector<pair<long long, long long> > v; for (long long i = 0; i < m; i++) { long long x, y; cin >> x >> y; ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<pair<string, int>> ans; int n, m, a[105][105], b[105][105]; cin >> n >> m; int row[105]; for (int i = 0; i < int(n); ++i) row[i] = 1e4; string r = "row", c = "col"; for ...
9
#include <bits/stdc++.h> using namespace std; long long f[310000], n, k, a[310000], sum = 0; long long lowbit(long long x) { return x & (-x); } void update(long long pos, long long v) { while (pos <= n) { f[pos] += v; pos += lowbit(pos); } } long long query(long long x) { long long ans = 0; while (x > 0...
11
#include <bits/stdc++.h> using namespace std; long long r[250], g[250], b[250]; long long dp[210][210][210]; int main() { int x, y, z; scanf("%d %d %d", &x, &y, &z); for (int i = 1; i <= x; i++) { scanf("%lld", &r[i]); } sort(r + 1, r + x + 1); for (int i = 1; i <= y; i++) { scanf("%lld", &g[i]); ...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; int x[MAXN], y[MAXN]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &x[i], &y[i]); x[i] += 100000000; y[i] += 100000000; } while (true) { int cnt[2][2]; cnt[0][0] = cnt[0][1] = cnt[1][...
15
#include <bits/stdc++.h> using namespace std; int T, n, m, a[100][100], cnt; bool flag, isOk; int main() { ios::sync_with_stdio(0); cin >> T; for (int t = 0; t < T; t++) { cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; flag = true; cnt = 0; while (...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int x[maxn], y[maxn], f[maxn], g[maxn], p, n, m, len; char str[maxn]; int v(int i, int j) { return (x[i] + y[j]) % p; } int getmax(int x, int y) { if (x > y) return x; return y; } int work(int l, int r, int d, int u) { int ans = 0, mid = (l + ...
17
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, M, V; cin >> a >> b >> c >> d; M = max(3 * a / 10, a - a / 250 * c); V = max(3 * b / 10, b - b / 250 * d); if (M > V) cout << "Misha"; else if (V > M) cout << "Vasya"; else cout << "Tie"; return 0; }
1
#include <bits/stdc++.h> using namespace std; void ___() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void data() { freopen("name.in", "r", stdin); freopen("name.out", "w", stdout); } const int N = 5e5 + 500; const long long INF = 1e18; const int mod = 1e9 + 7; int n, m, a[505][505]; long long s...
3
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template <typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } const double PI = acos(-1); const double EPS = 1e-9; long long...
0
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, ans = 1; cin >> n; n /= 2; for (int i = n + 1; i <= 2 * n; i++) { if (i % 2 == 1) ans *= i; else ans *= 2; } for (int i = 1; i <= n / 2; i++) ans /= i; for (int i = 1; i < n; i++) ans *= i * i; cout << a...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, k, len, sign, a[maxn]; set<int> st; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); k = a[1]; for (int i = 1; i <= n; i++) { if (k == a[i]) len++; else { k = a[i]; st.insert(le...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; long long s1, s2; double ans[maxn]; int a[maxn], l[maxn], r[maxn]; struct edge { int e, nx; } e[3 * maxn]; int head[maxn][6], cnt; inline void add(int i, int j, int to) { cnt++; e[cnt].e = to; e[cnt].nx = head[i][j]; head[i][j] = cnt; } i...
17
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0), eps = 1e-10; const int inf = ~0U >> 2; int mod = 1e9 + 7; int Pow(int x, long long t) { int r = 1; for (; t; t >>= 1, x = (long long)x * x % mod) if (t & 1) r = (long long)r * x % mod; return r; } const int N = 10101; int n; double x[...
13
#include <bits/stdc++.h> using namespace std; long long int N, n1, n2, a[500000], b[500000]; int main() { cin >> N; long long int i, x, sum1 = 0, sum2 = 0, last = 0; for (i = 1; i <= N; i++) { cin >> x; if (x > 0) a[++n1] = x, sum1 += x, last = 1; else b[++n2] = (-x), sum2 = sum2 + (-x), l...
6
#include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(string s) { return s; } template <class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <class T> string to_string(T v) { bool ...
1
#include <bits/stdc++.h> #include <iostream> #include <fstream> #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer #define mp make_pair #define pb push_back #define forn(n) for(ll i=0;i<n;i++)...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline void umax(T &x, T y) { if (y > x) x = y; } template <class T> inline void umin(T &x, T y) { if (y < x) x = y; } const long long N = 2e6 + 5, L = 2e6, B = 0x7fffffff; long long d, n, m; long long st[8 * L]; long long sag[N]; long long last, full...
14
#include <bits/stdc++.h> using namespace std; int n, a[107], F[107], optEl[107][(1LL << (18))], dp[107][(1LL << (18))]; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; vector<int> rst; void factorise() { for (int x = 1; x <= 60; ++x) { for (int i = 0; i < 17; ++i) { if ((x %...
12
#include <bits/stdc++.h> using namespace std; int main() { map<int, char*> mp; mp[1] = "Sheldon"; mp[2] = "Leonard"; mp[3] = "Penny"; mp[4] = "Rajesh"; mp[5] = "Howard"; int n, m; cin >> n; int cnt = 1; for (int i = 1; cnt <= n; i = i + i) { int j; for (j = 0; j < i && cnt <= n && (m = 1); j...
3
#include <bits/stdc++.h> using namespace std; const int mxN = 100010; vector<int> g[mxN]; int vis[mxN]; int h[mxN]; int mn[mxN], mnI[mxN]; bool f = false; vector<int> res; vector<int> at; vector<int> st; void dfs(int v) { at.resize(res.size(), 0); vis[v] = 1; mn[v] = h[v]; mnI[v] = v; st.push_back(v); for (...
19
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T &a) { return int(a.size()); } template <class T> T sqr(const T &a) { return a * a; } const int max_n = 100010; char a[max_n]; char s[10][20]; int p[10][20]; int len[10]; int u[10]; void init(char *s, int *p) { int u = 0; for (int ...
10
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, n, s = 0; cin >> n; int num[n + 1], swap[n + 1][n + 1]; for (i = 0; i <= n; i++) swap[0][i] = 0; for (i = 1; i <= n; i++) { cin >> num[i]; num[i]++; s += swap[i - 1][num[i]]; for (j = 1; j <= n; j++) { swap[i][j] ...
11
#include<bits/stdc++.h> #define O first #define R second using namespace std;const int N=4e5+7;typedef long long ll;typedef pair<int,int>pa; struct data{int to,next;}e[N<<1];int head[N],fa[N][20],p[N],c[N],toc[N],n,m,i,j,k,cnt,vis[N],root,sum,f[N],d[N],size[N];ll ans,dis[N],todis[N],Sum[N];pa a[N]; void ins(int u,int v...
27
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long a[N << 1], s[N << 1], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), a[i + n] = a[i]; s[1] = a[1]; for (int i = 2; i <= n * 2; i++) s[i] = s[i - 2] + a[i]; for (int i = n + 1; i <= n * ...
13
#include <bits/stdc++.h> using namespace std; int getnext(int a, int b, int c, int d) { vector<int> kek; if (b > a) kek.push_back(b); if (c > a) kek.push_back(c); if (d > a) kek.push_back(d); return *min_element(kek.begin(), kek.end()); } void solve() { int n, k; cin >> n >> k; vector<pair<int, int>> ar...
10
#include<bits/stdc++.h> using namespace std; long long mod = 998244353; long long n , m , dp [400005] , wt [400005] , num [400005] , vis [400005] , viss [400005]; vector < long long > gr [400005] , ngr [400005]; void dfs ( int x ) { vis [x] = 1; for ( int i = 0 ; i < ngr [x] . size () ; i ++ ) { int...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 300003; int n, stk[maxn], sum[maxn], sum1[maxn]; char s[maxn], t[maxn]; int main() { scanf("%d%s", &n, s); int tot0 = 0, tot1 = 0; for (int i = 0; i < n; i++) (s[i] == '(' ? tot0 : tot1)++; if (tot0 != tot1) { printf("0\n1 1"); return 0; }...
17
#include <bits/stdc++.h> using namespace std; #define ll long long void solve() { string s; while(cin >> s) { cout << "NO" << endl; fflush(stdout); } return; } int main() { int t=1; // cin >> t; while(t--) solve(); return 0; }
1
#include <bits/stdc++.h> using namespace std; long long calc(long long a, int from) { long long e = a / from; long long add = a % from; return e * e * (from - add) + (e + 1) * (e + 1) * add; } long long get(long long a, int from) { if (a < from) { return -1; } return calc(a, from) - calc(a, from + 1); }...
14
#include <bits/stdc++.h> using namespace std; bool vis[120000]; int main() { int n, k; cin >> n >> k; getchar(); for (int i = 1; i <= n; i++) { char ch = getchar(); vis[ch - 'a'] = true; } int cnt = 1, at, ans = 0; for (int i = 0; i < 26; i++) if (vis[i]) { at = i; ans = i + 1; ...
1
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long ln, lk, lm; int a[105]; int main() { scanf("%d", &n); for (int(i) = 0; (i) < (int)(n); (i)++) scanf("%d", a + i + 1); if (n % 2 == 0 && a[n]) { puts("-1"); return 0; ...
9
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vi = vector<int>; using ll = long long; const int MAXN = 2e3 + 10; struct point { vi p; int ind; point(int x, int y, int z) { p = {x, y, z}; } point() { p = vi(3); } bool operator<(const point& o) const { return p < o.p; } bool ...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void speed() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { speed(); long long zzz; cin >> zzz; while (zzz--) { long long n, m; cin >> n >> m; long long a[n][m]; for (long long i = 0; ...
5
#include <bits/stdc++.h> using namespace std; const int tope = 1 << 21; const int primero = 1 << 20; const int infinito = 1e9; int minimo[tope]; int cuantos[tope]; int n, m; int posicion[2000000]; int salvar[2000000]; void insertar(int pos, int mi, int c) { pos += primero; minimo[pos] = mi; cuantos[pos] = c; wh...
14
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long x, y, z; cin >> x >> y >> z; long long answer = (x + y) / z; if (answer == (x / z) + (y / z)) { cout << answer << " " << "0"; } else { long long answer = ...
2
#include <bits/stdc++.h> using namespace std; mt19937_64 mt(time(0)); const int MAXN = 233; int ret[MAXN]; bool try_to_process(int fi, int n, const vector<set<int>>& const_nums, const vector<int>& const_cnt) { auto nums = const_nums; auto cnt = const_cnt; for (int i = n - 1; i >= 2; i--) { ...
16
#include <bits/stdc++.h> using namespace std; long long re() { long long ret = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f = (ch == '-') ? -f : f, ch = getchar(); while (isdigit(ch)) ret = ret * 10 + ch - '0', ch = getchar(); return ret * f; } long long n, a[10005], s; signed main() { long long t ...
12
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m, m1, red[N], q[N], f[N], lv[N], p[2 * N][20], E[2 * N], pos[N]; vector<int> ke[N]; void enter() { scanf("%d%d", &n, &m); for (int i = 1, u, v; i < n; ++i) { scanf("%d%d", &u, &v); ke[u].push_back(v); ke[v].push_back(u); } } v...
16
#include <bits/stdc++.h> using namespace std; string s, t; int next1[4010][30], next2[4010][30]; int dp[4010][4010]; int main(void) { int M, N, I, D, R, E, i, j; cin >> I >> D >> R >> E >> s >> t; M = s.length(); N = t.length(); for ((i) = 0; (i) < (int)(26); (i)++) { char ch = 'a' + i; next1[M][i] = ...
18
#include <bits/stdc++.h> using namespace std; int get() { char ch; while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-') ; if (ch == '-') { int s = 0; while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0'; return -s; } int s = ch - '0'; while (ch = getchar(), ch >= '0' &...
23
#include <bits/stdc++.h> using namespace std; int n, k, a[100 + 5], ans = 100000000; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); if (k == a[n - 1]) { cout << 1 << endl; return 0; } for (int i = 0; i < n; ++i) { if (k % a[i] == 0) { ans = m...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 10; const int M = 998244353; int n, a[N]; long long sum, pow1 = 1, powsum = 1; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } for (int i = n - 1; i >= 0; --i) { sum = (sum + (powsum * a[i]) % M) ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 3000005; const int inf = 0x3f3f3f3f; int n, k, x; long long dp[5005][5005]; int a[5005]; deque<int> q; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> x; memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0ll; for (int i...
13
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; int n, m, k, res = 0; int ans[62]; void dfs(int i, bitset<120> s, int pre) { if (i > (m + 1) / 2) res = (res + pre) % mo; else { dfs(i + 1, s, pre); if (ans[i] && !s[i]) dfs(i + 1, s | s << i | s >> i | s << m - i | s >> m - ...
21
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; double L[100010], R[100010]; int A[100010], h[100010], B[N], C[10010], D[10010]; double O[N << 2], laz[N << 2]; void build(int o, int l, int r) { laz[o] = 1; if (l == r) { O[o] = 1; return; } int mid = l + (r - l) / 2; build(o * 2, l...
14
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> pii; const int MOD = 998244353; char s[1010], t[1010]; int n, m; int f[1010][1010][2]; void upd(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int main() { scanf("%s", s + 1); scanf("%s", t + 1); n = s...
16
#include <bits/stdc++.h> using namespace std; long long ncrp(long long n, long long r, long long p) { long long C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) for (long long j = min(i, r); j >= 1; j--) C[j] = (C[j] + C[j - 1]) % p; return C[r]; } long long mod_exp(long lon...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[2000]; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int ans = 0; for (int i = 1; i <= n; i++) { int num = 1; for (int j = i - 1; j > 0; j--) { if (a[j] <= a[j + 1]) num++; else br...
3
#include <bits/stdc++.h> using namespace std; using namespace chrono; const long long SZ = 1e5 + 7; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long MOD = 998244353; const long double PI = 3.1415926535897932384; long long tc_cnt = 1; auto clk = clock(); mt19937_64 rang(high_resolution_clock::n...
4
#include <bits/stdc++.h> using namespace std; int arr[100010]; int narr[100010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int bigstart = n / 2; for (int i = bigstart, arrout = 0; i < n; i++, arrout += 2) narr[arrout] = arr[i]; for (int i = 0, arrout ...
2
#include <bits/stdc++.h> using namespace std; int ans[200005], pos[200005], a[200005], c[200005]; int n, m; struct node { int i, l, r; bool operator<(const node &a) const { return l < a.l; } } es[200005], et[200005]; int lowbit(int x) { return x & (-x); } void update(int x) { int i; for (i = x; i <= n; i += low...
14
#include <bits/stdc++.h> using namespace std; const long long inf = INT_MAX, df = 3e5 + 7, N = 1e6 + 7; long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, opg, a[105][105], mn[105], mx; long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } inline long long read() { long long x ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { string s; cin >> s; ...
5
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:255000000") bool firstout = 1; template <class T> T &minn(T &a, T b) { if (b < a) a = b; return a; } template <class T> T &maxx(T &a, T b) { if (a < b) a = b; return a; } int &madd(int &a, int b) { a += b; if (a >= 1000000007) a -...
9
#include <bits/stdc++.h> using namespace std; long long ans, res; int n, m, cnt, k, valy[3050], suf[3050], pre[3050], f[3050]; struct P { int x, y; } p[3050]; bool cmpy(P a, P b) { return a.y < b.y; } bool cmpx(P a, P b) { return a.x < b.x; } void ins(int x) { suf[pre[x]] = x, pre[suf[x]] = x; } void del(int x) { suf...
22
#include <bits/stdc++.h> using namespace std; int mat[111][111], arr[10010][10]; int main() { ios::sync_with_stdio(false); int i, j, x, y, n, m, a, b, c, d, q; cin >> n >> m >> q; for (i = 0; i < q; i++) { cin >> arr[i][0]; if (arr[i][0] == 1 || arr[i][0] == 2) { cin >> arr[i][1]; } else { ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const long long inf = 1e9 + 5; int N, K; long long B, C; multiset<long long> s[5]; long long a[MAXN]; long long sum[5]; int main() { scanf("%d%d%I64d%I64d", &N, &K, &B, &C); B = min(B, 5 * C); long long ans = inf * inf; for (int i = 0; i < N; i...
16
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<string> mat(2); for (int i = 0; i < 2; i++) { cin >> mat[i]; } int i = 0; int j = 0; int flag = 0; while (1) { if (i == 1 && j == n) { flag = 1;...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; struct Point { long long x; long long y; }; long long Cross(Point a, Point b) { return (a.x * b.y - a.y * b.x); } Point p[maxn]; long long cal(int a, int b, int c) { Point l1, l2; l1.x = p[c].x - p[b].x; l1.y = p[c].y - p[b].y; l2.x = p[c]...
19
#include <bits/stdc++.h> long long a, b, c, d, e, f, g, h, i, j, k; long long low, high, mid; long long an; int T; long long check(long long x) { long long ii, jj, kk; long long CC; jj = 0; kk = 0; CC = 1; for (ii = 0; ii <= x; ii++) { e = CC; if (kk + e > a) e = a - kk; kk += e; jj += ii * ...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; priority_queue<int> q; int in[maxn], ans[maxn]; vector<int> g[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); g[v].push_back(u); in[u]++; } for (int i =...
15
#include <bits/stdc++.h> using namespace std; int last[100005]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; int count = 0; int res = 0; for (int j = 1; j <= sqrt(x); j++) { ...
11
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; for (; b; b >>= 1) { if (b & 1) res = res * a % 242121643; a = a * a % 242121643; } return res % 242121643; } long long gcd(long long x, long long y) { while (y) { long long t = x % y; ...
14
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e15; long long power(long long x, long long y) { long long t = 1; while (y > 0) { if (y % 2) y -= 1, t = t * x % mod; else y /= 2, x = x * x % mod; } ...
14
#include <bits/stdc++.h> using namespace std; int main() { string s, r, p, t; cin >> s >> r >> p; t += s + r; sort(t.begin(), t.end()); sort(p.begin(), p.end()); if (p == t) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; string input; pair<long long int, long long int> ans[10][10][20][10]; long long int brute(long long int t) { long long int sum = 0; while (0 < t) { long long int maxi = 0; for (long long int tmp = t; tmp; tmp /= 10) maxi = max(maxi, tmp % 10); t -= maxi; ...
17
#include <bits/stdc++.h> using namespace std; const int32_t mod = 1e9 + 7; const int32_t mod2 = 998244353; bool check(long long k, long long h, vector<long long> &v) { long long n = v.size(); long long sum = 0; for (long long i = 0; i < n - 1; i++) { sum += min(v[i + 1] - v[i], k); } sum += k; return (s...
4