contest_id
stringclasses
33 values
problem_id
stringclasses
14 values
statement
stringclasses
181 values
tags
listlengths
1
8
code
stringlengths
21
64.5k
language
stringclasses
3 values
1322
A
A. Unusual Competitionstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputA bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example; sequences "(())()", "()" and "(()(()))" are cor...
[ "greedy" ]
#include<stdio.h> char c[1000002];int n,cnt=0,v=0; int main(){ scanf("%d%s",&n,c+1); for(int i=1;i<=n;i++){ if(c[i]=='(')v++; else v--; if(v<0||(v==0&&c[i]=='('))cnt++; }printf("%d",v?-1:cnt); }
cpp
1311
C
C. Perform the Combotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons ...
[ "brute force" ]
#include<iostream> #include<cstring> #include<vector> #include<map> #include<queue> #include<unordered_map> #include<cmath> #include<cstdio> #include<algorithm> #include<set> #include<cstdlib> #include<stack> #include<ctime> #define forin(i,a,n) for(int i=a;i<=n;i++) #define forni(i,n,a) for(int i=n;i>=a;i--) #define f...
cpp
1315
A
A. Dead Pixeltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputScreen resolution of Polycarp's monitor is a×ba×b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x,y)(x,y) (0≤x<a,0≤y<b0≤x<a,0≤y<b). You can consider columns of pixels to ...
[ "implementation" ]
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back int main() { int t; ll a,b,x,y; cin>>t; while(t--){ cin>>a>>b>>x>>y; ll ans,ans1,ans2,ans3,ans4; ans = ans1 = ans2 = ans3 = ans4 = 0; ans1 = a * y; ans2 = b * x; ...
cpp
1296
E2
E2. String Coloring (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a hard version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format a...
[ "data structures", "dp" ]
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define S second #define F first #define pb push_back using namespace std; typedef long long ll; const int N = 2e5 + 123; ll n, a, b, k; vector <ll> dp(N, 1); vector <ll> dpn(N); string s; int main() { cin >> n >> s; for(int i = 0; i < n; ...
cpp
1288
B
B. Yet Another Meme Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers AA and BB, calculate the number of pairs (a,b)(a,b) such that 1≤a≤A1≤a≤A, 1≤b≤B1≤b≤B, and the equation a⋅b+a+b=conc(a,b)a⋅b+a+b=conc(a,b) is true; conc(a,b)conc(a,b)...
[ "math" ]
#include <bits/stdc++.h> using namespace std; using ll=long long; bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) ...
cpp
1304
F2
F2. Animal Observation (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraint on kk.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The ...
[ "data structures", "dp", "greedy" ]
///KoJa #include<bits/stdc++.h> using namespace std; #define task "test" #define vec vector #define fi first #define se second #define SZ(a) (a).begin(), (a).end() #define SZZ(a, Begin, End) (a) + (Begin), (a) + (Begin) + (End) #define BIT(n) (1LL << (n)) #define MASK(x, i) (((x) >> (i))&1) #define pb push_b...
cpp
1285
D
D. Dr. Evil Underscorestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; as a friendship gift, Bakry gave Badawy nn integers a1,a2,…,ana1,a2,…,an and challenged him to choose an integer XX such that the value max1≤i≤n(ai⊕X)max1≤i≤n(ai⊕X) is minimum possible, whe...
[ "bitmasks", "brute force", "dfs and similar", "divide and conquer", "dp", "greedy", "strings", "trees" ]
#include <bits/stdc++.h> using namespace std; #define ll long long int ll f(ll bit,vector<ll> &a){ if(bit==-1){ return 0; } vector<ll> pre,ab; ll n=a.size(); for(ll i=0;i<n;i++){ if(((1<<bit)&a[i])>0){ pre.push_back(a[i]); } else{ ...
cpp
1312
B
B. Bogosorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a1,a2,…,ana1,a2,…,an. Array is good if for each pair of indexes i<ji<j the condition j−aj≠i−aij−aj≠i−ai holds. Can you shuffle this array so that it becomes good? To shuffle an array m...
[ "constructive algorithms", "sortings" ]
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> #include <cstring> #include <unordered_set> #include <set> #include <stack> #include <map> #include <cmath> #include <sstream> #include <queue> #define int long long #define yes cout<<"YES"<<'\n' #define no c...
cpp
1291
A
A. Even But Not Eventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a number ebne (even but not even) if and only if its sum of digits is divisible by 22 but the number itself is not divisible by 22. For example, 1313, 12271227, 185217185217 are ebne num...
[ "greedy", "math", "strings" ]
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; int main () { cin.tie(0), ios::sync_with_stdio(0); int t, n; cin >> t; while (t--) { cin >> n; vi a(n); string s; cin >> s; int mod = 0; for (int i = 0; i < n; i++) { a[i] = s[i] - '0'; m...
cpp
1320
D
D. Reachable Stringstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem; we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a...
[ "data structures", "hashing", "strings" ]
#include<bits/stdc++.h> using namespace std; #define int long long const int N=2e6,P=998244353; int n,m,b[N],s[N],f[N][2],x,y,z; string a; int H(int l,int r,int x) { return (f[r][x]-f[l-1][x]*b[s[r]-s[l-1]]%P+P)%P; } signed main() { cin>>n>>a>>m,a=' '+a,b[0]=1; for(int i=1;i<=n;i++) b[i]=3*b[i-1]%P,s[i]=s[i-1]+(a[i]=='...
cpp
1290
C
C. Prefix Enlightenmenttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn lamps on a line, numbered from 11 to nn. Each one has an initial state off (00) or on (11).You're given kk subsets A1,…,AkA1,…,Ak of {1,2,…,n}{1,2,…,n}, such that the intersection of...
[ "dfs and similar", "dsu", "graphs" ]
/* * In the name of GOD */ #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair <int, int> pii; #define F first #define S second #define mk make_pair const int N = 301234; vector <int> a[N], b[N]; int w[N], force[N], ans[N][2], all; bool f[N], s[N]; int get (int v) { if (force[v] =...
cpp
13
B
B. Letter Atime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.You are given three segments on the plane. Th...
[ "geometry", "implementation" ]
#include <iostream> #include "vector" #include "string" #include "set" #include "cmath" #include "iomanip" #include "algorithm" #include "map" #include "unordered_set" using namespace std; typedef long long ll; typedef long double ld; typedef string str; const ld PI = acos(-1); void f() { ios::sync_w...
cpp
1313
D
D. Happy New Yeartime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBeing Santa Claus is very difficult. Sometimes you have to deal with difficult situations.Today Santa Claus came to the holiday and there were mm children lined up in front of him. Let's number them fr...
[ "bitmasks", "dp", "implementation" ]
// LUOGU_RID: 101831831 // Problem: Happy New Year // Contest: Luogu // URL: https://www.luogu.com.cn/problem/CF1313D // Memory Limit: 500 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) //不回家了,我们去鸟巢! #include<bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("un...
cpp
1296
D
D. Fight with Monsterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn monsters standing in a row numbered from 11 to nn. The ii-th monster has hihi health points (hp). You have your attack power equal to aa hp and your opponent has his attack power equal...
[ "greedy", "sortings" ]
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" using namespace __gnu_pbds; using namespace std::chrono;...
cpp
1316
F
F. Battalion Strengthtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn officers in the Army of Byteland. Each officer has some power associated with him. The power of the ii-th officer is denoted by pipi. As the war is fast approaching, the General would ...
[ "data structures", "divide and conquer", "probabilities" ]
#include<bits/stdc++.h> using namespace std; const int maxn=600005; const int mod=(1e9+7); int n,m,i,j,t,k,s,ls[maxn],tls,a[maxn],b[maxn]; int pla[maxn],chg[maxn],two[maxn]; int sum[maxn<<2],cnt[maxn<<2],lef[maxn<<2],rig[maxn<<2]; inline int Pow(int x,int y) { int ret=1; while (y) { if (y&1) ret=1ll*ret*x%mod; x=1ll*...
cpp
1299
E
E. So Meantime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is interactive.We have hidden a permutation p1,p2,…,pnp1,p2,…,pn of numbers from 11 to nn from you, where nn is even. You can try to guess it using the following queries:?? kk a1a1 a2a2 …… akak.I...
[ "interactive", "math" ]
#include <cstdio> #include <vector> #include <iostream> using namespace std; const int M = 805; int read() { int x=0,f=1;char c; while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;} while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();} return x*f; } int n,p[M],id[M],rd[M]; int ask(vector<int> v) { printf("? %d...
cpp
1304
A
A. Two Rabbitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeing tired of participating in too many Codeforces rounds; Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller ...
[ "math" ]
//Je Cruis En Moi #include <bits/stdc++.h> using namespace std; const int MAXN = 1e6+ 10; int a[MAXN], mn[MAXN],mx[MAXN]; int main () { int t; cin >> t; while (t --) { long long x, y, a, b; cin >> x >> y >> a >> b; if ((y - x) % (a + b) == 0) cout << (y - x) / (a + b) << endl; else ...
cpp
1322
A
A. Unusual Competitionstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputA bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example; sequences "(())()", "()" and "(()(()))" are cor...
[ "greedy" ]
#include<iostream> #include<cstring> #include<vector> #include<map> #include<queue> #include<unordered_map> #include<cmath> #include<cstdio> #include<algorithm> #include<set> #include<cstdlib> #include<stack> #include<ctime> #define forin(i,a,n) for(int i=a;i<=n;i++) #define forni(i,n,a) for(int i=n;i>=a;i--) #define f...
cpp
1284
F
F. New Year and Social Networktime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputDonghyun's new social network service (SNS) contains nn users numbered 1,2,…,n1,2,…,n. Internally, their network is a tree graph, so there are n−1n−1 direct connections between each user....
[ "data structures", "graph matchings", "graphs", "math", "trees" ]
# include <bits/stdc++.h> using namespace std; int n,ecnt,go[1000010],adj[500010],nxt[1000010],fa[500010],lg[250010],d[250010],bz[30][250010]; struct disjoint_set_union { struct node { int fa,sz;} f[250010]; void init_(int x) { for (int i=1;i<=x;i++) f[i].fa=i, f[i].sz=1; } int find_(in...
cpp
1323
A
A. Even Subset Sum Problemtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array aa consisting of nn positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 22) or determine that there is no such subse...
[ "brute force", "dp", "greedy", "implementation" ]
#include <bits/stdc++.h> using namespace std; #define A first #define B second #define MP make_pair #define ms(a, x) memset(a, x, sizeof(a)) #define boost() ios_base::sync_with_stdio(false); cin.tie(); cout.tie() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long lo...
cpp
1304
B
B. Longest Palindrometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputReturning back to problem solving; Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "...
[ "brute force", "constructive algorithms", "greedy", "implementation", "strings" ]
#include "bits/stdc++.h" #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T>...
cpp
1316
B
B. String Modificationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a string ss of length nn. He decides to make the following modification to the string: Pick an integer kk, (1≤k≤n1≤k≤n). For ii from 11 to n−k+1n−k+1, reverse the substring s[i:i+k−1]s...
[ "brute force", "constructive algorithms", "implementation", "sortings", "strings" ]
#include<bits/stdc++.h> using namespace std; #define OM_NAMAH_SHIVAY ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define F first #define S second #define int long long #define pb push_back void solve(){ int n;cin>>n; string s;cin>>s; string temp=""; string ansst=s; in...
cpp
1301
C
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu...
[ "binary search", "combinatorics", "greedy", "math", "strings" ]
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int m= 998244353; ll mod (ll x){ return ((x%m+m)%m); } ll add(ll a , ll b){ return mod(mod(a)+mod(b)); } ll mul(ll a, ll b){ return mod(mod(a)*mod(b)); } int main(){ int t; cin>>t; while(t--){ ...
cpp
1324
C
C. Frog Jumpstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a frog staying to the left of the string s=s1s2…sns=s1s2…sn consisting of nn characters (to be more precise, the frog initially stays at the cell 00). Each character of ss is either 'L' or 'R'. It...
[ "binary search", "data structures", "dfs and similar", "greedy", "implementation" ]
#include <bits/stdc++.h> #define Source ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL); #define ll long long #define int long long #define ld long double #define Endl '\n' //#define t int t;cin>>t;while(t--) #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define sz(a) (in...
cpp
1141
E
E. Superhero Battletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA superhero fights with a monster. The battle consists of rounds; each of which lasts exactly nn minutes. After a round ends, the next round starts immediately. This is repeated over and over again.E...
[ "math" ]
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("Ofast")//Comment optimisations for interactive problems (use endl) #pragma GCC target("avx,avx2,...
cpp
1286
F
F. Harry The Pottertime limit per test9 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputTo defeat Lord Voldemort; Harry needs to destroy all horcruxes first. The last horcrux is an array aa of nn integers, which also needs to be destroyed. The array is considered destroyed if all its e...
[ "brute force", "constructive algorithms", "dp", "fft", "implementation", "math" ]
#include <cstdio> #include <map> #include <iostream> #include <set> #include <algorithm> #include <unordered_map> #include <bitset> #include <queue> #include <stack> #include <random> #include <cstring> #include <ctime> #include <cmath> #include <assert.h> using namespace std; #define LL long long #define pp pair<int,...
cpp
1312
A
A. Two Regular Polygonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers nn and mm (m<nm<n). Consider a convex regular polygon of nn vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) an...
[ "geometry", "greedy", "math", "number theory" ]
#include<bits/stdc++.h> using namespace std; #define w(t) int t;cin >> t; while(t--) #define ll long long #define get_arr(x,o,n) for(int i=o;i<n;i++){cin >> x[i];} #define fr(i,x,y) for(int i=x;i<y;i++) #define fr_rev(i,x,y) ...
cpp
1304
A
A. Two Rabbitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeing tired of participating in too many Codeforces rounds; Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller ...
[ "math" ]
#include <bits/stdc++.h> using namespace std; int main() { int t; std::cin >> t ; int x; int y; int a; int b; while (t--){ cin >> x >> y>> a>> b; int i = y - x ; int j = a + b ; if ( i % j == 0){ cout << i / j << "\n" ; } ...
cpp
1291
B
B. Array Sharpeningtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an array a1,…,ana1,…,an of nn non-negative integers.Let's call it sharpened if and only if there exists an integer 1≤k≤n1≤k≤n such that a1<a2<…<aka1<a2<…<ak and ak>ak+1>…>anak>ak+1>…>an. ...
[ "greedy", "implementation" ]
#include<bits/stdc++.h> using namespace std; #define ll long long vector<bool> primes; void seive(int n){ primes.resize(n+1, true); primes[0] = false; primes[1] = false; for(int i=2; i*i<=n; i++){ if(primes[i]){ for(int j=i*i; j<=n; j+=i) primes[j] = false; } } ...
cpp
1141
F2
F2. Same Sum Blocks (Hard)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is given in two editions; which differ exclusively in the constraints on the number nn.You are given an array of integers a[1],a[2],…,a[n].a[1],a[2],…,a[n]. A block is a sequence ...
[ "data structures", "greedy" ]
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using vi = vc<int>; using vl = vc<ll>; using vvi = vc<vi>; using vvl = vc<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define inf 0x3f3f3f3f #define...
cpp
1293
B
B. JOE is on TV!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output3R2 - Standby for ActionOur dear Cafe's owner; JOE Miller, will soon take part in a new game TV-show "1 vs. nn"!The game goes in rounds, where in each round the host asks JOE and his opponents a common q...
[ "combinatorics", "greedy", "math" ]
#include<bits/stdc++.h> using namespace std; #define N 200001 #define ll long long int main(){ ll n; cin>>n; double x=0.0; while(n>0){ x+=(double)1/n; n--; } cout<<setprecision(12)<<x<<endl; return 0; }
cpp
1316
C
C. Primitive Primestime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is Professor R's last class of his teaching career. Every time Professor R taught a class; he gave a special problem for the students to solve. You being his favourite student, put your heart in...
[ "constructive algorithms", "math", "ternary search" ]
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m,p; cin>>n>>m>>p; vector<int> a(n); vector<int> b(m); for(int i = 0; i<n; i++){ cin>>a[i]; } for(int i = 0; i<m; i++){ cin>>b[i]; } ...
cpp
1284
F
F. New Year and Social Networktime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputDonghyun's new social network service (SNS) contains nn users numbered 1,2,…,n1,2,…,n. Internally, their network is a tree graph, so there are n−1n−1 direct connections between each user....
[ "data structures", "graph matchings", "graphs", "math", "trees" ]
#include <bits/stdc++.h> #define SP putchar(' ') #define EL putchar('\n') #define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout) template <typename T> void read(T &); template <typename T> void write(const T &); const int N = 250005; namespace DSU { int find(int x); void merge(i...
cpp
1294
D
D. MEX maximizingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: for the array [0,0,1,0,2][0,0,1,0,2] MEX equals to 33 because numbers 0,10,1 and 22 are prese...
[ "data structures", "greedy", "implementation", "math" ]
#include <iostream> #include <ranges> #include <algorithm> #include <numeric> #include <vector> #include <array> #include <set> #include <map> #include <bit> #include <sstream> #include <list> #include <stack> #include <queue> #include <cmath> typedef long long integerType; typedef integerType z; type...
cpp
1296
E2
E2. String Coloring (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a hard version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format a...
[ "data structures", "dp" ]
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vb = vector<bool>; using vll = vector<ll>; using vs = vector<string>; #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define SZ(v) int(v....
cpp
1288
C
C. Two Arraystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that: the length of both arrays is equal to mm; each element of each array is an integer between 11 and nn (in...
[ "combinatorics", "dp" ]
// clang-format off #include<bits/stdc++.h> using namespace std; #ifdef LOCAL #include "deb/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define int long long typedef unsigned long long ull; typedef long double ld; ...
cpp
1305
G
G. Kuroni and Antihypetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni isn't good at economics. So he decided to found a new financial pyramid called Antihype. It has the following rules: You can join the pyramid for free and get 00 coins. If you are already...
[ "bitmasks", "brute force", "dp", "dsu", "graphs" ]
#include<bits/stdc++.h> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") using namespace std; int const lim=(1<<18)-1;long long res; int i,j,n,x,u,v,f[lim+5],cnt[lim+5]; int read(){ int x=0;char ch=getchar(); while (ch<'0'||ch>'9') ch=getchar(); while (ch>=...
cpp
13
B
B. Letter Atime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.You are given three segments on the plane. Th...
[ "geometry", "implementation" ]
#include <bits/stdc++.h> #define int long long using namespace std; struct point{ int x,y; }; struct line{ point p1,p2; }a[4]; int len_line_pow(line a){//求线段长度的平方 return (a.p1.x-a.p2.x)*(a.p1.x-a.p2.x)+(a.p1.y-a.p2.y)*(a.p1.y-a.p2.y); } bool check_same_point(point p1,point p2){//判断两点是否相同 ...
cpp
1285
D
D. Dr. Evil Underscorestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; as a friendship gift, Bakry gave Badawy nn integers a1,a2,…,ana1,a2,…,an and challenged him to choose an integer XX such that the value max1≤i≤n(ai⊕X)max1≤i≤n(ai⊕X) is minimum possible, whe...
[ "bitmasks", "brute force", "dfs and similar", "divide and conquer", "dp", "greedy", "strings", "trees" ]
#include <bits/stdc++.h> using namespace std; #define ll long long int //<min, x> pair<ll, ll> f(ll c, vector<ll> &a){ if(a.size() == 0 || c == 0){ return pair<ll, ll>(0, 0); } vector<ll> setBit; vector<ll> unsetBit; for(ll i = 0; i<a.size(); i++){ if((a[i] & c) ==...
cpp
1294
A
A. Collecting Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has three sisters: Alice; Barbara, and Cerene. They're collecting coins. Currently, Alice has aa coins, Barbara has bb coins and Cerene has cc coins. Recently Polycarp has returned from the ...
[ "math" ]
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int a, b, c, n; cin >> a >> b >> c >> n; int val = a; val = max(val, b); val = max(val, c); a = val - a; b = val - b; c...
cpp
1284
A
A. New Year and Namingtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHappy new year! The year 2020 is also known as Year Gyeongja (경자년; gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Ko...
[ "implementation", "strings" ]
#include <bits/stdc++.h> using namespace std; #define ll long long #define nl endl #define pb push_back const int N=1e5+10; #define uniq(v) (v).erase(unique(v.begin(),v.end()),(v).end()) void solve(){ ll n,m; cin>>n>>m; // cout<<m<<" "<<n<<nl; vector<string>v1(n),v2(m); for(ll i=0;i<n;i++){ cin>>v...
cpp
1325
C
C. Ehab and Path-etic MEXstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of nn nodes. You want to write some labels on the tree's edges such that the following conditions hold: Every label is an integer between 00 and n−2n−2 inclusiv...
[ "constructive algorithms", "dfs and similar", "greedy", "trees" ]
//DEVENDRA KUMAR #include <bits/stdc++.h> using namespace std; #define int long long int #define vi vector<int> #define pb push_back #define pii pair<int,int> #define F first #define S second #define rep(i,n) for(int i=0; i<n; i++) #define nl cout<<endl #define all(x) x.begin(),x.end() #define yes {cout<<"Y...
cpp
1320
A
A. Journey Planningtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTanya wants to go on a journey across the cities of Berland. There are nn cities situated along the main railroad line of Berland, and these cities are numbered from 11 to nn. Tanya plans her journey...
[ "data structures", "dp", "greedy", "math", "sortings" ]
#include<iostream> #include<cstring> #include<vector> #include<map> #include<queue> #include<unordered_map> #include<cmath> #include<cstdio> #include<algorithm> #include<set> #include<cstdlib> #include<stack> #include<ctime> #define forin(i,a,n) for(int i=a;i<=n;i++) #define forni(i,n,a) for(int i=n;i>=a;i--) #define f...
cpp
1305
G
G. Kuroni and Antihypetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni isn't good at economics. So he decided to found a new financial pyramid called Antihype. It has the following rules: You can join the pyramid for free and get 00 coins. If you are already...
[ "bitmasks", "brute force", "dp", "dsu", "graphs" ]
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define rep(i, a, b) for(int i = (a); i <= (b); i ++) #define per(i, a, b) for(int i = (a); i >= (b); i --) #define Ede(i, u) for(int i = head[u]; i; i = e[i].nxt) using namespace std; #define eb emplace_back inline int read() { ...
cpp
1291
A
A. Even But Not Eventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a number ebne (even but not even) if and only if its sum of digits is divisible by 22 but the number itself is not divisible by 22. For example, 1313, 12271227, 185217185217 are ebne num...
[ "greedy", "math", "strings" ]
#include<iostream> using namespace std; using ll = long long int ; int main() { ll t; cin>>t; for(int i=0;i<t;i++) { int n; cin>>n; string s; string ss=""; cin>>s; for(int i=0; i<n; i++) { if(s[i]=='1' || s[i]=='3' || s[i]=...
cpp
1307
G
G. Cow and Exercisetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John is obsessed with making Bessie exercise more!Bessie is out grazing on the farm; which consists of nn fields connected by mm directed roads. Each road takes some time wiwi to cross. She is ...
[ "flows", "graphs", "shortest paths" ]
// LUOGU_RID: 99528311 #include<iostream> #include<stdio.h> #include<ctype.h> #include<string.h> #include<queue> #define ll long long #define ld long double #define fi first #define se second #define pii pair<int,int> #define lowbit(x) ((x)&-(x)) #define popcount(x) __builtin_popcount(x) #define inf 0x3f3f3...
cpp
1311
B
B. WeirdSorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array aa of length nn.You are also given a set of distinct positions p1,p2,…,pmp1,p2,…,pm, where 1≤pi<n1≤pi<n. The position pipi means that you can swap elements a[pi]a[pi] and a[pi+1]a[pi+...
[ "dfs and similar", "sortings" ]
#include <bits/stdc++.h> #include <ext/rope> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // ███████╗████████╗███████╗██╗ ██╗ #define endl "\n" // ██╔════╝╚══██╔══╝██╔════╝██║ ██║ #define F f...
cpp
1312
E
E. Array Shrinkingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a1,a2,…,ana1,a2,…,an. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements ai=ai+1ai=ai+1 (if there is at least one such...
[ "dp", "greedy" ]
#include <iostream> using namespace std; const int N = 510; int dp[N][N], one[N][N], a[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; for(int i=1; i<=n; i++) dp[i][i] = 1, one[i][i] = a[i]; ...
cpp
1301
C
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu...
[ "binary search", "combinatorics", "greedy", "math", "strings" ]
#include <bits/stdc++.h> using namespace std; #define ll long long int void solve(){ ll n, m; cin >> n >> m; // if(m == 0){ // cout << 0 << endl; // return; // } ll ans = (n*(n+1))/2; ll z = n - m; // floor(z/(m+1)) * (m-x) + ceil(z/(m+1)) * (x) ...
cpp
1299
B
B. Aerodynamictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon PP which is defined by coordinates of its vertices. Define P(x,y)P...
[ "geometry" ]
#include <bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n; cin>>n; vector<pair<ll,ll>>a(n); for(ll...
cpp
1301
C
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu...
[ "binary search", "combinatorics", "greedy", "math", "strings" ]
#include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <unordered_set> #include <map> #include <set> #include <cmath> #include <algorithm> #include <functional> using namespace std; #define int long long int gauss(int x) { return x*(x+1)/2; } void solve() { in...
cpp
1284
E
E. New Year and Castle Constructiontime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputKiwon's favorite video game is now holding a new year event to motivate the users! The game is about building and defending a castle; which led Kiwon to think about the following puz...
[ "combinatorics", "geometry", "math", "sortings" ]
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "debug.h" #else #define debug(...) 1 #endif using ll = long long; using db = long double; using VS = vector<string>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using PLL = pair<ll, ll>; using MLL = m...
cpp
1285
E
E. Delete a Segmenttime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn segments on a OxOx axis [l1,r1][l1,r1], [l2,r2][l2,r2], ..., [ln,rn][ln,rn]. Segment [l,r][l,r] covers all points from ll to rr inclusive, so all xx such that l≤x≤rl≤x≤r.Segments can be ...
[ "brute force", "constructive algorithms", "data structures", "dp", "graphs", "sortings", "trees", "two pointers" ]
#include <bits/stdc++.h> #define name "" #define test "test" #define ll long long #define ld long double #define fi first #define se second #define pll pair < ll, ll > #define pii pair < int, int > #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(x) ((int)(x).size()) #define pb push...
cpp
1286
A
A. Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVadim loves decorating the Christmas tree; so he got a beautiful garland as a present. It consists of nn light bulbs in a single row. Each bulb has a number from 11 to nn (in arbitrary order), such that all th...
[ "dp", "greedy", "sortings" ]
#include<bits/stdc++.h> #define ls i<<1 #define rs i<<1|1 #define fi first #define se second #define min amin #define max amax #define pb push_back using namespace std; using ll=long long; using pii=array<int,2>; constexpr int N=60; constexpr int inf=1E9; constexpr int p=998244353; int qpow(int x,int n=p-...
cpp
1299
B
B. Aerodynamictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon PP which is defined by coordinates of its vertices. Define P(x,y)P...
[ "geometry" ]
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second void yes(){cout<<"YES\n";} void no(){cout<<"NO\n";} long long mod = 1e9+7; struct Point{ int x,y; }; void solve() { int n; cin >> n; vector<Point> P(n+1); for(int i=0;...
cpp
1141
A
A. Game 23time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp plays "Game 23". Initially he has a number nn and his goal is to transform it to mm. In one move, he can multiply nn by 22 or multiply nn by 33. He can perform any number of moves.Print the number of ...
[ "implementation", "math" ]
#import<iostream> int m,n,s;main(){std::cin>>n>>m;if(m%n)return std::cout<<-1,0;for(m/=n;~m%2||m%3<1;s++)m%2?m%3?:m/=3:m/=2;std::cout<<(m>1?-1:s);}
cpp
1296
F
F. Berland Beautytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn railway stations in Berland. They are connected to each other by n−1n−1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.You have a map of ...
[ "constructive algorithms", "dfs and similar", "greedy", "sortings", "trees" ]
#include <bits/stdc++.h> #include <cstdio> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair<long long,long long>, null_type,less<pair<long long,long long> >, rb_tree_tag,tree_order_statistics_node_update>...
cpp
1320
D
D. Reachable Stringstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem; we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a...
[ "data structures", "hashing", "strings" ]
// Problem: D. Reachable Strings // Contest: Codeforces - Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round) // URL: https://codeforces.com/contest/1320/problem/D // Memory Limit: 256 MB // Time Limit: 3000 ms // // Powered by CP Editor (https://cpeditor.org) #pragma GCC optimize("Ofast,unrol...
cpp
1315
B
B. Homecomingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a long party Petya decided to return home; but he turned out to be at the opposite end of the town from his home. There are nn crossroads in the line in the town, and there is either the bus or the tr...
[ "binary search", "dp", "greedy", "strings" ]
#include<bits/stdc++.h> #define int long long int #define rep(i,a,b) for(int i=a;i<b;i++) #define vi vector<int> #define vll vector<long long int> using namespace std; bool isPossible(int num,string &str,int a,int b,int have){ int total_cost = 0; char prev = 'Z'; for(int i=num;i<str.length();i++){ if(str...
cpp
1316
B
B. String Modificationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a string ss of length nn. He decides to make the following modification to the string: Pick an integer kk, (1≤k≤n1≤k≤n). For ii from 11 to n−k+1n−k+1, reverse the substring s[i:i+k−1]s...
[ "brute force", "constructive algorithms", "implementation", "sortings", "strings" ]
#include <bits/stdc++.h> using namespace std; #define ll long long string modify(string &s,int n,int k){ string result_prefix = s.substr(k - 1, n - k + 1); string result_suffix = s.substr(0, k - 1); if (n % 2 == k % 2) reverse(result_suffix.begin(), result_suffix.end()); return result_pre...
cpp
1290
B
B. Irreducible Anagramstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call two strings ss and tt anagrams of each other if it is possible to rearrange symbols in the string ss to get a string, equal to tt.Let's consider two strings ss and tt which are anagram...
[ "binary search", "constructive algorithms", "data structures", "strings", "two pointers" ]
#include<bits/stdc++.h> using namespace std; const int N=2e5+10; int pre[N][30]; string s; int main() { ios::sync_with_stdio(false);cin.tie(0); string s; cin>>s; int n=s.size(); s=' '+s; for(int i=1;i<=n;i++) { for(int j=0;j<26;j++) { pre[i][j]=pre[i-1][j]+(s[i]==j+'a'); } } int q; ...
cpp
1286
E
E. Fedya the Potter Strikes Backtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFedya has a string SS, initially empty, and an array WW, also initially empty.There are nn queries to process, one at a time. Query ii consists of a lowercase English letter cici and a n...
[ "data structures", "strings" ]
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <string> #pragma GCC optimize("Ofast") #pragma GCC target("avx,sse2,sse3,sse4,mmx,arch=cannonlake,tune=cannonlake") #define query(pos) (a[*lower_bound(stk + 1, stk + 1 + r, (pos))]) #define endl '\n' using std::cin; usin...
cpp
1312
E
E. Array Shrinkingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a1,a2,…,ana1,a2,…,an. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements ai=ai+1ai=ai+1 (if there is at least one such...
[ "dp", "greedy" ]
/* Your Mind Is Your Biggest Enemy */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize ("-O3") #define ll long long int #define ld long double #define ff first #define ss second /*...
cpp
1307
C
C. Cow and Messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However; Bessie is sure that there is a secret message hidden inside.The text is a string ss of lowercase Latin letter...
[ "brute force", "dp", "math", "strings" ]
// LUOGU_RID: 96383303 #include<bits/stdc++.h> using namespace std; string s; long long ans1; long long sum[205][205],ans[205]; int main(){ cin >> s; for(int i = 0;i < s.size();i++){ for(int j = 97;j <= 122;j++){ if(ans[j]){ sum[j][s[i]] += ans[j]; ans1 = max(ans1,sum[j][s[i]]); } } ans[s[i]]++; ans1 = max(ans1,ans[s[i...
cpp
1322
D
D. Reality Showtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA popular reality show is recruiting a new cast for the third season! nn candidates numbered from 11 to nn have been interviewed. The candidate ii has aggressiveness level lili, and recruiting this candi...
[ "bitmasks", "dp" ]
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define rep(i, a, b) for(int i = (a); i <= (b); i ++) #define per(i, a, b) for(int i = (a); i >= (b); i --) #define Ede(i, u) for(int i = head[u]; i; i = e[i].nxt) using namespace std; inline int read() { int x = 0, f = 1; char c =...
cpp
1300
B
B. Assigning to Classestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReminder: the median of the array [a1,a2,…,a2k+1][a1,a2,…,a2k+1] of odd number of elements is defined as follows: let [b1,b2,…,b2k+1][b1,b2,…,b2k+1] be the elements of the array in the sorted ord...
[ "greedy", "implementation", "sortings" ]
#include<bits/stdc++.h> using namespace std; int main() {int t; cin >> t; while(t--){ int n; cin >> n; int a[2 * n]; for(int i=0;i<2*n;i++){ cin >> a[i]; } sort(a,a + (2*n)); cout << a[n] - a[n-1] << endl; } return 0; }
cpp
1296
E1
E1. String Coloring (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easy version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format ...
[ "constructive algorithms", "dp", "graphs", "greedy", "sortings" ]
#include<bits/stdc++.h> using namespace std; #define ll long long #define debug(x) cout<<":["<<x<<"XE]"<<endl; #define debug2(x,y) cout<<":["<<x<<" "<<y<<"XE]"<<endl; #define _ ios_base::sync_with_stdio(false); #define mod 1000000007 #define mod2 998244353 #define inf LLONG_MAX #define yes cout << "YES\n" #...
cpp
1311
C
C. Perform the Combotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons ...
[ "brute force" ]
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define fastread() (ios_base:: sync_with_stdio(false), cin.tie(NULL)); //LL, other ways to simplify it?, tricks & math, backwards, constraints, //ll mod(1e9+7); void runCase() { vector<int> v(26, 0); int n; cin >>...
cpp
1325
B
B. CopyCopyCopyCopyCopytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEhab has an array aa of length nn. He has just enough free time to make a new array consisting of nn copies of the old array, written back-to-back. What will be the length of the new array's longe...
[ "greedy", "implementation" ]
//ABANOUB FAWAZ #include <iostream> #include <iomanip> #include<cmath> #include<string> #include<vector> #include<algorithm> #include<stack> #include<queue> #include<map> #include<set> #define ll long long using namespace std; void fast() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NU...
cpp
1303
F
F. Number of Componentstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix n×mn×m, initially filled with zeroes. We define ai,jai,j as the element in the ii-th row and the jj-th column of the matrix.Two cells of the matrix are connected if they sh...
[ "dsu", "implementation" ]
/* * @name Dinic algorithm * @description Algorithm for flow searching in O(n^2m) * */ /* Includes */ #include <bits/stdc++.h> /* Using libraries */ using namespace std; /* Defines */ #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define ld long double #define pb push_back #de...
cpp
1313
C2
C2. Skyscrapers (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version n≤500000n≤500000The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the constru...
[ "data structures", "dp", "greedy" ]
#include<iostream> #include<math.h> #include<algorithm> #include<string> #include<cstring> #include<string.h> #include<vector> #include<map> #include<cmath> #include<cstdio> #include<set> #include<deque> #include<queue> #include<stack> using namespace std; const int inf=0x3f3f3f3f,hamod=1e9+7,HAmod=1e9+9,mod=200907,N=1...
cpp
1292
C
C. Xenon's Attack on the Gangstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputINSPION FullBand Master - INSPION INSPION - IOLITE-SUNSTONEOn another floor of the A.R.C. Markland-N; the young man Simon "Xenon" Jackson, takes a break after finishing his project early (...
[ "combinatorics", "dfs and similar", "dp", "greedy", "trees" ]
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> g(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } vector par(n, vector<int>(n, -1)), sz(n, vector<int>(n, 1));...
cpp
1322
A
A. Unusual Competitionstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputA bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example; sequences "(())()", "()" and "(()(()))" are cor...
[ "greedy" ]
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int main() { long long n; cin>>n; string s; cin>>s; long long i=0,ct=0,ans=0; while (n--) { if(s[i]=='('){ct++;} else if(s[i]==')'){ct--;...
cpp
1310
C
C. Au Pont Rougetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVK just opened its second HQ in St. Petersburg! Side of its office building has a huge string ss written on its side. This part of the office is supposed to be split into mm meeting rooms in such way th...
[ "binary search", "dp", "strings" ]
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1005, M = 1000005; int n, m, cnt, lcp[N][N]; ll k, f[N][N], g[N][N]; char s[N]; struct str {int l, r;} a[M]; bool operator< (const str &x, const str &y) { int l1 = x.l, r1 = x.r, l2 = y.l, r2 = y.r; int lp = lcp[l1][l2], len = min(r1 ...
cpp
1307
D
D. Cow and Fieldstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie is out grazing on the farm; which consists of nn fields connected by mm bidirectional roads. She is currently at field 11, and will return to her home at field nn at the end of the day.The Cowfe...
[ "binary search", "data structures", "dfs and similar", "graphs", "greedy", "shortest paths", "sortings" ]
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll tc = 1; // cin >> tc; while (tc--) { ll n, m...
cpp
1141
B
B. Maximal Continuous Resttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach day in Berland consists of nn hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a1,a2,…,ana1,a2,…,an (each aiai is either 00 or 11)...
[ "implementation" ]
#include <bits/stdc++.h> using namespace std; #define sz(s) (int)(s.size()) #define all(v) v.begin(),v.end() #define clr(d, v) memset(d,v,sizeof(d)) #define ll long long void file() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int main() { file(); int n;...
cpp
1295
C
C. Obtain The Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings ss and tt consisting of lowercase Latin letters. Also you have a string zz which is initially empty. You want string zz to be equal to string tt. You can perform the followi...
[ "dp", "greedy", "strings" ]
// Time Limit: 2023-02-13 11:44:50 // Just_Chill #include<bits/stdc++.h> #define int long long #define mod (int)1000000007l #define nl cout<<"\n"; #define pb push_back #define all(a) a.begin(),a.end() #define pii pair<int,int> #define vi vector<int> #define vpi vector<pair<int,int>> #define vvi vector<vect...
cpp
1295
B
B. Infinite Prefixestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string ss of length nn consisting of 0-s and 1-s. You build an infinite string tt as a concatenation of an infinite number of strings ss, or t=ssss…t=ssss… For example, if s=s= 10010, ...
[ "math", "strings" ]
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define r_all(x) x.rbegin(), x.rend() #define sz(x)(ll) x.size() #define g_max(x, y) x = max(x, y) #define g_min(x, y) x = min(x, y) #define rsz(a, n) a.resize(n) #define ass(a, n) a.assign(n, 0) #define YES() cout << "YES\n" #define Yes cout << "Yes...
cpp
1313
C2
C2. Skyscrapers (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version n≤500000n≤500000The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the constru...
[ "data structures", "dp", "greedy" ]
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = tuple<ll, ll>; using vi = vector<ll>; using vii = vector<ii>; using vvii = vector<vii>; int n; vi a; vvii t; void build() { t.push_back(vii(n)); for (int i=0; i < n; i++) t[0][i] = {a[i],i}; for (int i=1, k=2; k <= n...
cpp
1304
F2
F2. Animal Observation (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraint on kk.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The ...
[ "data structures", "dp", "greedy" ]
/// Author : Nguyễn Thái Sơn - Ti20 - THPT chuyên Lương Thế Vinh /// Training VOI 2023 #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/trie_policy.hpp> //#include <ext/rope> //#pragma GCC optimize("Ofast") //#pragma GCC optimization("unroll-loops, no-stack-protector")...
cpp
1304
F2
F2. Animal Observation (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraint on kk.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The ...
[ "data structures", "dp", "greedy" ]
// OMAR AL-MIDANI // /* ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣤⣀⡀⠄⠄⠄⠄⠄⣰⣷⡀⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⣀⣀⣀⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠄⠄⢠⣿⣿⣷⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠤⠒⠛⠛⠛⠛⠻⠷⣦⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣿⣿⣿⠟⠁⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⢀⣤⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⡤⠐⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⢀⣶⣿⣿⠿⢛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿...
cpp
1299
A
A. Anu Has a Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9f(11,6)=(11|6)−6=15−6=9. It can be proved that for an...
[ "brute force", "greedy", "math" ]
#include<iostream> #include<cstring> #include<vector> #include<map> #include<queue> #include<unordered_map> #include<cmath> #include<cstdio> #include<algorithm> #include<set> #include<cstdlib> #include<stack> #include<ctime> #define forin(i,a,n) for(int i=a;i<=n;i++) #define forni(i,n,a) for(int i=n;i>=a;i--) #define f...
cpp
1316
C
C. Primitive Primestime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is Professor R's last class of his teaching career. Every time Professor R taught a class; he gave a special problem for the students to solve. You being his favourite student, put your heart in...
[ "constructive algorithms", "math", "ternary search" ]
//______________"In The Name Of GOD"______________ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair <ll, ll> pll; typedef pair <int, int> pii; const int lg = 20; const int mod = 1e9 + 7; const ll inf = 1e9 + 100; const int maxn = 1e6 ...
cpp
1290
A
A. Mind Controltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou and your n−1n−1 friends have found an array of integers a1,a2,…,ana1,a2,…,an. You have decided to share it in the following way: All nn of you stand in a line in a particular order. Each minute, the p...
[ "brute force", "data structures", "implementation" ]
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <limits> #include <t...
cpp
1303
B
B. National Projecttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour company was appointed to lay new asphalt on the highway of length nn. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip...
[ "math" ]
/*亲爱的上帝,我求你给我力量来赢得这场战斗。*/ #include <bits/stdc++.h> using namespace std ; using i64 = long long; #ifndef ONLINE_JUDGE #define debug(x) cerr << #x << "->"; god(x); cerr << "\n"; #else #define debug(x) #endif void god(i64 UWU) { cerr << UWU;} void god(int UWU) { cerr << UWU;} void god(string UWU) { cerr << ...
cpp
1324
C
C. Frog Jumpstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a frog staying to the left of the string s=s1s2…sns=s1s2…sn consisting of nn characters (to be more precise, the frog initially stays at the cell 00). Each character of ss is either 'L' or 'R'. It...
[ "binary search", "data structures", "dfs and similar", "greedy", "implementation" ]
#include <iostream> #include <map> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <climits> using namespace std; #define ll long long #define code std::ios::sync_with_stdio(false);::cin.tie(nullptr); bool isPrime(ll n){ if(n < 2) return false; for (ll i = 2; i * i <= ...
cpp
1303
D
D. Fill The Bagtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a bag of size nn. Also you have mm boxes. The size of ii-th box is aiai, where each aiai is an integer non-negative power of two.You can divide boxes into two parts of equal size. Your goal is t...
[ "bitmasks", "greedy" ]
#include<bits/stdc++.h> using namespace std; #define vt vector #define pb push_back #define ll long long #define sz(x) (int)(x).size #define all(x) (x).begin(),(x).end() #define allb(x) (x).rbegin(),(x).rend() #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstrea...
cpp
1311
D
D. Three Integerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three integers a≤b≤ca≤b≤c.In one move, you can add +1+1 or −1−1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero)...
[ "brute force", "math" ]
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using o_multiset = tree<T, null_...
cpp
1286
C2
C2. Madhouse (Hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is different with easy version only by constraints on total answers lengthIt is an interactive problemVenya joined a tour to the madhouse; in which orderlies play with patients th...
[ "brute force", "constructive algorithms", "hashing", "interactive", "math" ]
#ifdef MY_LOCAL #include "D://competitive_programming/debug/debug.h" #define debug(x) cerr << "[" << #x<< "]:"<<x<<"\n" #else #define debug(x) #endif #define REP(i, n) for(int i = 0; i < n; i ++) #define REPL(i,m, n) for(int i = m; i < n; i ++) #define SORT(arr) sort(arr.begin(), arr.end()) #define LSOne(S) (...
cpp
1285
A
A. Mezo Playing Zomatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Mezo is playing a game. Zoma, a character in that game, is initially at position x=0x=0. Mezo starts sending nn commands to Zoma. There are two possible commands: 'L' (Left) sets the position...
[ "math" ]
#include<bits/stdc++.h> using namespace std; int main() { int length; string S; cin >> length >> S; int lefts = 0, rights = 0; for(int i = 0; i < length; i++) { switch(S[i]) { case 'L' : lefts++; break; case 'R' : rights++; break; ...
cpp
1311
C
C. Perform the Combotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons ...
[ "brute force" ]
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--){ int x,k; string s;cin>>x>>k>>s; int a[k]; for(int i=0;i<k;i++)cin>>a[i]; sort(a,a+k); map<char,int>mp; int j=k-1; for(int i=x-1;i>=0;i--){ while(a[j]>=i+1&&j>=0)j--; mp[s[i]]+=k-j; } for(char p='a'...
cpp
1285
B
B. Just Eat It!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Yasser and Adel are at the shop buying cupcakes. There are nn cupcake types, arranged from 11 to nn on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type ii i...
[ "dp", "greedy", "implementation" ]
#include<bits/stdc++.h> using namespace std; int main() { long long t;cin>>t; while(t--) { map<long long,long long> mp; long long n;cin>>n; vector<long long> v(n); long long s1=0,sum=0; long long maxi= LONG_LONG_MIN; long long neg=0; for(l...
cpp
1305
D
D. Kuroni and the Celebrationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem; Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortun...
[ "constructive algorithms", "dfs and similar", "interactive", "trees" ]
#include<bits/stdc++.h> using namespace std; int n; vector<int> v[1005]; int vis[1005]={0}; int dfs(int a) { vis[a]=1; for(auto i:v[a]) { if(!vis[i]) return dfs(i); } return a; } int main() { //int n; //vector<int> v[n]; cin>>n; for(int i=1;i<n;i++) { int u,k; cin>>u>>k; v[u].push_back(k); v[k].push_back(u); } int x=0...
cpp
1324
F
F. Maximum White Subtreetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree consisting of nn vertices. A tree is a connected undirected graph with n−1n−1 edges. Each vertex vv of this tree has a color assigned to it (av=1av=1 if the vertex vv is whi...
[ "dfs and similar", "dp", "graphs", "trees" ]
#include <bits/stdc++.h> #define ll long long #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; const int N = 2e5 + 10; const int inf = 0x3f3f3f3f; int head[N], nex[N << 1], to[N << 1], cnt=1; int dp[N], a[N], n; //cnt:start from 1,no need to memset (-1) void add(int x, int y) { ...
cpp
1299
C
C. Water Balancetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn water tanks in a row, ii-th of them contains aiai liters of water. The tanks are numbered from 11 to nn from left to right.You can perform the following operation: choose some subsegment [l...
[ "data structures", "geometry", "greedy" ]
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mod 1000000007 #define ll long long int #define endl '\n' #define mem(a,x) memset(a,x,sizeof(a)) #define EPS 1e-12 #define double long double using namespace std; using namespace __gnu_pbds; typedef...
cpp
1284
A
A. New Year and Namingtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHappy new year! The year 2020 is also known as Year Gyeongja (경자년; gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Ko...
[ "implementation", "strings" ]
#include <iostream> using namespace std; int main(){ int n,m; cin >> n >> m; string a[n],b[m]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; int q,t; cin >> q; while(q--){ cin >> t; t--; cout << a[t % n] + b[t % m] << endl; } }
cpp
1325
A
A. EhAb AnD gCdtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive integer xx. Find any such 22 positive integers aa and bb such that GCD(a,b)+LCM(a,b)=xGCD(a,b)+LCM(a,b)=x.As a reminder, GCD(a,b)GCD(a,b) is the greatest integer that divides both...
[ "constructive algorithms", "greedy", "number theory" ]
/* Bismillahir Rahmaneer Raheem Rabbi Zidni Ilmah Assalamu wala Manittaba Al huda */ #include<bits/stdc++.h> #define ll long long using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("C:/Users/Mehrab Evan/Desktop/input.txt", "r", stdin); freopen("C:/Users/Mehrab Evan/Desktop/o...
cpp
13
A
A. Numberstime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.Now he wonders what is an average value of ...
[ "implementation", "math" ]
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 /*bool isprime(int n){ for (int i=2;i*i<=n;i++){ if (n%i==0) return 0; } return 1; }*/ bool cmp(long long a, long long b){ return a>b; } int main() { long long n,x=0,y; cin >> n;...
cpp
1315
C
C. Restoring Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence b1,b2,…,bnb1,b2,…,bn. Find the lexicographically minimal permutation a1,a2,…,a2na1,a2,…,a2n such that bi=min(a2i−1,a2i)bi=min(a2i−1,a2i), or determine that it is impossib...
[ "greedy" ]
/* ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⠟⠛⠛⠛⠛⠛⣛⣻⣿⣿⣿⣿⣿⣟⣛⣛⣛⠛⠒⠲⠶⠦⣤⣤⣤⣀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⠏⠁⠀⠀⢀⣤⠶⣛⣩⣥⠤⠤⠤⠤⢤⣤⣤⣭⣭⣉⣉⣛⣛⣻⣭⣥⠬⡍⠛⢶⣄ ⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⠃⠀⠀⣠⡶⢋⡵⢛⡩⠵⠒⠒⠒⠒⠢⡀⠀⠀⠀⠀⠀⢀⣠⠤⠤⠤⢤⣄⠀⠀⠀⠉⠻⣆ ⠀⠀⠀⠀⠀⠀⠀⢀⣿⠃⠀⠀⠘⢁⡴⢋...
cpp
1301
C
C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu...
[ "binary search", "combinatorics", "greedy", "math", "strings" ]
#include <bits/stdc++.h> #define up(i, j, n, k) for (int i = j; i <= n; i += k) #define dw(i, j, n, k) for (int i = j; i >= n; i -= k) #define int long long using namespace std; typedef pair<int, int> PII; const int mod = 998244353; const int mn = 2e6 + 1000; const int INF = 0x3f3f3f3f; const int LINF = 9223...
cpp