solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; inline int nxt() { int x; scanf("%d", &x); return x; } struct State { int len; int link; array<int, 2> to; State() : len(0), link(-1) { to.fill(-1); } State(int _len, int _link) : len(_len), link(_link) { to.fill(-1); } bool has(int c) const { return to[c]...
4
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <numeric> #include <functional> #include <set> #include <sstream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <climits> #include ...
0
#include <bits/stdc++.h> int main() { int n, k, p1, p2, count; scanf("%d", &n); scanf("%d", &k); p1 = 1; p2 = 1 + k; count = 0; while (p2 - p1 > 0 && count < n) { printf("%d %d ", p1++, p2--); count += 2; } if (count < n) { if (p1 == p2) { printf("%d ", p1); count++; p1 =...
3
#include <bits/stdc++.h> using namespace std; string tostr(long long a) { stringstream rr; rr << a; return rr.str(); } long long pow(long long c, long long d) { return d == 0 ?: c * pow(c, d - 1); } 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...
2
#include <bits/stdc++.h> using namespace std; int a[205]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); swap(a[0], a[n - 1]); for (int i = 0; i < n; i++) cout << a[i] << ' '; cout << "\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<pair<bool, int>> ab(n); vector<int> b(m); long long res = 0; for (int i = 0; i < n; ++i) { cin >> ab[i].second; } for (int i = 0; i < m; ++i) { cin >> b[i]; b[i]--; ...
3
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> string to_str(T str) { stringstream stream; stream << str; return stream.str(); } template <typenam...
1
#include <bits/stdc++.h> using namespace std; int n; string s[100005][2]; long long in[100005]; long long dp[100005][2]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> in[i]; } for (int i = 0; i < n; ++i) { cin >> s[i][0]; s[i][1] = s[i][0]; reverse(s[i][1].begin(), s[i][1].end()); ...
3
#include <iostream> #include <string> using namespace std; #define BASE1 124248592 #define BASE2 163282852 #define MOD 197436252 long long hash_temp[1000][1000], hash_field[1000][1000], hash_pattern[1000][1000]; void gen_hash(string str[], int H, int W, int R, int C, long long hash[][1000]) { for (int i = 0; i ...
0
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { short negative = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') negative = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); x *= negative; } in...
3
#include <bits/stdc++.h> using namespace std; vector<int> ans; int main() { int x; cin >> x; int cnt = 0; while ((x & (x + 1)) != 0) { int n = 0; while (!(x >> n & 1)) n++; ans.push_back(n); x ^= ((1 << n) - 1); cnt++; if ((x & (x + 1)) != 0) { x++; cnt++; } } cout <<...
2
#include<iostream> #include<cstring> using namespace std; int main() { string a,b,c; cin>>a>>b>>c; cout<<a[0]<<b[0]<<c[0]; }
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 14; int sp[MAX]; char sir[MAX]; int numara(int i, int j) { return sp[j] - sp[i - 1]; } int main() { int n, k; cin >> n >> k; cin >> (sir + 1); for (register int i = 1; i <= n; ++i) { if (sir[i] == 'a') { sp[i] = sp[i - 1] + 1; } e...
3
#include <bits/stdc++.h> using namespace std; const int N = 20; const double pi = acos(-1); const int mod = 1e9 + 7; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x...
3
#include<bits/stdc++.h> using namespace std; struct edge { int v,nxt; }e[10010]; int n,t,u,v,s[5010],h[5010],g[5010],a[5010],f[5010][5010]; void add(int u,int v) { t++; e[t].v=v; e[t].nxt=h[u]; h[u]=t; } inline void dfs(int u,int fa) { s[u]=f[u][1]=1; for(int i=h[u];i>0;i=e[i].nxt) { int v...
0
#include <bits/stdc++.h> char nums[100005][10]; int seq[100005]; char temp[10]; int N; int min_p, max_p; int last; int len; int e[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; int check(int mid, int flag) { char tmp[20]; int cnt = 0; for (int i...
5
#include <bits/stdc++.h> using namespace std; struct node { int l, r; int va; } f[100]; int k, x, n, m; bool gao(int a1, int a2, int a3, int a4, int vax, int vay) { f[1].l = a1; f[1].r = a2; f[1].va = vax; f[2].l = a3; f[2].r = a4; f[2].va = vay; int i; for (i = 3; i <= k; i++) { f[i].l = f[i - ...
4
#include <bits/stdc++.h> using namespace std; struct pt { int x; int y; pt() {} pt(int x, int y) : x(x), y(y) {} }; vector<pt> v; bool comp(const pt &a, const pt &b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int ccw(pt &a, pt &b, pt &c) { return 1LL * a.x * (b.y - c.y) + 1LL * b.x * (c.y - a.y) + ...
5
#include <bits/stdc++.h> using namespace std; int n; long long res; long long arr[100010]; unordered_map<long long, long long> cnt; int main() { ios_base::sync_with_stdio(false); int T; cin >> T; while (T--) { cin >> n; res = 0; for (int i = 0; i < n; i++) { char c; cin >> c; arr[i...
3
#include <bits/stdc++.h> using namespace std; int main() { long long k, d, t; cin >> k >> d >> t; t <<= 1; double ans = 0; long long x = k / d, tx = 0; if (k % d) x++; tx = x * d + k; ans += t / tx * x * d; t %= tx; if (t <= 2 * k) ans += t / 2.0; else ans += t - k; printf("%.15lf", ans)...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, n; long long M = 1000000007; cin >> x >> y >> n; long long int a[6] = {x, y, y - x, -x, -y, x - y}; long long int c = (a[(n - 1) % 6] % M + M) % M; cout << c; }
2
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; int I_INF = 2e9; long long int L_INF = 1e18; void solve() { long long int n, i, j, l, r, index, ctr, num; cin >> n >> l >> r; vector<long long int> vect(n, 0); vect[0] = 2 * (n - 1); for (i = 1; i < n; i++) { vect[i] = 2 * (n - 1 -...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; bool cmp(string left, string right) { if (left.length() != right.length()) { return left.size() < right.size(); } int n = left.size(); for (int i = 0; i < n; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 200002; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<pair<int, int> > b(n); unsigned long long ans = 0; for (int i = 0; i < n; i++) cin >> b[i].first; for (int i = 0; i < n; i++) cin >> b[i].sec...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000000") using namespace std; const long long int INF = 2e9; int ma[3000][3000]; inline bool in(int x, int y, int d, int j, int len) { if ((x == d || x == d + len) && y >= j && y <= j + len) return true; if ((y == j || y == j + len) && x >= d && x <=...
4
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=1e5+4; vector<ll> adj[N]; vector<vector<ll>> dp(N,vector<ll>(2)); const ll mod=1e9+7; void dfs(ll u,ll p){ dp[u][0]=1; dp[u][1]=1; for(ll v:adj[u]){ if(v==p) continue; dfs(v,u); dp[u][0]=dp[u][0]*((dp[v][0]+dp[v][1])%mod)%mod; dp[u...
0
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)(1e9 + 7); long long modpow(long long a, long long b) { if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2) * (b & 1 ? a : 1) % mod; } long long getbase(long long a, int base) { long long b = 1LL << base; return 1LL * ((a...
3
#include <iostream> #include <set> using namespace std; int main() { int n; multiset<int> s; cin >> n; for(int i=0;i<n;i++){ int a; cin >> a; a = -a; auto itr = s.upper_bound(a); if(itr != s.end()){ s.erase(itr); } s.insert(a); ...
0
#include <bits/stdc++.h> using namespace std; bool cmp(const pair<int, int> &a, const pair<int, int> &b) { if (a.second != b.second) { return a.second > b.second; } return a.first > b.first; } pair<int, int> ar[1010]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", ...
2
#include <bits/stdc++.h> using namespace std; int n, m; const int N = 1e6 + 2; struct Line { int y, xl, xr, v; Line() {} Line(int y, int xl, int xr, int v) : y(y), xl(xl), xr(xr), v(v) {} bool operator<(const Line &rhs) const { return y < rhs.y; } }; vector<Line> lines; int x[N], y[N]; struct Tree { int data[...
3
#include <bits/stdc++.h> using namespace std; double ans, res, n, m, i, j, all, now; double DP[1002][1002]; int main() { cin >> n >> m; DP[0][0] = 1; for (i = 1; i <= n; i++) for (j = 0; j <= min((int)i, int(m)); j++) { if (j >= 1) DP[(int)i][(int)j] = DP[(int)i - 1][(int)j - 1] * (m...
3
#include <bits/stdc++.h> using namespace std; const int N = 200010; typedef long long LL; int fa[N], p[N], c0[N], c1[N]; struct node { int u, c0, c1; bool operator < (const node &b) const { LL t1 = (LL)c1 * b.c0, t2 = (LL)c0 * b.c1; if (t1 != t2) return t1 < t2; return u < b.u; } }; int find(int x) ...
0
#include<iostream> #include<cstdio> #include<algorithm> #include<map> #include<string> using namespace std; struct Edge{ int a,b,d; bool operator<(const Edge a)const{ return d<a.d; } }; int par[100],rank_[100]; void init(int n){ for(int i=0;i<n;i++) par[i] = i, rank_[i] = 1; } int find(int x...
0
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int kMaxn = 55; int n, a[kMaxn], b[kMaxn]; pair<int, int> c[kMaxn]; int main() { static int i, j, x, y, ans; scanf("%d", &n); for (i = 1; i <= n; ++i) { scanf("%d", a + i); c[i].first = a[i]; c[i].second = i; } sor...
2
#include <bits/stdc++.h> using namespace std; int n, m, col[1005]; vector<int> G[1005]; bool ok = 1; bool vis[1005]; int dist[1005], cno[1005], idx = 0, ans[1005]; void dfs(int u, int co) { cno[u] = idx; col[u] = co; for (int i = 0; i < G[u].size(); i++) { if (!col[G[u][i]]) dfs(G[u][i], -co); else ...
5
#include <bits/stdc++.h> using namespace std; int n, a[100100], dp[100100], st, dr, mid; int bs(int val, int idx) { st = 1; dr = idx - 1; if (a[dr] < val) return -1; if (a[1] >= val) return 0; while (st <= dr) { mid = st + dr >> 1; if (a[mid] >= val) dr = mid - 1; else st = mid + 1; ...
4
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> mp; #define inf 1e9 int main(){ bool f = true; while(1){ int a,b; cin>>a>>b; if(a==0)break; if(f){ f = false; }else{ cout<<endl; } vector<int> ans; for(int i=a;i<=b;i++){ if(i%400==0){ ans.push_back(i); }el...
0
#include <bits/stdc++.h> int n, i, j, tot, d, k, tt, tot1; int a[100010], p[100010], f[100010], s[100010], a1[1000010], b1[1000010]; int pp(int); int swap(int, int); int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); p[a[i]] = i; } f[1] = 0; for (i = 2; i <= n; i++) { if ...
3
#include<stdio.h> #include<string.h> #include<math.h> int main(void) { int a,s,d,f,g,h,i,j,k; char z[10]; while(scanf("%s %d %d",z,&a,&s)!=EOF){ d=a*200+s*300; f=a+s; printf("%s %d %d\n",z,f,d); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXM = 100005, MAXN = 5005; const double MAXL = 100000.000; struct edge { int u, v, num; double w, delta; bool choose; bool st_edge() { return u == 1 || v == 1; } }; edge e[MAXM]; int n, m, k; int f[MAXN]; bool cmp(edge e1, edge e2) { return e1.w + e1.delt...
5
#include<bits/stdc++.h> using namespace std; constexpr int N = 100005; struct Edege{ int u, v, w; bool operator < (const Edege &b) const{ return w < b.w; } }; struct Node{ int id, x; bool operator < (const Node &b) const { return x < b.x; } }; int fa[N], cnt; Node a[N], b[N]; Edege e[N * 3]; v...
0
#include <bits/stdc++.h> using namespace std; int i, n, m, q, p, j, cnt; long long sum[22][2]; int a[(1 << 20) + 1], b[(1 << 20) + 1]; long long ans; void solve(int dep, int l, int r) { int mid, x, y, z, i; if (dep == 0) return; mid = (l + r) / 2; solve(dep - 1, l, mid); solve(dep - 1, mid + 1, r); cnt = 0;...
3
#include "bits/stdc++.h" using namespace std; #include "string" #define int long long #define pi pair <int, int> #define ff first #define ss second #define boost ios::sync_with_stdio(false);cin.tie(nullptr) #define endl '\n' int32_t main() { boost; int n; cin >> n; vector < int > a(n), b(n); for(int &i : a) cin...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const double EPS = 1e-7; long long data[200005]; long long query(int x) { long long sum = 0; for (; x > 0; x -= (x & -x)) sum += data[x]; return sum; } void update(int x, int val) { for (; x < 200005; x += (x & -x)) data[x] += val; } void up...
3
/* _/ _/ _/_/_/ _/ _/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/ _/_/ _/_/ _/_/ _/_/ _/ */ #include<iostream> #include<algorithm> #include<cmath> #i...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 8 * 1e18; const int big = 1e6 + 7; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long power(long long x, long long y, long long p = mod) { long long res = 1; x %= p; wh...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 10; struct Point { int x, y; } p[MAX]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y); int minx = 1e9, miny = 1e9; int maxx = -1e9, maxy = -1e9; for (int i = 0; i < n; i++) { minx = min(minx,...
5
#include <bits/stdc++.h> using namespace std; int main(){ int K,T; cin>>K>>T; int a[T]; for(int i=0;i<T;i++){ cin>>a[i]; } sort(a,a+T); int d=a[T-1]; if(d>K-d+1){ cout<<d-(K-d)-1<<endl; return 0; } cout<<0<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int ar[200005]; char ch[200005]; int n, m, ii, k; long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } long long mul(long long a, long long b) { a *= b; a %= 1000000007; return a; } void solve() { scanf("%d%s", &n...
6
#include <bits/stdc++.h> using namespace std; const int N = 3e5; vector<pair<long long, long long> > adj[N]; long long n; long long dfs(long long node, long long par) { long long ans = 0; for (int i = 0; i < adj[node].size(); i++) { long long nn = adj[node][i].first; long long ncost = adj[node][i].second; ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; int main() { int n, m, l[maxn], r[maxn], cnt[maxn] = {0}, tot = 0; cin >> n >> m; for (int i = 0; i < m; i++) { scanf("%d%d", &l[i], &r[i]); for (int j = l[i]; j <= r[i]; j++) { cnt[j]++; } } for (int i = 1; i <= n; i++) ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1010; namespace Solver { int n; int64_t ans; map<pair<int, int>, int64_t> a; void solve() { cin >> n; for (int i = 1; i <= n; ++i) { string s; cin >> s; vector<int> b; for (int c : s) { if (c == '(') { b.push_back(0); } ...
3
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& in, vector<T>& v) { for (long long i = 0; i < ((int)(v).size()); i++) cin >> v[i]; return in; } template <typename T, typename second> istream& operator>>(istream& in, pair<T, second>& p) { cin >> p.first >> p.second;...
3
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
2
#include <bits/stdc++.h> using namespace std; long long n, ans; int l; string k; long long powx(long long x, int y) { if (y == 0) return 1; long long s = powx(x, y / 2); if (y % 2) return s * s * x; else return s * s; } int main() { scanf("%I64d", &n); long long t = n; while (t > 0) { t /= 10L...
4
#include <bits/stdc++.h> using namespace std; int n, p, k; int main() { cin >> n >> p >> k; if (p - k > 1) cout << "<<" << ' '; for (int i = max(1, p - k); i < p; i++) { cout << i << ' '; } cout << "(" << p << ")" << ' '; for (int i = p + 1; i <= min(p + k, n); i++) { cout << i << ' '; } if (p +...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int deletes(vector<int> &v, int l, int h) { int me = INT_MAX; int r = 0; int a = l; for (int i = l; i <= h; ++i) { me = min(me, v[i]); } for (int i = l; i <= h; ++i) { v[i] -= me; } for (int i = l; i <= h; ++i) { if (v[i] ==...
5
#include <bits/stdc++.h> #include <cmath> using namespace std; typedef long long ll; //typedef unsigned long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) //#define rep(i, n) for (ll i = 0; i < (n); ++i) //#define sz(x) ll(x.size()) //typedef pair<ll, int> P; typedef pair<ll, ll> P; //const double INF = 1e...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 2e9 + 1; int main() { ios_base::sync_with_stdio(false); long long n, k; cin >> n >> k; vector<long long> a(n), b(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { cin >> b[i]; } long long lf = 0, r...
4
#include <bits/stdc++.h> using namespace std; int main() { int i, a = 0, d = 0; string n; getline(cin, n); string s; getline(cin, s); for (i = 0; i < s.length(); i++) { if (s[i] == 'A') a++; if (s[i] == 'D') d++; } if (a > d) cout << "Anton"; else if (d > a) cout << "Danik"; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { char A[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; string str; cin >> str; int z = A[0]; int k{0}, l{0}, n{0}; for (int i =...
1
#include <iostream> #include <cstdio> #include <iomanip> #include <vector> #include <map> #include <set> #include <queue> #include <bitset> #include <stack> #include <utility> #include <numeric> #include <algorithm> #include <functional> #include <cctype> #include <complex> #include <string> #include <sstream> #include...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); const double EPS = 1e-10; inline bool isVowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; } int main() { ios_b...
3
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } template <typename T...
3
#include<cstdio> #include<cstdlib> #include<string> #include<iostream> using namespace std; struct Node{ Node *r,*l,*p; int key; }; Node *root, *NIL; void insert(int k){ Node *y = NIL; Node *x = root; Node *z; z =(Node *)malloc(sizeof(Node)); z->key = k; z->l = NIL; z->r = NIL; while(x!=NIL){ ...
0
#include <bits/stdc++.h> using namespace std; long long base1 = 403007, base2 = 403963, p1 = 1e9 + 7, p2 = 1e9 + 9, po1[400005], po2[400005]; int n; vector<int> adj[100005]; map<pair<int, int>, int> mp; int ty[100005], cnt = 0; pair<int, int> hsh[100005]; void dfs(int x, int p) { long long hsh1 = 0, hsh2 = ...
4
#include <bits/stdc++.h> using namespace std; char s[300005]; int main() { cin >> s; long long ans = 0; int len = strlen(s); int r = len; for (int i = len - 1; i >= 0; i--) { r = min(r, i + 9); for (int j = 1; i + 2 * j < r; j++) { if (s[i] == s[i + j] && s[i] == s[i + 2 * j]) { r = min(...
4
#include <bits/stdc++.h> using namespace std; void _fill_int(int* p, int val, int rep) { int i; for (i = 0; i < rep; i++) p[i] = val; } signed long long GETi() { signed long long i; scanf("%lld", &i); return i; } int N, M; string S[2]; const int sp = 1000; signed long long dist[2][300000][2][2]; signed long l...
5
#include <bits/stdc++.h> using namespace std; long long pd[100][100][100]; int t, B, G; int v[100]; long long solve(int pos, int b, int g) { if (pd[pos][b][g] != -1) return pd[pos][b][g]; if (b + g == t) { if (g >= 1 && b >= 4) return 1; return 0; } if (pos == G + B) return 0; long long ans = 0; if ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1000100; int dp[N][2], n, a[N]; string s; int f(int idx, bool goingOn) { if (idx == n) { return 0; } if (dp[idx][goingOn] != -1) { return dp[idx][goingOn]; } int ans = 100000000; if (goingOn) { if (a[idx] == 1) { ans = min(ans, f(...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int add(int a, int b) { long long x = a + b; if (x >= 998244353) x -= 998244353; if (x < 0) x += 998244353; return x; } long long mul(long long a, long long b) { return (a * b) % 998244353; } long long pw(long long a, long long b) { long...
5
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } struct P { long long x, y; P(doub...
5
#include <bits/stdc++.h> using namespace std; bool deb_mode = 0; class debugger { vector<string> vars; public: template <typename T> debugger &operator,(const T v) { stringstream ss; ss << v, vars.push_back(ss.str()); return *this; } void printall() { int j = 0, l = vars.size(); for (int...
2
#include <bits/stdc++.h> using namespace std; long int mod = 1000000007; int main() { map<char, int> m; string s; getline(cin, s); for (int i = 0; i < s.length(); i++) { if (s[i] != ' ') m[s[i]]++; } string a; getline(cin, a); bool ans = true; for (int i = 0; i < a.length(); i++) { if (a[i] !=...
2
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9 + 7; int main() { ll T1, T2; cin >> T1 >> T2; ll A1, A2; cin >> A1 >> A2; ll B1, B2; cin >> B1 >> B2; if (A1 > B1) { swap(A1, B1); swap(A2, B2); } ll diff = A1 * T1 + A2 * T2 - (B1*T1 + B2 * T2);...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char s[N]; int n, w[N]; bool ctrl(int x) { int pk = 0, exp = 0; for (int i = 1; i <= n; i++) { if (s[i] == '*' && i > exp && !pk) pk = i; if (s[i] == 'P') { if (pk == 0) exp = i + x; else { int dis = i - pk; ...
5
#include <iostream> using namespace std; int main(){ int x; cin >> x; cout << ((x<1200) ? "ABC" : "ARC")<< endl; }
0
#include<bits/stdc++.h> using namespace std; const int N=510; int a[N][N]; int main(){ int n,m,q;scanf("%d%d%d",&n,&m,&q); for(int i=1,x,y;i<=m;++i) scanf("%d%d",&x,&y),a[x][y]++; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) a[i][j]+=a[i][j-1]; for(int i=1,x,y;i<=q;++i){ int ans=0; scanf("%d%d",&x,&y); f...
0
#include <iostream> using namespace std; #define MAX 100000 typedef long long llong; int n,k; llong T[MAX]; int check(long p){ int i =0; for (int j=0;j<k;j++){ llong s=0; while(s+T[i]<=p){ s +=T[i]; i++; if (i==n) return n; } } return i; } int solve(){ llong left =0; llong right = 100000 * 1000...
0
#include <bits/stdc++.h> using namespace std; using cat = long long; struct group { char c; int l, r; group operator+(int x) const { return {c, l + x, r + x}; } group operator-(int x) const { return {c, l - x, r - x}; } }; void apply(vector<group>& gA, vector<group>& gB, int prefA, int prefB, vector<...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> elements; map<int, int> max_positions; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (max_positions[a] < i) { max_positions[a] = i; } elements.push_back(a); } int count = 1; int current_...
5
#include<iostream> using namespace std; int main() { int R0,W0,C,R; while(true) { cin >> R0 >> W0 >> C >>R ; if(R0 == 0) break; double d = static_cast<double>(C*W0-R0)/R; if(d>0&&(int)d==d)cout << (int)d << endl; else if (d>0)cout << (int)d+1 << endl; else cout << 0 << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, ss = 0, su = 0; string s; cin >> n >> s; int m = n / 2 - 1; for (int i = 0; i <= m; i++) { if (s[i] == '4' || s[i] == '7') ss += (s[i] - '0'); else { cout << "NO"; return 0; } } for (int i = m + 1; i < n; i++) ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; vector<int> pr; bool saw[maxn]; void gherbal(int mx) { for (int i = 2; i <= mx; i++) { if (!saw[i]) { pr.push_back(i); for (int j = 2 * i; j <= mx; j += i) { saw[j] = true; } } } } void printvec(vector<int> v)...
5
#include <bits/stdc++.h> using namespace std; int min(int a, int b, int c) { if (a <= b && a <= c) return a; else if (b <= a && b <= c) return b; else return c; } int main() { string firstword, secondword; cin >> firstword >> secondword; int x = firstword.size(); int y = secondword.size(); i...
4
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, t, d; cin >> v1 >> v2 >> t >> d; int ans = 0; for (int i = 0; i <= t - 2; i++) { int s1, s2; s1 = v1 + (i * d); s2 = v2 + ((t - i - 2) * d); if (abs(s1 - s2) <= d) { int now = v1; for (int j = 0; j < i; j++) { ...
2
#include <bits/stdc++.h> using namespace std; vector<pair<int, char>> ans; int main() { int n, m, i = 1, j = 1, moves = 0; long long k, t = 0; cin >> n >> m >> k; if (k > 4 * m * n - 2 * m - 2 * n) { cout << "NO\n"; return 0; } cout << "YES\n"; if (m == 1) { if (n - 1 >= k) { cout << 1 <...
4
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); string a, b; while (cin >> a >> b) { unsigned int len = a.size(); int ans = 0; bool OK = true; map<int, int> dic; for (unsigned int i = 0; i < len; ++i) { if (a.at(i) != b.a...
2
#include <bits/stdc++.h> using namespace std; int dp[2001][10][715]; int tr[22222]; int inv[22222]; int su[2001][2]; int tr2[22222]; int ten[5] = {1, 10, 100, 1000, 10000}; struct fq { int x, y, z; }; queue<fq> q; int pls(int xx, int yy, int zz) { return tr[tr2[xx + 1000 * zz]]; } int can(int xx, int yy) { int rev ...
3
#include <bits/stdc++.h> using namespace std; map<string, long long> M; map<long long, string> M1; long long snm[2018]; bool flag[2018]; vector<string> ans; long long Time; vector<pair<string, string> > ANS; long long find(long long v) { if (snm[v] != v) return snm[v] = find(snm[v]); else return v; } void u...
2
#include <bits/stdc++.h> long long num[1000000], num1[1000000], num2[1000000]; long long solve(long long a) { long long i; i = 0; while (a > 0) { i += a & 1; a = a >> 1; } return i; } long long ans1[1000000], ans2[1000000]; int main() { long long i, j, k, a, b, c, n, m, ans; scanf("%lld%lld", &n, ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n), g(n); for (int i = 0; i < n; i++) { cin >> v[i]; g[i] = v[i]; } sort(g.begin(), g.end()); int d = 0; for (int i = 0; i < n; i++) { if (v[i] != g[i]) d++; } if (d <= 2) cout << "YES"; else ...
1
#include <bits/stdc++.h> using namespace std; long long BIT1[1000010], BIT2[1000010], arr[1000010], val[1000010]; map<long long, long long> m; long long ans[1000010]; void pointupdate(long long index, long long val, long long n, long long BIT[]) { for (long long i = index; i <= n; i += (i & (-i))) { BIT[i] += val...
5
#include <bits/stdc++.h> using namespace std; set<char> s; map<string, int> mp; map<char, int> mp2; vector<int> p, rk; int getp(int v) { if (v == p[v]) return v; return p[v] = getp(p[v]); } void join(int u, int v) { u = getp(u); v = getp(v); if (u == v) return; if (rk[u] < rk[v]) swap(u, v); rk[u] += rk[v...
4
#include <bits/stdc++.h> using namespace std ; const int MAX = 3e5 + 10 ; int r[MAX] , c[MAX] , freq[MAX] ; vector<int>v[MAX] ; int n , m , q ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m>>q ; int Max = 0 ; while(q--) { int i , j ; cin>>i>>j ; r[i]++ , c[j]++ ; Max = max(Max , ...
0
#include <bits/stdc++.h> using namespace std; int m, k, p; vector<int> v[100005]; int N[100005], M; void DFS(int dep, int nw, int pr) { N[dep]++, M = max(M, dep); for (int i = 0; i < v[nw].size(); i++) if (pr != v[nw][i]) DFS(dep + 1, v[nw][i], nw); } void INIT() { int a, b; scanf("%d%d%d", &m, &k, &p); f...
4
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <set> #include <string> #include <iostream> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000001 using namespace std; int div_row[8] = {-1,-1,-1,0,0,1,1,1},d...
0
#include <bits/stdc++.h> int a[200000]; int main(void) { int n, m, i, l, r, sum1 = 0, sum2 = 0, t; while (scanf("%d%d", &n, &m) != EOF) { for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] == 1) sum1++; else sum2++; } for (i = 0; i < m; i++) { scanf("%d%d", &l...
1
#include <bits/stdc++.h> using namespace std; int main() { char a[100]; cin >> a; int i, c = 1; int b = strlen(a); for (i = 0; i < b; i++) { if (a[i] == '1') { if (a[i + 1] == '1') { c++; if (c == 7) break; } else c = 1; } else if (a[i] == '0') { if (a[i + 1] ...
1
#include <iostream> #include <bits/stdc++.h> int k,m,n; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int t; scanf("%d",&t); for(int i=0;i<t;i++){ scanf("%d %d %d",&n,&m,&k); if(n*m-1==k){ printf("YES\n"); } else{ ...
2