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
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" ]
//MD SHARIQUE HUSSAIN 2112015 #include <iostream> #include <math.h> #include <vector> #include <map> #include <set> #include<iomanip> #include<algorithm> #include<utility> #include<set> #include<unordered_set> #include<list> #include<iterator> #include<deque> #include<queue> #include<stack> #include<bitset> #include<ra...
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<bits/stdc++.h> #define eps 1e-9 #define emailam ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' #define ll long long #define ull unsigned long long #define MAX 200010 #define pb push_back #define all(a) a.begin(),a.end() #define pf push_front #define ...
cpp
1305
A
A. Kuroni and the Giftstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni has nn daughters. As gifts for them, he bought nn necklaces and nn bracelets: the ii-th necklace has a brightness aiai, where all the aiai are pairwise distinct (i.e. all aiai are differen...
[ "brute force", "constructive algorithms", "greedy", "sortings" ]
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; int32_t main(){ int t; cin>>t; while(t--){ int n,m; cin>>n; int a[n]; for(int i=0;i<n;i++)cin>>a[i]; sort(a,...
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 <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; typedef tree<int, nul...
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: 99917153 #include <deque> #include <cstdio> #include <cstring> #include <algorithm> using std :: swap;using std :: min; namespace nagisa{ const int maxn = 55,maxm = 2505,inf = 0x3f3f3f3f; int n,m,q,ans[maxn],F; struct MCMF{ int head[maxn],tot;MCMF(){tot = 1;} struct Edge{int next,to,cap,v...
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 <cstdio> #include <vector> #include <algorithm> const int INF=1e9+7; int N; int as[200005]; std::vector<int> edges[200005]; int dist[2][200005]; int q[200005]; void bfs(int* dist,int s){ std::fill(dist,dist+N,INF); int qh=0,qt=0; q[qh++]=s; dist[s]=0; while(qt<qh){ int x=...
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" ]
#include "bits/stdc++.h" using namespace std; #define ll long long string query(int l, int r) { cout << "? " << l << " " << r << "\n"; cout.flush(); int n = r - l + 1; vector<vector<int>> a(n + 1, vector<int>(26)); for (int i = 0; i < (n * (n + 1)) / 2; i++) { string curr; cin >> curr; for (cha...
cpp
1307
E
E. Cow and Treatstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a successful year of milk production; Farmer John is rewarding his cows with their favorite treat: tasty grass!On the field, there is a row of nn units of grass, each with a sweetness sisi. Farmer...
[ "binary search", "combinatorics", "dp", "greedy", "implementation", "math" ]
#include<bits/stdc++.h> #define Mx 5000 #define LL long long #define mod 1000000007 using namespace std; int n,m; bool ok; int s[5002],l[5002],r[5002]; LL fac[5002],inv[5002]; vector<int> pos[5002]; vector<int> vec[2][5002]; struct aaa { int mx; LL cnt; }tmp={0,1},ans; inline void upd(aaa &a,aaa b) {...
cpp
1307
E
E. Cow and Treatstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a successful year of milk production; Farmer John is rewarding his cows with their favorite treat: tasty grass!On the field, there is a row of nn units of grass, each with a sweetness sisi. Farmer...
[ "binary search", "combinatorics", "dp", "greedy", "implementation", "math" ]
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <...
cpp
1284
D
D. New Year and Conferencetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFilled with optimism; Hyunuk will host a conference about how great this new year will be!The conference will have nn lectures. Hyunuk has two candidate venues aa and bb. For each of the nn l...
[ "binary search", "data structures", "hashing", "sortings" ]
#include <bits/stdc++.h> using namespace std; #define dg(x) cout<<#x<<"="<<x<<endl using ll = long long; const int N = 1e5+5; int n,sa[N],sb[N],ea[N],eb[N]; pair<pair<int,int>,int> t[N<<1]; bool chk(){ for (int i=0; i<(n<<1); i+=2){ t[i]={{sa[i/2],0},i/2}; t[i+1]={{ea[i/2],1},i/2}; } sort...
cpp
1296
B
B. Food Buyingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka wants to buy some food in the nearby shop. Initially; he has ss burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer numb...
[ "math" ]
#include<iostream> #include<vector> #include<set> #include<queue> #include<map> #include<algorithm> #include<numeric> #include<cmath> #include<cstring> #include<bitset> #include<iomanip> #include<random> #include<fstream> #include<complex> #include<time.h> #include<stack> using namespace std; #define endl "\n" #define ...
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" ]
// LUOGU_RID: 101723561 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<bitset> #include<random> #include<cmath> #include<ctime> #include<queue> #include<map> #include<set> #define int long long #define fi first #define se second #define max Max #define min Min #defi...
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; #define ll long long int main() { int t; cin>>t; while(t--) { ll x,y,a,b; cin>>x>>y>>a>>b; ll k,n; k=y-x; n=a+b; if((k<n)||(k%n!=0)) { cout<<"-1"<<endl; } el...
cpp
1311
A
A. Add Odd or Subtract Eventime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers aa and bb.In one move, you can change aa in the following way: Choose any positive odd integer xx (x>0x>0) and replace aa with a+xa+x; choose any positiv...
[ "greedy", "implementation", "math" ]
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int a,b,k=0; cin >> a >> b; if(a==b) cout << k << endl; else if(b>a){ k=b-a; if(k%2==0) cout << 2 << endl; else ...
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> #define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define xs(a) cout<<setiosflags(ios::fixed)<<setprecision(a); #define lbit(a) (__builtin_ffsll(a)) #define ubit(a) (64-__builtin_clzll(a)) #define FOR(i, a, b) for (ll (i) = (a); (i) <= (b); (i)++) #define ROF(i, a, b) for ...
cpp
1307
F
F. Cow and Vacationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie is planning a vacation! In Cow-lifornia; there are nn cities, with n−1n−1 bidirectional roads connecting them. It is guaranteed that one can reach any city from any other city. Bessie is consi...
[ "dfs and similar", "dsu", "trees" ]
#include <bits/stdc++.h> using namespace std; const int N=1e6+5; int dep[N],f[N][21],head[N],nxt[N],vet[N],edgenum,que[N],fa[N],K,r,n; void Add(int u,int v) { vet[++edgenum]=v; nxt[edgenum]=head[u]; head[u]=edgenum; } int find(int x) { if (x!=fa[x]) fa[x]=find(fa[x]); return fa[x]; } void bfs() { for (int i=1; ...
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" ]
#define _USE_MATH_DEFINES #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; const int n1=1000000007; #define miv map<int,vector<int>> #define inf 5e18 #define mlv map<ll,vector<ll>> #define mip map<int,pair<int,int>> #define mii map<int,int> #define mll map<ll,ll> #define umip uno...
cpp
1141
G
G. Privatization of Roads in Treelandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTreeland consists of nn cities and n−1n−1 roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are righ...
[ "binary search", "constructive algorithms", "dfs and similar", "graphs", "greedy", "trees" ]
#include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1e18 #define N 200005 ll n,m,k,ans=0,x,y,l,r,s,z; ll cnt=0,head[N]; struct edge{ ll x,y,col,id; }e[2*N]; ll d[N]; bool flag[N]; ll col[N]; struct point{ ll d,id; }a[N]; template<typename T>inline void read(T &n){ T w=1; 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" ]
#include <bits/stdc++.h> #include <algorithm> #include <iostream> #define fr(a, n) for(int i = a ; i < n ;++i) #define fr2(a, n, i) for(int i = a ; i < n ;++i) using namespace std; void solve() { int n; cin>>n; int arr[n]; int left[n]; int right[n]; map<int, int> mp; set<int>st;...
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; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t; cin>>t; while(t--){ int n; cin>>n; int arr[n]; for(int i=0;i<n;i++){ cin>>arr[i]; } if(n==1 && arr[0]%2){ cout<<...
cpp
1141
G
G. Privatization of Roads in Treelandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTreeland consists of nn cities and n−1n−1 roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are righ...
[ "binary search", "constructive algorithms", "dfs and similar", "graphs", "greedy", "trees" ]
// LUOGU_RID: 100224854 #include<bits/stdc++.h> using namespace std; #define ll long long #define inf INT_MAX #define N 200005 ll n,m,k,ans=0,x,y,l,r,s,z; ll cnt=0,head[N]; struct edge{ ll x,y,col,id; }e[2*N]; ll d[N]; bool flag[N]; ll col[N]; struct point{ ll d,id; }a[N]; template<typename T>inline v...
cpp
1313
E
E. Concatenation with intersectiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya had three strings aa, bb and ss, which consist of lowercase English letters. The lengths of strings aa and bb are equal to nn, the length of the string ss is equal to mm. Vasya d...
[ "data structures", "hashing", "strings", "two pointers" ]
#include<cstdio> #include<vector> #include<queue> #include<cstring> #include<iostream> #include<algorithm> #include<ctime> #include<random> #include<assert.h> #define pb emplace_back #define mp make_pair #define fi first #define se second #define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'...
cpp
1303
A
A. Erasing Zeroestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a cont...
[ "implementation", "strings" ]
#include<bits/stdc++.h> using namespace std; #define ll long long int main () { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); ll t; cin >> t; while( t-- ){ string s; cin >> s; ll cnt = 0, z = 0, cal = 0 , ans = 0; for(ll i = 0; i < s.size(); i++)if(s[i] == '1') {cal = i, z++; bre...
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> using namespace std; void solve() { int n; cin >> n; vector<pair<int, int>> intervals; vector<int> nums; for(int i = 0; i < n; i++) { int l, r; cin >> l >> r; nums.push_back(l); nums.push_back(r); intervals.push_back({l, r}); } sort(nums.begin(), nums.end()); nums....
cpp
1304
E
E. 1-Trees and Queriestime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGildong was hiking a mountain; walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree?Then...
[ "data structures", "dfs and similar", "shortest paths", "trees" ]
#include<bits/stdc++.h> #define rep(i,x,y) for(auto i=(x);i<=(y);++i) #define dep(i,x,y) for(auto i=(x);i>=(y);--i) using namespace std; typedef long long ll; const int N=1e5+10; const int mo=1e9+7; const int inf=1e9; int f[18][N],h[N];vector<int>p[N]; void dfs(int x){ for(auto&i:p[x])if(i!=f[0][x]){ f[0][i]=x;h[i]=h[...
cpp
1286
D
D. LCCtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn infinitely long Line Chillland Collider (LCC) was built in Chillland. There are nn pipes with coordinates xixi that are connected to LCC. When the experiment starts at time 0, ii-th proton flies from the ii-th...
[ "data structures", "math", "matrices", "probabilities" ]
#include<bits/stdc++.h> typedef long long ll; #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; const int P = 998244353; inline int plu(int x, int y) {return x + y >= P ? x + y...
cpp
1320
E
E. Treeland and Virusestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are nn cities in Treeland connected with n−1n−1 bidirectional roads in such that a way that any city is reachable from any other; in other words, the graph of cities and roads is a tree. Tr...
[ "data structures", "dfs and similar", "dp", "shortest paths", "trees" ]
#include <bits/stdc++.h> using namespace std; const int N = 2 * 100 * 1000 +10; int n, q; int dp[N][22], st[N], ft[N], t, h[N]; int k, m, vir[N], S[N], is_vir[N], added[N]; int ans[N]; long long ans_time[N]; vector<int>vertex; vector<int> adj[N]; set<pair<int,int>> vertex_st; set<pair<int,long long>> s...
cpp
1312
C
C. Adding Powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you are performing the following algorithm. There is an array v1,v2,…,vnv1,v2,…,vn filled with zeroes at start. The following operation is applied to the array several times — at ii-th step (00-...
[ "bitmasks", "greedy", "implementation", "math", "number theory", "ternary search" ]
#include <bits/stdc++.h> using namespace std; typedef long long int ll ; map<ll, ll> mp ; void check(ll n, ll k) { ll cnt=0 ; while(n) { mp[cnt]+=(n%k); n/=k ; cnt++ ; } } int main() { ll tc; cin >> tc ; while(tc--) { ll n, k, i ; cin >> n >> k ; bool bb = 1 ; for(int i=0; i...
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<bits/stdc++.h> #define endl '\n' #define int long long #define INF 0x3f3f3f3f using namespace std; const int N=500+3; int a[N],f[N][N],dp[N]; //区间DP //求出f[l,r]表示[l,r]区间向左合并的最小可能数。然后dp一遍枚举区间划分即可。 void solve() { int n; cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; map<int ,int >mp; for(int i=1; ...
cpp
1312
C
C. Adding Powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you are performing the following algorithm. There is an array v1,v2,…,vnv1,v2,…,vn filled with zeroes at start. The following operation is applied to the array several times — at ii-th step (00-...
[ "bitmasks", "greedy", "implementation", "math", "number theory", "ternary search" ]
#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fix(n,f) std::fixed<<std::setprecision(f)<<n #define ll long long #define all(v) v.begin(),v.end() #define nl "\n" #define M 1000000007 #define sum(a,b) ((a%M)+(b%M))%M #d...
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 <bits/stdc++.h> #define N 1005 #define pb push_back using namespace std; int n, a[N], b[N], pos[N]; int qry(vector<int> &v) { printf("? %u ", v.size()); for (auto x : v) printf("%d ", x); puts(""); fflush(stdout); int r = 0; scanf("%d", &r); return r; } int ask(int x) { vector<int> v; ...
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 <iostream> #include <vector> using namespace std; #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); typedef long long int64; struct Point{ double x, y; Point(){ } Point(double x, double y){ this->x = x; this->y = y; } }; Point sub(Point ...
cpp
1141
F1
F1. Same Sum Blocks (Easy)time limit per test2 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 ...
[ "greedy" ]
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define ld long double #define el "\n" #define matrix vector<vector<int>> #define pt complex<ld> #define ordered_set tr...
cpp
1316
A
A. Grade Allocationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputnn students are taking an exam. The highest possible score at this exam is mm. Let aiai be the score of the ii-th student. You have access to the school database which stores the results of all studen...
[ "implementation" ]
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = tuple<int, int>; using vi = vector<ll>; using vii = vector<ii>; using vvi = vector<vi>; using si = set<ll>; int main() { cin.tie(0), ios::sync_with_stdio(0); ll t, n, m; cin >> t; while (t--) { cin >> n >> m; ...
cpp
1294
B
B. Collecting Packagestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a robot in a warehouse and nn packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0,0)(0,0). The ii-th package is ...
[ "implementation", "sortings" ]
#include<bits/stdc++.h> using namespace std; int main() {int t; cin>>t; while(t--){ int n; cin>>n; pair<int ,int >a[n]; for(int i=0;i<n;i++){ cin>>a[i].first>>a[i].second; } sort(a,a+n); int x=0,y=0,f=0; string s=""; for(int i=0;i<n;i++){ int u=a[i].first,v=a[i].second; if(v<y){ f=1; cout<<"NO"; cou...
cpp
1287
B
B. Hypersettime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shape...
[ "brute force", "data structures", "implementation" ]
/* ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⣋⣯⡀⠀⣠⣿⠿⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⣤⡙⣿⡄⠀⣷⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⣠⡾⠙⠟⣩⡤⢾⠉⡿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⣼⣿⡷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⢀⣾⠿⠶⠶⠚⠉⡀⢰⣤⢳⠧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⢸⠃⠀⣿⡄⠀⠀⣷⡘⡿⠟⠃⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠠⠀⢸⣀⡀⠟⠉⣟⣛⣿⡴⠶⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀...
cpp
1307
A
A. Cow and Haybalestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of nn haybale piles on the farm. The ii-th pile contains aiai haybales. However, Farmer John has just left for vac...
[ "greedy", "implementation" ]
#include <bits/stdc++.h> using namespace std; int t,n,a[105],d; int main() { cin >> t; while (t--){ cin >> n >> d; for (int i=1; i<=n; ++i){ cin >> a[i]; } while (d--){ for (int i=2; i<=n; ++i){ if (a[i] > 0){ ++a[i-1]; ...
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" ]
#include <bits/stdc++.h> #define sys ios_base::sync_with_stdio(0);cin.tie(0); #define mod 1000000007 using namespace std; //#pragma comment(linker, "/STACK:268435456"); #define count_setbits(n) __builtin_popcount(n) #define fixed cout<<fixed<<setprecision(16) #define count_bits(n) ((ll)log2(n))+1 #define no_of...
cpp
1312
F
F. Attack on Red Kingdomtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe Red Kingdom is attacked by the White King and the Black King!The Kingdom is guarded by nn castles, the ii-th castle is defended by aiai soldiers. To conquer the Red Kingdom, the Kings have t...
[ "games", "two pointers" ]
#include<bits/stdc++.h> #define f(i,x,y) for(int i=x, i##end=y; i<=i##end; ++i) #define d(i,x,y) for(int i=y, i##end=x; i>=i##end; --i) #define uf(i,x,y) for(int i=x, i##end=y; i<i##end; ++i) #define ll long long #define pir pair<int, int> #define fir first #define sec second #define mp make_pair #define pb pu...
cpp
1305
F
F. Kuroni and the Punishmenttime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni is very angry at the other setters for using him as a theme! As a punishment; he forced them to solve the following problem:You have an array aa consisting of nn positive integers. ...
[ "math", "number theory", "probabilities" ]
#include<bits/stdc++.h> using namespace std; #define int long long const int N=2e5+5; int n; int a[N]; set<int>s; inline void Solve(int x) { for(int i=2;i*i<=x;i++) { if(x%i==0) { s.insert(i); while(x%i==0)x/=i; } } if(x>1)s.insert(x); } signed main() { mt19937 rnd(time(0)); ios::sync_with_stdio(0); cin.tie(0),cout.t...
cpp
1285
F
F. Classical?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array aa, consisting of nn integers, find:max1≤i<j≤nLCM(ai,aj),max1≤i<j≤nLCM(ai,aj),where LCM(x,y)LCM(x,y) is the smallest positive integer that is divisible by both xx and yy. For example, LCM(6,8...
[ "binary search", "combinatorics", "number theory" ]
// LUOGU_RID: 102598786 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100000 + 10; int n, lim, a[N], vis[N]; vector<int> vec, d[N]; int cnt[N], sta[N], top; int p[N], v[N], mu[N], pcnt = 0; void init(int n) { mu[1] = 1; for (int i = 2; i <= n; ++i) { ...
cpp
1301
A
A. Three Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three strings aa, bb and cc of the same length nn. The strings consist of lowercase English letters only. The ii-th letter of aa is aiai, the ii-th letter of bb is bibi, the ii-th letter of...
[ "implementation", "strings" ]
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ string s1,s2,s3; cin>>s1>>s2>>s3; int cnt=0; for(int i=0;i<s1.size();i++){ swap(s1[i],s3[i]); if(s1[i]==s2[i])cnt++; else{ swap(s1[i],s3[i]); swap(s2[i],s3[i]); if(s1[i]==s2[i])cnt++; ...
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> #include <ext/pb_ds/assoc_container.hpp> #define FORI(start, stop, step) for(int i = start; (step > 0) ? (i < stop) : (i >= stop); i += step) #define FORJ(start, stop, step) for(int j = start; (step > 0) ? (j < stop) : (j >= stop); j += step) #define FORK(start, stop, step) for(int k = star...
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" ]
/********************************* * Author -> Puspendra yadav * **********************************/ #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; #define idx(x) find_by_order(x) #define...
cpp
1320
B
B. Navigation Systemtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe map of Bertown can be represented as a set of nn intersections, numbered from 11 to nn and connected by mm one-way roads. It is possible to move along the roads from any intersection to any othe...
[ "dfs and similar", "graphs", "shortest paths" ]
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MOD 1000000007 using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //priority_queue <int, vecto...
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" ]
/* It is code Zhanabergen Abdurroshid :)))) */ #include<bits/stdc++.h> #define ll long long #define int ll #define m_p make_pair #define p_b push_back #define pii pair<int,int> #define piii pair<int,pii> #define vi vector<ll> #define vii vector<pii> #define viii vector<pair<int,pii> > #define si set<int> ...
cpp
1313
E
E. Concatenation with intersectiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya had three strings aa, bb and ss, which consist of lowercase English letters. The lengths of strings aa and bb are equal to nn, the length of the string ss is equal to mm. Vasya d...
[ "data structures", "hashing", "strings", "two pointers" ]
#include<bits/stdc++.h> using namespace std; long long n,m,nt[1000006],f[2][500005],sz[2][500005],ans; vector<long long> vec[500005]; char a[500005],b[500005],c[1000006]; inline void add(long long op,long long u,long long w){for(long long i=u;i<=n;i+=(i&(-i))) sz[op][i]+=w;} inline long long qry(long long op,long long ...
cpp
1313
A
A. Fast Food Restauranttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTired of boring office work; Denis decided to open a fast food restaurant.On the first day he made aa portions of dumplings, bb portions of cranberry juice and cc pancakes with condensed milk.The ...
[ "brute force", "greedy", "implementation" ]
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef float ff; typedef vector<long long int> vi; #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)x.size() #define pb(x) push_back(x) #define endl "\n" void solve(){ vector <int> a(3...
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 q; cin >> q; for (int i = 0; i < q; ++i) { int a[3], n; cin >> a[0] >> a[1] >> a[2] >> n; sort(a, a + 3); n -= 2 * a[2] - a[1] - a[0]; if (n < 0 || n % 3 != 0) { cout << "NO" << ...
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> using namespace std; #define ll long long //#define ld long double #define vv vector<ll> #define T ll ttt;cin>>ttt;while(ttt--) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define mod 1000000007 #define pb emplace_back #define eeq <<"\n"; #define PI 3.14159265359...
cpp
1296
A
A. Array with Odd Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array aa consisting of nn integers.In one move, you can choose two indices 1≤i,j≤n1≤i,j≤n such that i≠ji≠j and set ai:=ajai:=aj. You can perform such moves any number of times (poss...
[ "math" ]
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for(int i=0;i<n;i++){ int even = 0,odd = 0; // vector<int> arr; int m; cin >> m; for(int j=0;j<m;j++){ int num; cin >> num; // arr.push_back(num); if(num & 1) odd++; ...
cpp
1325
E
E. Ehab's REAL Number Theory Problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array aa of length nn that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this...
[ "brute force", "dfs and similar", "graphs", "number theory", "shortest paths" ]
#include <bits/stdc++.h> using namespace std; #define pb emplace_back const int MN=1e6+3; int N, at=170, dist[MN], ans = MN; bool pvis[1001], vis[MN]; set<int> start; vector<int> prime, vals, adj[MN]; queue<pair<int, pair<int, int> > > next1; // (distance, (node, parent)) void bfs(int j){ memset(vis, 0, sizeo...
cpp
1285
F
F. Classical?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array aa, consisting of nn integers, find:max1≤i<j≤nLCM(ai,aj),max1≤i<j≤nLCM(ai,aj),where LCM(x,y)LCM(x,y) is the smallest positive integer that is divisible by both xx and yy. For example, LCM(6,8...
[ "binary search", "combinatorics", "number theory" ]
// LUOGU_RID: 101638026 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+5; ll n,m,ans; ll mark[N],miu[N],v[N],cnt[N]; vector<ll> factors[N],primes; inline void Mobius(ll n) { miu[1]=1; for(ll i=2; i<=n; i++) { if(!v[i]) { primes.push_back(i); miu[i]=-1; ...
cpp
1293
A
A. ConneR and the A.R.C. Markland-Ntime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSakuzyo - ImprintingA.R.C. Markland-N is a tall building with nn floors numbered from 11 to nn. Between each two adjacent floors in the building, there is a staircase connecting them.I...
[ "binary search", "brute force", "implementation" ]
#include <bits/stdc++.h> #define ll long long #define lpi(x,n) for(int i=x;i<n;++i) #define lpj(x,n) for(int j=x;j<n;++j) #define S second #define F first #define all(x) x.begin(),x.end() #define sorterase(v) {sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());} #define pb push_back #define pf ...
cpp
1294
E
E. Obtain a Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular matrix of size n×mn×m consisting of integers from 11 to 2⋅1052⋅105.In one move, you can: choose any element of the matrix and change its value to any integer between ...
[ "greedy", "implementation", "math" ]
#include<iostream> #include <bits/stdc++.h> using namespace std; template<class container> void print(container v) { for (auto& it : v) cout << it << ' ' ;cout <<endl;} using ll = long long; using ull = unsigned long long; using ld = long double; #define nd "\n" #define all(x) (x).begin(), (x).end() #define po...
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" ]
#include <iostream> #include <utility> #include <vector> #include <cmath> #include <algorithm> #include <unordered_set> #include <set> #include <queue> #include <cmath> #include <numeric> #include <sstream> #include <string> #include <map> #include <unordered_map> #include <deque> #include <iomanip> #in...
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> #define nl "\n" #define fi first #define se second #define pi 3.14159 #define ll long long #define odd(a) (a&1) #define even(a) !(a&1) #define Mod 1'000'000'007 #define INF 2'000'000'000 #define sz(x) int(x.size()) #define charToInt(s) (s - '0') #define ull unsigned long long #def...
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; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, p; cin >> n >> m >> p; vector<int> a(n), b(m); for (int &i : a) cin >> i; for (int &i : b) cin >> i; int i1 = n - 1; while (a[i1] % p == 0) i1--; int i...
cpp
1295
F
F. Good Contesttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn online contest will soon be held on ForceCoders; a large competitive programming platform. The authors have prepared nn problems; and since the platform is very popular, 998244351998244351 coder from ...
[ "combinatorics", "dp", "probabilities" ]
#include<bits/stdc++.h> #define re register using namespace std; inline int read(){ re int t=0;re char v=getchar(); while(v<'0')v=getchar(); while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar(); return t; } const int M=998244353; inline void add(re int&x,re int y){(x+=y)>=M?x-=M:x;} inline int Mod(re int x){ret...
cpp
1305
E
E. Kuroni and the Score Distributiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuroni is the coordinator of the next Mathforces round written by the "Proof by AC" team. All the preparation has been done; and he is discussing with the team about the score distrib...
[ "constructive algorithms", "greedy", "implementation", "math" ]
// #pragma GCC optimize("O3") // #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "complex" using namespace std; using namespace __gnu_pbds; template <class T> using o_set = tree<T, null_type, less<T>, rb_tree_ta...
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> using namespace std; #define ll long long const int MAX_N=100; string s[MAX_N]; void solve() { ll int n,m,i; cin>>n>>m; set<string> d; for(i=0;i<n;i++) { cin>>s[i]; d.insert(s[i]); } vector<string> left,right; string mid; for(...
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; 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, p = 1; vector<ll> pow2; map<ll, ll> rev_pow2;...
cpp
1313
B
B. Different Rulestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikolay has only recently started in competitive programming; but already qualified to the finals of one prestigious olympiad. There going to be nn participants, one of whom is Nikolay. Like any good o...
[ "constructive algorithms", "greedy", "implementation", "math" ]
#include <bits/stdc++.h> using namespace std; int main() { int t, n, x, y; cin >> t; while (t--) { cin >> n >> x >> y; int score = x+y; int worst, best; if (score > n+1) worst = n; else worst = score-1; if (score <= n) best = 1; else best = min(n, score-n+1); cout ...
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> using namespace std; #define ll long long #define fi first #define se second int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<pair<int, int>>> adj(n); for(int i = 0; i < n - 1; i++ ){ int x, y; cin...
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 #define ld long double #define vv vector<ll> #define T ll ttt;cin>>ttt;while(ttt--) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define mod 1000000007 #define pb emplace_back #define eeq <<"\n"; #define PI 3.14159265359 #...
cpp
13
D
D. Trianglestime limit per test2 secondsmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do no...
[ "dp", "geometry" ]
#include<bits/stdc++.h> using namespace std; #define int long long int a[501],b[501],c[501],d[501],f[501][501]; main() { int n,m; cin>>n>>m; for(int x=1;x<=n;x++) cin>>a[x]>>b[x]; for(int x=1;x<=m;x++) cin>>c[x]>>d[x]; for(int x=1;x<=n;x++) for(int y=1;y<=n;y++) if(a[x]<a[y]) { int u=b[y]-b[x],v=a[x]-a[y],w=-a[x]*u-b[...
cpp
1312
D
D. Count the Arraystime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYour task is to calculate the number of arrays such that: each array contains nn elements; each element is an integer from 11 to mm; for each array, there is exactly one pair of equal elements; f...
[ "combinatorics", "math" ]
#include <iostream> #include <iomanip> #include <vector> using namespace std; const long long mod = 998244353; int n, m; vector<long long> fac; long long fast_power(long long x, long long y) { long long res = 1; while(y > 0) { if(y & 1) res = (res * x) % mod; x = (x * x) % mod; ...
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<iostream> #include<vector> using namespace std; int n; vector<int>a; int solve(vector<int>p, int k) { if (p.size() == 0 || k < 0)return 0; vector<int>p1, p0; for (int i : p) { if (i & (1 << k))p1.push_back(i); else p0.push_back(i); } if (p1.size() == 0)return solve(p0, k - 1); if (p0.size...
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 <iostream> #include <cstdint> #include <cmath> #include <bits/stdc++.h> using namespace std; #define ll long long void printFraction(int up, int down) { for(int i = down <= up? down : up; i > 0; i--) { if(up % i == 0 && down % i == 0) { cout << up/i << "/" << down/i; retur...
cpp
1303
C
C. Perfect Keyboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row; where all 2626 lowercase Latin letters will be arrange...
[ "dfs and similar", "greedy", "implementation" ]
/* iamujj15 */ #pragma GCC optimize("O3,unroll-loops") #include "bits/stdc++.h" using namespace std; using namespace std::chrono; #define fstio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define INF 5e18 #define nline "\n" #define pb e...
cpp
1325
F
F. Ehab's Last Theoremtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's the year 5555. You have a graph; and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either.Given a connected graph w...
[ "constructive algorithms", "dfs and similar", "graphs", "greedy" ]
#include<iostream> #include <bits/stdc++.h> using namespace std; template<class container> void print(container v) { for (auto& it : v) cout << it << ' ' ;cout <<endl;} using ll = long long; using ull = unsigned long long; using ld = long double; #define nd "\n" #define all(x) (x).begin(), (x).end() #define po...
cpp
1292
A
A. NEKO's Maze Gametime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or aliveNEKO#ΦωΦ has just got a new maze game on her PC!The game's main puzzle is a maze; in the forms of a 2×n2×n rectangle grid. NEKO...
[ "data structures", "dsu", "implementation" ]
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define endl '\n' int n, q; vector<vector<int>> lava; void Input() { cin >> n >> q; lava.resize(2, vector<int>(n, 0)); } void Solve() { int blockedPair = 0; while (q--) { int x, y; cin >> x >> y; x--; y--; i...
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 <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <ranges> #include <set> #include <string> #include <vector> using namespace std; #define all(x) (x).begin(), (x).end() #defin...
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" ]
#include <iostream> #include <string> const int SIZE = 1e4; int main() { int t, x; std::cin >> t; std::string arr[SIZE]; for (int i = 0; i < t; i++) { std::cin >> x; arr[i] = "1 " + std::to_string(x - 1); } for (int i = 0; i < t; i++) std::co...
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" ]
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d",&t); while (t--) { int n; scanf("%d",&n); set<int> s; while (n--) { int a; scanf("%d",&a); s.insert(a); } printf("%d\n",s.size()); ...
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; using ll = long long; using ari2 = array<int, 2>; using arl2 = array<ll, 2>; using arl3 = array<ll, 3>; constexpr ll MOD = 998244353; void solve(); void precomp(); signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); precomp(); int T = 1; c...
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 <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> #include <map> using namespace std; #define eb emplace_back #define vv vector #define fi first #define se second using pii = pair<int, int>; using ll = long long; const int N = 4005; int n, m; int l[N]...
cpp
1323
B
B. Count Subrectanglestime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array aa of length nn and array bb of length mm both consisting of only integers 00 and 11. Consider a matrix cc of size n×mn×m formed by following rule: ci,j=ai⋅bjci,j=ai⋅bj (i.e....
[ "binary search", "greedy", "implementation" ]
#include<bits/stdc++.h> using namespace std; #define ll long long #define c(ans) cout << ans << endl #define cs(ans) cout << ans << " " #define fori(i,j,k) for(ll i = j; i < k; i++) #define ifor(i,j,k) for(ll i = j; i >= k; i--) #define inarr(j,n,a) for(ll i = j; i < n; i++) cin >> a[i]; #define sortall(v) so...
cpp
1324
B
B. Yet Another Palindrome Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array aa consisting of nn integers.Your task is to determine if aa has some subsequence of length at least 33 that is a palindrome.Recall that an array bb is called a s...
[ "brute force", "strings" ]
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //--------------------------------------------------------------------------------- #define ll long long #define fixed(n) cout << fixed << setprecision(n) #define sz(x) int(x.size()) #define TC int t; cin >> t; ...
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; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T, n; ll a, b, c; cin>>T; while(T--) { cin>>a>>b>>c>>n; n = n+a+b+c; if(n%3!=0) { cout<<"NO"<<"\n"; } else { n /= 3; if(n<a||n<b||n<...
cpp
1292
E
E. Rin and The Unknown Flowertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMisoilePunch♪ - 彩This is an interactive problem!On a normal day at the hidden office in A.R.C. Markland-N; Rin received an artifact, given to her by the exploration captain Sagar.After much...
[ "constructive algorithms", "greedy", "interactive", "math" ]
# include <bits/stdc++.h> using namespace std; int T; int n,m,f[60]; inline char get_(int x) { return x==1 ? 'C' : x==2 ? 'H' : 'O';} int main() { scanf("%d",&T); while (T--) { memset(f,0,sizeof(f)); scanf("%d",&n); printf("? CC\n"), fflush(stdout); scanf("%d",&m); for (int x,i=1;i<=m;i++)...
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 <iostream> #include <fstream> #include <stack> #include <set> #include <map> #include <stack> #include <vector> #include <queue> #include <string> #include <algorithm> #include <numeric> #include <cmath> #include <array> #include <bitset> #include <queue> #include <cstring> #include <iomanip> ...
cpp
1307
B
B. Cow and Friendtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically; he wants to get from (0,0)(0,0) to (x,0)(x,0) by...
[ "geometry", "greedy", "math" ]
/* Ψ In Search Of An Equilibrium Ψ */ #include<bits/stdc++.h> using namespace std; #define endl "\n" #define lp(i, a, b) for (int i = a; i < b; i++) #define lpp(i, a, b) for (int i = a; i <=b; i++) #define print(arrrr) lp(i,0,n) cout << arrrr[i] << " " #define scan(arrrr) lp(i,0,n) cin >> arrrr[i] #define pi...
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" ]
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cmath> #include<queue> #include<deque> #include<stack> #include<map> #include<set> using namespace std; int main() { int n,m; cin>>n>>m; vector<long long>dp(n+1,0); dp[n]=1; for(int i=1;i<=2*m+1;++i){ ...
cpp
1316
E
E. Team Buildingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice; the president of club FCB, wants to build a team for the new volleyball tournament. The team should consist of pp players playing in pp different positions. She also recognizes the importance of ...
[ "bitmasks", "dp", "greedy", "sortings" ]
#include <iostream> #include<bits/stdc++.h> #include<deque> #include<algorithm> #include<math.h> #include<sstream> #include<stdio.h> #include<bitset> #include<string> #include<vector> #include<unordered_map> #include<queue> #include<set> #include<fstream> #include<map> #define int long long int #define ld long double #...
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 <algorithm> #include <iostream> #include <numeric> #include <cmath> #include <conio.h> #include <iomanip> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define ld long do...
cpp
1296
B
B. Food Buyingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka wants to buy some food in the nearby shop. Initially; he has ss burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer numb...
[ "math" ]
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int s; cin >> s; int sol = 0; int pw = 1000 * 1000 * 1000; while (s > 0) { while (s < pw) pw /= 10; sol += pw; s -= pw - pw / 10; } cout << sol << "\n"; } int main() { ios::sync...
cpp
1307
A
A. Cow and Haybalestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of nn haybale piles on the farm. The ii-th pile contains aiai haybales. However, Farmer John has just left for vac...
[ "greedy", "implementation" ]
// LUOGU_RID: 102570640 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; const LL mod = 1e9 + 7; const int N = 100005; int a[105]; int main() { int _; cin >> _; while (_--) { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { ...
cpp
1295
F
F. Good Contesttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn online contest will soon be held on ForceCoders; a large competitive programming platform. The authors have prepared nn problems; and since the platform is very popular, 998244351998244351 coder from ...
[ "combinatorics", "dp", "probabilities" ]
#include<bits/stdc++.h> using namespace std; const int P=998244353,N=1e3; using ll=long long; ll inv[N]; ll POW(ll x,int k=P-2,ll rs=1) {while(k){if(k&1)rs=rs*x%P;x=x*x%P;k>>=1;}return rs;} void init() { for(int i=2;i<N;++i)inv[i]=POW(i); inv[0]=inv[1]=1; } int l[N],r[N],mp[N]; ll dp[N][N],C[N]; i...
cpp
1301
B
B. Motarack's Birthdaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array aa of nn non-negative integers.Dark created that array 10001000 years ago, so so...
[ "binary search", "greedy", "ternary search" ]
#include<bits/stdc++.h> using namespace std; typedef long long ll; int a[100005]; vector<int>sb; int main() {int t,n,m,k,h=-1; cin>>t; while(t--) {sb.clear();k=0; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) if(a[i]!=-1&&(a[i-1]==-1||a[i+1]==-1)) sb.push_back(a[i]); sort(sb.begin(),sb.end()); if(sb.e...
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<iostream> #include<bits/stdc++.h> using namespace std; long long min(long long a,long long b){ if(a<b) return a; return b; } long long max(long long a,long long b){ if(a>b) return a; return b; } bool isPrime(int x){ int root = sqrt(x+1); bool b = true; for(int i = 2;i<=root;i+...
cpp
1307
B
B. Cow and Friendtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically; he wants to get from (0,0)(0,0) to (x,0)(x,0) by...
[ "geometry", "greedy", "math" ]
//Created by yrm_1406 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; for (int i = 0; i < t; i++) { int n,x; cin>>n>>x; vector<int>a(n); bool ans = true; for (int i = 0; i < n; i++) { cin>>a[i]; if(x == a[i]) { ans = false; } } if(!ans) { co...
cpp
1313
E
E. Concatenation with intersectiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya had three strings aa, bb and ss, which consist of lowercase English letters. The lengths of strings aa and bb are equal to nn, the length of the string ss is equal to mm. Vasya d...
[ "data structures", "hashing", "strings", "two pointers" ]
// LUOGU_RID: 90275007 #include<cstdio> #include<cstdlib> #include<utility> #include<vector> #include<random> #define mod 998244353 std::mt19937 seed(*new int); std::pair<long long,int> operator +(std::pair<long long,int> x,std::pair<long long,int> y) {return std::make_pair(x.first+y.first,x.second+y.second);} ...
cpp
1301
E
E. Nanosofttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWarawreh created a great company called Nanosoft. The only thing that Warawreh still has to do is to place a large picture containing its logo on top of the company's building.The logo of Nanosoft can be des...
[ "binary search", "data structures", "dp", "implementation" ]
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < n; i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb push_back using namespace std; type...
cpp
1310
E
E. Strange Functiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's define the function ff of multiset aa as the multiset of number of occurences of every number, that is present in aa.E.g., f({5,5,1,2,5,2,3,3,9,5})={1,1,2,2,4}f({5,5,1,2,5,2,3,3,9,5})={1,1,2,2,...
[ "dp" ]
#include<bits/stdc++.h> #define LL long long #define mod 998244353 using namespace std; int n,k,t=0,t1,t2; LL ans=0; int p[72],p1[2022],p2[2022],f[2022]; int dp[2022][2022]; template<class T>void read(T &x) { x=0;int f=0;char ch=getchar(); while(ch<'0' || ch>'9')f|=(ch=='-'),ch=getchar(); while(ch>='0' &...
cpp
1324
E
E. Sleeping Scheduletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova had a pretty weird sleeping schedule. There are hh hours in a day. Vova will sleep exactly nn times. The ii-th time he will sleep exactly after aiai hours from the time he woke up. You can assu...
[ "dp", "implementation" ]
//Author : MD GHOUSE MOHIUDDIN #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<class T> using ordered_set = tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>; #define ...
cpp
1320
E
E. Treeland and Virusestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are nn cities in Treeland connected with n−1n−1 bidirectional roads in such that a way that any city is reachable from any other; in other words, the graph of cities and roads is a tree. Tr...
[ "data structures", "dfs and similar", "dp", "shortest paths", "trees" ]
#include<bits/stdc++.h> using namespace std; namespace QSY{ // by OneZzz6174 const int SIZ = 1000000; namespace IO{ // by OneZzz6174 #ifdef ONLINE_JUDGE static char buf[SIZ],*A=buf,*B=buf; #define getchar() A==B&&(B=(A=buf)+fread(buf,1,SIZ,stdin),A==B)?EOF:*A++ #endif static char obuf[SIZ],*C=obuf; #define ...
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" ]
#pragma GCC optimize(2) #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #define fi first #define sc second #define mkp make_pair #define pii pair<int,int> #include <iostream> using namespace std; typedef long long ll; const int N=25,M=(1<<20)+5,K=40000,oo=1e9; inline int read() { int x=0...
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<iostream> #define q 1<<18 long long h;int c[q],f[q],i,j,s,t;int p(int a){return f[a]==a?a:f[a]=p(f[a]);}main(){for(*c=1,scanf("%d",&t);t--&&scanf("%d",&s);c[s]++)h-=s;for(i=q;--i;f[i]=i);for(i=q;--i;)for(j=i;j;--j&=i)if(c[j]&&c[i^j]&&(s=p(j))^(t=p(i^j)))f[s]=t,h+=i*(c[s]+c[t]-1LL),c[t]=1;std::cout<<h;}
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" ]
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int>pi; typedef pair<ll, ll>pl; typedef vector<pi>vpi; typedef vector<pl>vpl; typedef vector<vi> vvi; typedef vector<vl...
cpp