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
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> #define x first #define y second #define TLE ios::sync_with_stdio(0),cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<double, double> PDD; typedef unsigned long long ULL; const int N = 3e5 + 10, M = 2 * N, mod = 1e9 + 7; const double eps =...
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> using namespace std; void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #ifdef LOCAL #define debug(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define debug(...) "zzz"...
cpp
1300
A
A. Non-zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGuy-Manuel and Thomas have an array aa of nn integers [a1,a2,…,ana1,a2,…,an]. In one step they can add 11 to any element of the array. Formally, in one step they can choose any integer index ii (1≤i≤n1≤i≤n) a...
[ "implementation", "math" ]
#include <bits/stdc++.h> #define f first #define S second #define pb push_back #define msk(x , y) (x >> y) & 1 #define all(x) x.begin() , x.end() using namespace std; typedef long long int ll; const int N = 5e5 + 7 ; const ll mod = 998244353; const int dx[] = {-1, -1 , -1 , 0, 0 , -1 , 1 , 1}; const i...
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; const int MN=8e4; int N, at=170, dist[MN], ans = MN; bool pvis[1001], vis[MN]; set<int> start; vector<int> prime, vals, adj[MN]; unordered_map<int, int> ind; // (value, index it maps to) queue<pair<int, pair<int, int> > > next1; // (distance, (node, parent)) void ...
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 <cstdio> #include <vector> #include <cassert> #include <queue> #include <algorithm> const int INF=1e9+7; std::vector<int> edges[400005]; int anc[19][400005]; int depth[400005]; void dfs(int node){ for(int child:edges[node]){ edges[child].erase(std::find(edges[child].begin(),edges[child...
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 <iostream> #include <algorithm> #define int long long using namespace std; struct point{ int x,y; }p[501],p2[501]; inline point operator-(point a, point b){ return {a.x-b.x,a.y-b.y}; } inline int operator*(point a, point b){ return a.x*b.y-a.y*b.x; } int f(point a, point b, point c){ ...
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" ]
#include <bits/stdc++.h> #define itn long long #define int long long #define double long double //#define endl '\n' #define p_b push_back #define fi first #define se second #define pii std::pair<int, int> #define oo LLONG_MAX #define big INT_MAX #define elif else if using namespace std; int input()...
cpp
1290
D
D. Coffee Varieties (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. You can find the easy version in the Div. 2 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.Th...
[ "constructive algorithms", "graphs", "interactive" ]
/* Wei Wai Wei Wai Zumigat nan damu dimi kwayt rayt */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; /*typedef __uint128_t L; struct FastMod { ull b, m; FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {} ull reduce(ull a) { ull ...
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" ]
//author: TomoriNao #include<bits/stdc++.h> #define all(x) x.begin(), x.end() #define ll long long //#include<time.h> using namespace std; int main(){ // freopen("1.inp","r",stdin); //freopen("1.ans","w",stdout); ios::sync_with_stdio(0); cin.tie(0); int t; cin >>t; while (t--) { ll a; st...
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> using namespace std; int main() { int t; cin>>t; int a[t+2]; for(int i=0; i<t; i++) { int n,m; cin>>n>>m; if(n%m == 0)a[i]=1; else a[i] =0; } for(int i=0; i<t; i++) { if(a[i] == 1)cout<<"YES\n"; else ...
cpp
1284
G
G. Seollaltime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputIt is only a few days until Seollal (Korean Lunar New Year); and Jaehyun has invited his family to his garden. There are kids among the guests. To make the gathering more fun for the kids, Jaehyun is going t...
[ "graphs" ]
#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; } int A[805],B[805],pre[805],S,T,n,m,fa[805],dis[805],Q[805],hd,tl,d[805],col[805],k; char vis[805],usd[805]...
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; struct pt { int x, y; }; long long sq(int x) { return 1LL*x*x; } long long norm(pt& a) { return sq(a.x)+sq(a.y); } int quadrant(pt a) { if (a.y >= 0 && a.x > 0) return 0; else if (a.x <= 0 && a.y > 0) return 1; else if (a.y <= 0 && a.x < 0) return 2; else ...
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" ]
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; typedef unsigned long long ull; typedef pair <int, int> pii; typedef long long ll; template <typename _T> inli...
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" ]
#include <bits/stdc++.h> #define timetaken cerr<<"Compile successful\n";cerr<<fixed<<setprecision(10);cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl #define Fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>t;while(t--) #define tou(s) transform(s.begin(),s.end(),s.begin(),::touppe...
cpp
1284
B
B. New Year and Ascent Sequencetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputA sequence a=[a1,a2,…,al]a=[a1,a2,…,al] of length ll has an ascent if there exists a pair of indices (i,j)(i,j) such that 1≤i<j≤l1≤i<j≤l and ai<ajai<aj. For example, the sequence [0,2,0,...
[ "binary search", "combinatorics", "data structures", "dp", "implementation", "sortings" ]
#include <bits/stdc++.h> using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);...
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
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 <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> //#define int long long #define all(v) ...
cpp
1301
D
D. Time to Runtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBashar was practicing for the national programming contest. Because of sitting too much in front of the computer without doing physical movements and eating a lot Bashar became much fatter. Bashar is going...
[ "constructive algorithms", "graphs", "implementation" ]
#include <bits/stdc++.h> using namespace std; #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define all(_) _.begin(), _.end() #define rall(_) _.rbegin(), _.rend() #define sz(_) (int)_.size() #define fs first #define se second #define Odd(_x) ((_x) & 1) using i64 = long long; using ll = ...
cpp
1321
A
A. Contest for Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, a...
[ "greedy" ]
// <3 // #include<bits/stdc++.h> #define ll long long #define out return 0; #define str string #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int main() { FAST int n, k = 0, m = 0, l = 0; cin>>n; int a[n], b[n]; for (int i = 0; i < n; i ++) ...
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> using namespace std; #define ll long long #define vll vector<ll> #define mll map<ll,ll> #define cinv(v) ll x; cin>>x; v.push_back(x); #define floop(i,b) for(ll i=0;i<b;i++) #define fr(i,a,b) for(ll i=a;i<b;i++) #define sortv(v) sort(v.begin(),v.end()) #define ayk ll t; cin>>t; while(t...
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" ]
#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
1310
A
A. Recommendationstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVK news recommendation system daily selects interesting publications of one of nn disjoint categories for each user. Each publication belongs to exactly one category. For each category ii batch algori...
[ "data structures", "greedy", "sortings" ]
#include <bits/stdc++.h> #define pb push_back #define sz(v) ((int)(v).size()) using namespace std; using ll = long long; class Task { public: void solve() { int l; cin >> l; vector<ll> arr(l); for (int i = 0; i < l; i++) { cin >> arr[i]; } ...
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; typedef long long ll; vector<int> func(vector<vector<int>> &roads, int x) { int n = roads.size(); queue<int> q; vector<int> dist(n, 1e9); q.push(x); dist[x] = 0; while (q.size()) { int a = q.front(); q.pop(); int d...
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" ]
#include<bits/stdc++.h> using namespace std; #define lb long double int n,m,Q,cnt,xl[51][2]; lb ans; inline int rd(){ int s=0;char ch=getchar();bool f=0; while(ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar(); while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return f?-s:s; } struct fyl{ #define NN...
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" ]
/* B. Food Buying time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output - Mishka wants to buy some food in the nearby shop. Initially, he has s burles on his card. - Mishka can...
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 <iostream> #include <vector> #include <cstdio> #include <map> #define int long long #define maxn 600005 using namespace std; inline int read(){ int x = 0, flag = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') flag = -1; ch = getchar(); } wh...
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 endl '\n' #define ll long long const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll a, fa, sum=0; cin>>a; fa = a; for (ll i=2; i<a; i++) { fa=a; while (fa>0) { sum+=fa%i; ...
cpp
1288
A
A. Deadlinetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAdilbek was assigned to a special project. For Adilbek it means that he has nn days to run a special program and provide its results. But there is a problem: the program needs to run for dd days to calculate...
[ "binary search", "brute force", "math", "ternary search" ]
#include<bits/stdc++.h> #include <fstream> #include <cstdlib> #include<conio.h> #include <windows.h> #include <stdlib.h> #include <time.h> #define pb push_back #define ll long long #define dbl double #define srt(massiv) sort(massiv.begin(),massiv.end()) #define rvrs(massiv) reverse(massiv.begin(),massiv.end(...
cpp
1310
A
A. Recommendationstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVK news recommendation system daily selects interesting publications of one of nn disjoint categories for each user. Each publication belongs to exactly one category. For each category ii batch algori...
[ "data structures", "greedy", "sortings" ]
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const double PI = acos(-1); const ll mod7 = 1e9 + 7; const ll mod9 = 998244353; const ll INF = 2...
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" ]
//Your worst fear owns this #include <bits/stdc++.h> #define ll long long int #define srv(v) sort(v.begin(),v.end()) #define rrv(s1) sort(s1.begin(),s1.end(),greater<ll>()) #define str string #define sz size() #define dv(v) vector<ll> v #define ds(s) set<ll> s #define dm...
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" ]
using namespace std; #include <bits/stdc++.h> #define int long long #define repp(n) for(int i=0;i<n;i++) #define mod 1000000007 void solve() { int n,k,ans=0;cin>>n>>k; string a[n]; repp(n)for(int j=0;j<k;j++){ char c;cin>>c; a[i]+=c; } map<string,int> m; rep...
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" ]
// LUOGU_RID: 99815778 #include <bits/stdc++.h> using namespace std; #define int long long #define mp make_pair #define inf 1e9 #define pii pair <int, int> const int mod = 998244353; inline int read () { int x = 0, f = 1; char ch = getchar (); while (ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = g...
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<iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ string s; cin>>s; bool flag=false; int first_index=0; for(int i=0;i<s.length();i++){ if(s[i]=='1'){ first_index=i; break; ...
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> #include <random> #include <chrono> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long ll; typedef unsigned long long ull; typedef long double ld;...
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> #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() using namespace std; typedef long long lint; typedef pair<lint, int> pi; const int MAXN = 300005; vector<int> gph[MAXN]; int dist[2][MAXN]; void bfs(int x, int *dist){ dist[x] = 0; queue<int> que; que.push(...
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<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);} struct tree { std::...
cpp
1322
B
B. Presenttime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputCatherine received an array of integers as a gift for March 8. Eventually she grew bored with it; and she started calculated various useless characteristics for it. She succeeded to do it for each one she cam...
[ "binary search", "bitmasks", "constructive algorithms", "data structures", "math", "sortings" ]
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #include <ext/rope> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/trie_policy.hpp> #include <ext/pb_ds/priori...
cpp
1303
E
E. Erase Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss. You can build new string pp from ss using the following operation no more than two times: choose any subsequence si1,si2,…,siksi1,si2,…,sik where 1≤i1<i2<⋯<ik≤|s|1≤i1<i...
[ "dp", "strings" ]
#pragma GCC optimize("O2") #pragma GCC target("avx,avx2,fma") #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; #define ll long long #define test int _TEST; cin>>_TEST; while(_TEST--) #define ff ...
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<iostream> #include <bits/stdc++.h> #include <ext/numeric> using namespace std; //using L = __int128; #include<ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using ld = long double; #define nd "\n" ...
cpp
1288
F
F. Red-Blue Graphtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a bipartite graph: the first part of this graph contains n1n1 vertices, the second part contains n2n2 vertices, and there are mm edges. The graph can contain multiple edges.Initially, each...
[ "constructive algorithms", "flows" ]
// LUOGU_RID: 92279710 #include <bits/stdc++.h> using namespace std; #define Int register int #define inf 0x3f3f3f3f #define int long long #define MAXM 50005 #define MAXN 5005 template <typename T> void read (T &x){char c = getchar ();x = 0;int f = 1;while (c < '0' || c > '9') f = (c == '-' ? -1 : 1),c = getchar ();w...
cpp
1288
F
F. Red-Blue Graphtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a bipartite graph: the first part of this graph contains n1n1 vertices, the second part contains n2n2 vertices, and there are mm edges. The graph can contain multiple edges.Initially, each...
[ "constructive algorithms", "flows" ]
#include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; //typedef tree<int, nu...
cpp
1312
G
G. Autocompletiontime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a set of strings SS. Each string consists of lowercase Latin letters.For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type...
[ "data structures", "dfs and similar", "dp" ]
#pr\ agma optimize("Ofast") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #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 l...
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() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int32_t n; cin >> n; string str; cin >> str; cout << n+1; return 0; }
cpp
1321
C
C. Remove Adjacenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string ss consisting of lowercase Latin letters. Let the length of ss be |s||s|. You may perform several operations on this string.In one operation, you can choose some index ii and re...
[ "brute force", "constructive algorithms", "greedy", "strings" ]
#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;...
cpp
1294
C
C. Product of Three Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given one integer number nn. Find three distinct integers a,b,ca,b,c such that 2≤a,b,c2≤a,b,c and a⋅b⋅c=na⋅b⋅c=n or say that it is impossible to do it.If there are several answers, yo...
[ "greedy", "math", "number theory" ]
#include <iostream> using namespace std; void solve(){ int n,a=2,b=3,c=4; cin>>n; if (n<24){ cout<<"NO\n"; return ; } while(a*b*c<=n){ while(a*b*c<=n) { c=n/(a*b); if (a*b*c==n && c!=a && c!=b){ cout<<"YES\n"<<a<<' '<<b<<' ...
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> #define all(x) (x).begin(), (x).end() typedef long long ll; #define range(i, n) for(int i = 0; i < (n); ++i) #define rangex(i, n, x) for(int i = x; i <= (n); ++i) #define vcin(a) for (auto &i : a) cin >> i #define yes cout << "YES\n"; #define no cout << "NO\n"; using namespace std; voi...
cpp
1303
G
G. Sum of Prefix Sumstime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputWe define the sum of prefix sums of an array [s1,s2,…,sk][s1,s2,…,sk] as s1+(s1+s2)+(s1+s2+s3)+⋯+(s1+s2+⋯+sk)s1+(s1+s2)+(s1+s2+s3)+⋯+(s1+s2+⋯+sk).You are given a tree consisting of nn vertices. Eac...
[ "data structures", "divide and conquer", "geometry", "trees" ]
#include <bits/stdc++.h> using namespace std; using poly = vector <int>; int n, a[150005]; poly g[150005]; bool vis[150005]; int f[150005], siz[150005], sum, rt = 0; long long ans = 0; void findrt(int u, int fa) { f[u] = 0, siz[u] = 1; for (auto v : g[u]) { if (v != fa && !vis[v...
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" ]
// LUOGU_RID: 93923800 #include<stdio.h> #include<bits/stdc++.h> #define fir first #define sec second #define all(x) begin(x),end(x) using namespace std; typedef long long ll; typedef unsigned uint; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef __int128 int128; typedef ...
cpp
1141
C
C. Polycarp Restores Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2...
[ "math" ]
#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
1286
B
B. Numbers on Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvlampiy was gifted a rooted tree. The vertices of the tree are numbered from 11 to nn. Each of its vertices also has an integer aiai written on it. For each vertex ii, Evlampiy calculated cici — the n...
[ "constructive algorithms", "data structures", "dfs and similar", "graphs", "greedy", "trees" ]
#include<bits/stdc++.h> using namespace std; int n; int fa[2005],rk[2005],rt; vector<int> vec[2005],tmp[2005]; void dfs(int x){ if(!rk[x])tmp[x].push_back(x); for(auto u:vec[x]){ dfs(u); for(auto it:tmp[u]){ tmp[x].push_back(it); if(tmp[x].size()==rk[x])tmp[x].push_back(x); } } if(tmp[x].size()<rk[x]){ puts("NO"); exi...
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 main(){ int t,n,d,num; cin >> t; while(t--){ cin >> n >> d; int ans=0; for(int i=0;i<n;i++){ cin >> num; if(i==0){ ans=num; }else if(d>=i*num){ ans+=num; d-=i*num; }else{ ans+=d/i; d=0; } } cout << ans << endl; } }
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" ]
#include "bits/stdc++.h" using namespace std; signed main() { int n, m; scanf("%d%d", &n, &m); vector<string> a(n); for (auto &i: a) cin >> i; int cnt = 0; map<string, int> mp; for (auto i: a) mp[i]++; for (int i = 0; i < n; i++) { for (int j = i + 1; j < ...
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" ]
#line 1 "library/my_template.hpp" #if defined(LOCAL) #include <my_template_compiled.hpp> #else #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<ll, ll>; using vi = vector<ll>; using u32 = unsigned int;...
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> using namespace std; #define ar array #define vc vector #define ll long long #define db long double #define mk make_pair #define pb push_back #define umap unordered_map #define sz(A) ((int)(A.size())) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(), x.rend() #define lin...
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> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int int64_t #define endl '\n' #define inf 2e18 #define vi vector<int> ...
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" ]
#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 n, m; cin >> n >> m; if (n <= 2) { if (m) cout << "...
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 #define AWM() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int main() { AWM(); int t; cin>>t; while(t--) { ll int x,y,a,b,sum; cin>>x>>y>>a>>b; sum=abs(x-y); if(sum%(a+b)==0) cout<...
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> #define _CRT_SECURE_NO_WARNINGS #define ll long long #define all(x) (x).begin(), (x).end() #define test_case int t;cin>>t;while(t--) #define endl '\n' ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } using namespace std; void ...
cpp
1310
D
D. Tourismtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha lives in a country with nn cities numbered from 11 to nn. She lives in the city number 11. There is a direct train route between each pair of distinct cities ii and jj, where i≠ji≠j. In total there are ...
[ "dp", "graphs", "probabilities" ]
#include<bits/stdc++.h> #define task "C" #define ll long long #define ld long double #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 80 + 5; const ll INF = 1e18 + 5; int n, k; int a[MAXN][MAXN]; void Input() { cin >> n >> k; for (int i = 1; i <= n...
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 int long long #define fa(i,a,n) for(int i=a;i<n;i++) #define pb push_back #define bp pop_back #define mp make_pair #define all(v) v.begin(),v.end() #define vi vector<int> #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; void solve(){ ...
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" ]
// Siddharth Ruria //Linkedin: https://www.linkedin.com/in/ruria-siddharth/ //Codeforces: https://codeforces.com/profile/Sw00sh //Codechef: https://www.codechef.com/users/airurdis #include <iostream> #include <bits/stdc++.h> // #include <sys/resource.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_d...
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" ]
// LUOGU_RID: 101076511 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 5; const int M = 1e6 + 5; int n, prime[M], tot; ll a[N]; mt19937 rnd(19260817); bool vis[M]; inline void Euler() { for (int i = 2; i <= M - 5; i++) { if (!vis[i]) prime[++tot] = i;...
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> #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
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 first #define s second #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) ((int) (x).size()) using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; using vp = vector <pii>; using vl = ...
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" ]
//#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; /*测量运行时间 #include <windows.h> DWORD star_time = GetTickCount(); DWORD end_time = GetTickCount(); cout << (end_time - star_time) << "ms." << endl; */ typedef long long ll; typedef pair<int,int> PII; typedef double db; #define pb push_bac...
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<iostream> #include<cstring> using namespace std; using LL = long long; const int maxn = 3e5 + 5; int n, a, b, c; int f[1005][3]; int sg[maxn], val[maxn]; int dp(int x, int y){ if (~f[x][y]) return f[x][y]; int s[4] = {0}; s[dp(max(0, x - a), 0)] = 1; if (y != 1) s[dp(max(0, x - b)...
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" using namespace std; #define ll long long const int MAXN = 100100; const int LOG = 20; int n; vector<int> g[MAXN]; int dep[MAXN]; int jp[LOG][MAXN]; void dfs(int c, int l, int d) { dep[c] = d; jp[0][c] = l; for (int i : g[c]) { if (i == l) continue; dfs(i, c, d + 1); } } in...
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> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long #define vvll vector<vector<ll>> #define all(v) v.begin(),v.end() #define vvc vector<vector<char>> #define vss vector<string> #define emp emplace #define pb push_back #define pf push_front ...
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; #include <cmath> #include <algorithm> #define ll long long #define fi first #define se second #define sst string #define pb push_back #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <cli...
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> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define int long long int #define ll long long #define mod 1000000007 // #define mod 998244353 #define fastIO \ ios_base...
cpp
1290
D
D. Coffee Varieties (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. You can find the easy version in the Div. 2 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.Th...
[ "constructive algorithms", "graphs", "interactive" ]
#include<bits/stdc++.h> using namespace std; int n,K,kc,ks,vis[1030]; char s[3]; void ins(int x){ int l=kc*x+1,r=l+kc-1; for(int i=l;i<=r;i++)if(!vis[i]){cout<<"? "<<i<<endl;cin>>s;if(s[0]=='Y')vis[i]=1;} } void work(int x){ ins(x); for(int i=1;i<(ks>>1);i++){ ins((x-i+ks)%ks); ins((x+i)%ks); }if(ks>1)ins((x+(ks>>1))%k...
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" ]
#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
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; #define FAST_IO ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define ll long long #define loop(n) for (int i{0}; i<n; ++i) #define lop(n) for (int i{1}; i<n; ++i) const int N = 2e5+7, mod= 1e9 + 7; int left_most(int n){ int pos = 0; ...
cpp
1284
B
B. New Year and Ascent Sequencetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputA sequence a=[a1,a2,…,al]a=[a1,a2,…,al] of length ll has an ascent if there exists a pair of indices (i,j)(i,j) such that 1≤i<j≤l1≤i<j≤l and ai<ajai<aj. For example, the sequence [0,2,0,...
[ "binary search", "combinatorics", "data structures", "dp", "implementation", "sortings" ]
#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
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" ]
// Depressed boy Bhaskor Roy #include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb ...
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 ll long long // ll int N = 1e9+7; #define f(n) for (auto i = 0; i < n; i++) #define fo(i, k, n) for (auto i = k; i < n; i++) #define ff first #define ss second #define vi vector<int> #define rep(i, a, b) for (int i = a; i < b; i++) #define pb push_back #d...
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" ]
#include "iostream" using namespace std; int n,m; int cnt=0; int main(){ cin>>n>>m; int temp=m/n; if(m%n!=0){ cout<<"-1"; return 0; } while(temp%2==0) { cnt++; temp/=2; } while(temp%3==0) { cnt++; temp/=3; } if(temp!=1){ ...
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; #ifdef ONLINE_JUDGE #define fast ios_base::sync_with_stdio(0); cin.tie(0); // fast IO! b...
cpp
1304
F1
F1. Animal Observation (easy 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" ]
// OMAR AL-MIDANI // /* ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣤⣀⡀⠄⠄⠄⠄⠄⣰⣷⡀⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠄⣀⣀⣀⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠄⠄⢠⣿⣿⣷⠄⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠤⠒⠛⠛⠛⠛⠻⠷⣦⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣿⣿⣿⠟⠁⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⢀⣤⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⡤⠐⠄⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⢀⣶⣿⣿⠿⢛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿...
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; const int N = 200005; int dis1[N], disn[N]; bitset<N> special; vector<int> g[N]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < k; ++i) { int x; cin >> x; specia...
cpp
1324
D
D. Pair of Topicstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe next lecture in a high school requires two topics to be discussed. The ii-th topic is interesting by aiai units for the teacher and by bibi units for the students.The pair of topics ii and jj (i<ji...
[ "binary search", "data structures", "sortings", "two pointers" ]
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll a, b[200001] = {}, c, res = 0, now = 0; cin >> a; for (ll i = 0; i < a; i++) cin >> b[i]; for (ll i = 0; i < a; i++) { cin >> c; b[i] -= c; } sort(b, b + a); for (ll ...
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> #define fi first #define se second #define faster ios_base::sync_with_stdio(0); cin.tie(0); #define pb push_back using namespace std; using ll = long long; using pii = pair <int, int>; mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 2e5 + 1; c...
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
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 <iostream> #include <cmath> using namespace std; int sum(long long int a, long long int b, long long int c){ return a+b+c; } int main() { int t; long long int a, b, c, n; long long int diff; cin >> t; while(t--){ cin >> a >> b >> c >> n; int arr[3]={a, b, c}; sort(arr, arr+3); dif...
cpp
1296
C
C. Yet Another Walking Robottime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a robot on a coordinate plane. Initially; the robot is located at the point (0,0)(0,0). Its path is described as a string ss of length nn consisting of characters 'L', 'R', 'U', 'D'....
[ "data structures", "implementation" ]
#include <bits/stdc++.h> #define ll long long int #define take(n) ll n; cin>>n; #define fo(i,n) for(ll i = 0; i<(ll)n; ++i) #define rep(i,a,b,d) for(ll i=a; (d<0)?(i>b):(d>0)?i<b:0; i += d) #define takevect(a,n) vector<ll> a(n); fo(q,n) cin>>a[q]; #define el "\n" #define pii pair<ll,ll> #define F first #define...
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" ]
#include <bits/stdc++.h> using namespace std; #define pb push_back //typedef __int128 lll; #define ll long long #define all(x) x.begin(),x.end() #define repp(n) for(int i=0;i<n;i++) const ll MOD=998244353; const ll mod = 1e9 +7; void solve(){ ll n,a,b,k; cin>>n>>a>>b>>k; vector<ll> h(n);...
cpp
1284
C
C. New Year and Permutationtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputRecall that the permutation is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a ...
[ "combinatorics", "math" ]
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, j, k) for (int i = j; i <= k; i++) #define FORR(i, j, k) for (int i = j; i >= k; i--) ll inf = 0x3f3f3f3f, linf = LLONG_MAX/2; ll MOD = 1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll...
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> #define int long long using namespace std; const int maxn = 1e6 + 10; int n,m; int f[4*maxn],lazy[4*maxn]; void down(int x, int lx, int rx) { f[x]+=(rx-lx+1)*lazy[x]; if (lx!=rx) { lazy[2*x]+=lazy[x]; lazy[2*x+1]+=lazy[x]; } lazy[x]=0; } void add(int x, int...
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> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; typedef long long ll; typedef long double ldb; t...
cpp
1325
D
D. Ehab the Xorcisttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven 2 integers uu and vv, find the shortest array such that bitwise-xor of its elements is uu, and the sum of its elements is vv.InputThe only line contains 2 integers uu and vv (0≤u,v≤1018)(0≤u,v≤1...
[ "bitmasks", "constructive algorithms", "greedy", "number theory" ]
#include <bits/stdc++.h> using namespace std; int main() { long long u,v; scanf("%I64d%I64d",&u,&v); if (u%2!=v%2 || u>v) { printf("-1"); return 0; } if (u==v) { if (!u) printf("0"); else printf("1\n%I64d",u); return 0;...
cpp
1291
F
F. Coffee Varieties (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. You can find the hard version in the Div. 1 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.Th...
[ "graphs", "interactive" ]
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; int n, k; vector<int> B[MAXN]; set<pll> st; inli...
cpp
1304
F1
F1. Animal Observation (easy 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" ]
// LUOGU_RID: 101284988 #include <bits/stdc++.h> #define int long long #define mem(a,b) memset(a,b,sizeof(a)) #define fre(z) freopen(z".in","r",stdin),freopen(z".out","w",stdout) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> Pair; const double eps=1e-8; const ...
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> #define ll long long #define ull unsigned long long #define int ll #define fr first #define se second #define INF 0x3f3f3f3f #define LINF 0x3f3f3f3f3f3f3f3f #define For(i,a,b) for(int i = a; i <= b; ++i) #define Rep(i,a,b) for(int i = a; i >= b; --i) using namespace std; typedef pair<int,int> pi...
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 <ranges> #include <algorithm> #include <numeric> #include <vector> #include <array> #include <set> #include <map> #include <bit> #include <sstream> #include <list> #include <stack> #include <queue> typedef long long integerType; typedef integerType z; typedef std::vector<in...
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
1285
C
C. Fadi and LCMtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Osama gave Fadi an integer XX, and Fadi was wondering about the minimum possible value of max(a,b)max(a,b) such that LCM(a,b)LCM(a,b) equals XX. Both aa and bb should be positive integers.LCM(a,b)L...
[ "brute force", "math", "number theory" ]
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; const ll mod = 998244353; const int mm = 1e5 + 10; ll dp[mm*10]; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); ll x; cin>>x; ll bjx=x; vector<ll>v; for(int i=2;i<=...
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" ]
/* * created by Mohamed hossam #### #### ## ## ## ## ## ## ##### ## ## ###### ## ## ## ## ## ## ## ####### ############## ## ## ######## ## ###### ## ## ...
cpp
1301
F
F. Super Jabertime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJaber is a superhero in a large country that can be described as a grid with nn rows and mm columns, where every cell in that grid contains a different city.Jaber gave every city in that country a specifi...
[ "dfs and similar", "graphs", "implementation", "shortest paths" ]
/// Nu am loc de lista de adicenta? Calculez singur vecinii. /// Nota: Nu e nev de nodurile auxiliare pentru a compresa graful - daca ma joc odata prin culoare, nu ma mai uit #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " "...
cpp
1141
D
D. Colored Bootstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn left boots and nn right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings ll and rr, both of length nn. The...
[ "greedy", "implementation" ]
#include <bits/stdc++.h> #define ll long long #define yes cout << "YES\n" #define no cout << "NO\n" #define pb insert #define mod 998244353 using namespace std; mt19937 rng(time(0)); int random(int l, int r) { return rng() % (r - l + 1) + l; } int main() { int n; cin>>n; string a,b; cin>>a...
cpp
1287
A
A. Angry Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a walking tour day in SIS.Winter; so tt groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are an...
[ "greedy", "implementation" ]
#define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; #define l "\n" #define mod 100000009; #define L_M LLONG_MAX typedef unsigned long long ull; #define all(v) v.begin(),v.end() ll gcd(ll a, ll b) { return(!b) ? a : gcd(b, a % b); } ll lcm(...
cpp