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 |
|---|---|---|---|---|---|
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;
typedef long long ll;
inline int read(){
int f=1,r=0;char c=getchar();
while(!isdigit(c))f^=c=='-',c=getchar();
while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
return f?r:-r;
}
#define pii pair<int,int>
#define fi first
#define se second
const int N=57,inf=0x3f3... | 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;
int main()
{
int t;
cin>>t;
while(t--){
long long int s,ans=0;
cin>>s;
while(s){
ans+=((s/10)*10);
s=(s%10)+(s/10);
if(s<10)break;
}
ans+=s;
cout<<ans<<endl;
... | 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"
] | /* In The Name Of God */
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define sortt(v) sort(v.begin(), v.end())
typedef long long ll;
const ll maxx = 1e10 + 10;
void solve()
{
string s; cin >> s;
vector... | cpp |
1324 | A | A. Yet Another Tetris Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given some Tetris field consisting of nn columns. The initial height of the ii-th column of the field is aiai blocks. On top of these columns you can place only figures of size 2×12... | [
"implementation",
"number theory"
] | #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 |
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 fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sort(v) sort(v.begin(),v.end())
void solve(){
string s;
cin>>s;
map<char,int> mp;
map<string,int> mp1;
vector<int> v;
int mx=0;
int mx1=0;
for... | 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: 101881164
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma... | 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"
] | // Akash Singh
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //Make less_equal for multiset
// find_by_order(k) ... | 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"
] | // LUOGU_RID: 101660289
#include <bits/stdc++.h>
#define ll int
#define ull unsigned long long
using namespace std;
const int N=2030;
ll dp[N][N],sm[N][N],a[N],mod=998244353,rg,n,k;
ll ans=0,smz=0,biao[N]= {
0,1,2,4,6,8,12,16,20,26,33,40,50,61,72,87,104,121,143,167,192,224,259,295,339,387,437,497,563,631,712,8... | cpp |
1316 | D | D. Nash Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands. This board game is played on the n×nn×n b... | [
"constructive algorithms",
"dfs and similar",
"graphs",
"implementation"
] | #include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t) int t; cin >> t; for(int i = 1; i <= t; i++)
#def... | 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"
] | #include<bits/stdc++.h>
using namespace std;
int dp[51][20009];
int a[51][20009];
int pf[51][20009];
int st[80009];
int lazy[80009];
void push(int id){
if (lazy[id]==0)return;
st[id*2]+=lazy[id];
st[id*2+1]+=lazy[id];
lazy[id*2]+=lazy[id];
lazy[id*2+1]+=lazy[id];
lazy[id]=0;
}
void update(int id,int l,in... | cpp |
1322 | E | E. Median Mountain Rangetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBerland — is a huge country with diverse geography. One of the most famous natural attractions of Berland is the "Median mountain range". This mountain range is nn mountain peaks, located on one... | [
"data structures"
] | // BEGIN BOILERPLATE CODE
#include <bits/stdc++.h>
using namespace std;
#ifdef KAMIRULEZ
const bool kami_loc = true;
const long long kami_seed = 69420;
#else
const bool kami_loc = false;
const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif
const string kami_fi =... | 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"
] | //#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define UseOFF ios_base::sync_with_stdio(0);cin.tie(0), cout.tie(0);
#d... | cpp |
1304 | F2 | F2. Animal Observation (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraint on kk.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The ... | [
"data structures",
"dp",
"greedy"
] | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve ve... | 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"
] | #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define elif else if
#define ALL(x) x.begin(),x.end()
#define lowbit(x) (x&(-x))
using namespace std;
void fileio(const string &s)
{
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int INF=4e1... | cpp |
1316 | F | F. Battalion Strengthtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn officers in the Army of Byteland. Each officer has some power associated with him. The power of the ii-th officer is denoted by pipi. As the war is fast approaching, the General would ... | [
"data structures",
"divide and conquer",
"probabilities"
] | // LUOGU_RID: 99436832
#pragma GCC optimize(2,3,"Ofast","inline","unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
const int md=1e9+7,N=300010;
int tmp[N<<... | 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;
typedef long long ll;
typedef pair<ll,ll> pll;
#define MP make_pair
#define MAXN 5069
#define LL_MIN LONG_LONG_MIN
#define LL_MAX LONG_LONG_MAX
pll p[MAXN]; vector<ll> adj[MAXN];
vector<pll> edges;
vector<pair<pll,ll>> updates;
ll h[MAXN];
void dfs(ll x, ll par)... | 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: 102248085
#include <bits/stdc++.h>
using namespace std;
const int N = 600010,MASK = (1<<30)-1;
int n,col[N],necol[N][27],w[N],ne[N];
char str[N];
__int128 ans;
struct map_doge{
map<int,int> mp;
map<int,int>::iterator it;
long long sum;
void init(){return;}
void insert(int val){
it = mp.... | cpp |
1295 | D | D. Same GCDstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers aa and mm. Calculate the number of integers xx such that 0≤x<m0≤x<m and gcd(a,m)=gcd(a+x,m)gcd(a,m)=gcd(a+x,m).Note: gcd(a,b)gcd(a,b) is the greatest common divisor of aa and bb.I... | [
"math",
"number theory"
] | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
ll a,m;
cin>>a>>m;
ll GCD = __gcd(a,m);
a = a/GCD;
m = m/GCD;
ll ans = m,m1 = m;
for(ll j... | cpp |
1310 | C | C. Au Pont Rougetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVK just opened its second HQ in St. Petersburg! Side of its office building has a huge string ss written on its side. This part of the office is supposed to be split into mm meeting rooms in such way th... | [
"binary search",
"dp",
"strings"
] | #include <bits/stdc++.h>
#define int long long
using namespace std;
string s;
int lcp[1005][1005];
bool cmp(pair<int,int> x,pair<int,int> y)
{
int L=lcp[x.first][y.first];
int px=x.first+L,py=y.first+L;
if(px>x.second||py>y.second) return x.second-x.first<y.second-y.first;
return s[px]<s[py];
}
pair<in... | 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 <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<ll> x(n);
vector<ll> y(n);
for(int i=0;i<n;i++){ci... | cpp |
1292 | D | D. Chaotic V.time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputÆsir - CHAOS Æsir - V."Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time."The emotion samples are now suffici... | [
"dp",
"graphs",
"greedy",
"math",
"number theory",
"trees"
] | // #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 |
1141 | B | B. Maximal Continuous Resttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach day in Berland consists of nn hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a1,a2,…,ana1,a2,…,an (each aiai is either 00 or 11)... | [
"implementation"
] | #include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
ll n,rest = 0,ans = 0;
cin>>n;
vector... | cpp |
1292 | D | D. Chaotic V.time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputÆsir - CHAOS Æsir - V."Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time."The emotion samples are now suffici... | [
"dp",
"graphs",
"greedy",
"math",
"number theory",
"trees"
] | #include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int INF = 1e9;
int lpf[N], lca[N][N];
int vp[N], freq[N], freqs[N];
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
iota(lpf, lpf+N, 0);
for (int l = 1; l < N; l++) {
for (int r = l+1; r < N; r++) {
lca[l][r] ... | cpp |
1284 | A | A. New Year and Namingtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHappy new year! The year 2020 is also known as Year Gyeongja (경자년; gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Ko... | [
"implementation",
"strings"
] | // ~BhupinderJ
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define spc <<" "<<
#define pii pair<int, int>
#define vvi vector<vector<int>>
//#define int long long
const int M = 1e9+7;
const int N = 1e5+1;
bool SOLVE(){
int n, m; cin >> n >> m;
vector<string> s(n), t(m);
for(i... | 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<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll mod = 1e9+7;
const int mm = 2e5 + 10;
ll up[1005][15],down[1005][15];
ll qian[1005],hou[1005];
ll ansh[1005];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int ... | 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 |
1315 | B | B. Homecomingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a long party Petya decided to return home; but he turned out to be at the opposite end of the town from his home. There are nn crossroads in the line in the town, and there is either the bus or the tr... | [
"binary search",
"dp",
"greedy",
"strings"
] | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
void iosbase(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll p,a,b;
string s;
bool get(ll pos){
ll ans=0;
vector<char> v;
v.push_back(s[pos-1]);
for(ll i=pos+1;... | cpp |
1316 | D | D. Nash Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands. This board game is played on the n×nn×n b... | [
"constructive algorithms",
"dfs and similar",
"graphs",
"implementation"
] | /**
* Author: Richw818
* Created: 01.25.2023 23:09:49
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string dir = "ULDR";
int n; cin >> n;
ve... | cpp |
1291 | A | A. Even But Not Eventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a number ebne (even but not even) if and only if its sum of digits is divisible by 22 but the number itself is not divisible by 22. For example, 1313, 12271227, 185217185217 are ebne num... | [
"greedy",
"math",
"strings"
] | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define em emplace_back
#define fi(l, r) for(ll i=l; i<r; i++)
#define fir(r, l) for(ll i=r; i>=l; i--)
void solve(){
ll n;
cin >> n;
string s;
cin >> s;
if(s.length() <= 1){
cout << -1 << endl;
return... | cpp |
1288 | D | D. Minimax Problemtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given nn arrays a1a1, a2a2, ..., anan; each array consists of exactly mm integers. We denote the yy-th element of the xx-th array as ax,yax,y.You have to choose two arrays aiai and ajaj (1≤i,j... | [
"binary search",
"bitmasks",
"dp"
] | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
# define mod 1000000007
int a[300000+10][10];
int b[1010],n,m;
int ans1,ans2;
bool check(int mid)
{
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
int now=0;
for(int j=1;j<=m;j++)
{
i... | 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"
] | #include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define all(x) x.begin(), x.end()
#define ull unsigned long long
#define pii pair < int , int >... | cpp |
1311 | F | F. Moving Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn points on a coordinate axis OXOX. The ii-th point is located at the integer point xixi and has a speed vivi. It is guaranteed that no two points occupy the same coordinate. All nn points mo... | [
"data structures",
"divide and conquer",
"implementation",
"sortings"
] | // LUOGU_RID: 100872105
#include <bits/stdc++.h>
using namespace std;
#define max_n 200100
#define int long long
void read(int &p)
{
p = 0;
int k = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
{
k = -1;
}
c = getchar();
}
while... | 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>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll mm = 1e5 + 10;
int mi[mm],ma[mm],bj[mm];
int mii[mm*10],maa[mm*10];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
mi[i]=1000... | 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;
#define ll long long
#define mod 1000000007
int main(){
ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr);
int T=1; //cin>>T;
while(T--) {
int n; cin>>n;
ll cnt=0;
vector<ll>a(n),v(n);
for(int i=0;i<n... | 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"
] | //Author: Ankush Bhagat (https://github.com/ankushbhagat124)
//RFIPITIDS
#include <bits/stdc++.h>
#define int long long
const int N = (int)(3e5 + 1);
const int mod = (int)(1e9 + 7);
using namespace std;
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
... | 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;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
long long gcd(long long int a, long long int b)
{
if (b == 0)
return a;
return gcd(b, a % b);... | 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"
] | // LUOGU_RID: 102584653
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 22
ll n;
ll p[N],a[N];
ll f[1<<N];
ll cnn[1<<N];
bool vis[1<<N];
inline ll suan(ll x){
if(f[x]!=-1)return f[x];
ll an=(vis[x]);
for(int i=(x-1)&x;i;i=(i-1)&x){
if(!vis[x^i])continue;
// if(cnn[i]/2+1... | 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>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n];
int b[n];
for(int i =0; i<n; i++){
cin>>a[i];
}
for(int i =0; i<n; i++){
cin>>b[i];
}
... | 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;
//#define int long long
typedef pair<int,int> PII;
typedef long long LL;
const int INF=0x3f3f3f3f;
const long long LNF=0x3f3f3f3f3f3f3f3f;
const int mod=998244353;
const int N=200010,M=N<<1;
inline int read(){
int f=1,x=0;char s=getchar();
while(s<'0'||s... | cpp |
13 | E | E. Holestime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:There are N holes located in a single row and numbered from left to right with numbers from 1 to N. ... | [
"data structures",
"dsu"
] | #include<bits/stdc++.h>
using namespace std;
int const M=100100;int i,n,m,x,opt,block;
int a[M],L[M],R[M],bel[M],nxt[M],dis[M];
int read(){
int x=0;char ch=getchar();
while (ch<'0'||ch>'9') ch=getchar();
while (ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x;
}
void update(int x){
for (int i=R[x];... | 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<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,k;
ll g[N],d[N];
vector<pair<int,int>> adj[N];
map<int,int>f;
void dfs(int u,int p,int c){
int... | cpp |
1296 | E1 | E1. String Coloring (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easy version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format ... | [
"constructive algorithms",
"dp",
"graphs",
"greedy",
"sortings"
] | #include <bits/stdc++.h>
#define fbo find_by_order
#define ook order_of_key
#define del(x) erase(op.find_by_order(op.order_of_key(x)))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_t... | cpp |
1285 | B | B. Just Eat It!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday; Yasser and Adel are at the shop buying cupcakes. There are nn cupcake types, arranged from 11 to nn on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type ii i... | [
"dp",
"greedy",
"implementation"
] | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5, MOD = 1e9+7;
const long long INF = 1e18;
const double EPS = 1e-6, PI_Val = 3.141592653589793238;
/* --- YOU SHOULD HAVE A VISION --- */
bool flag;
int n;
long long sum;
int a[N];
int main()
{
ios_base::sync_with_stdio... | 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 |
1316 | D | D. Nash Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands. This board game is played on the n×nn×n b... | [
"constructive algorithms",
"dfs and similar",
"graphs",
"implementation"
] | // RADHASOAMI , WITH THE GRACE OF HUZUR I PROMISE TO FIGHT TILL THE LAST SECOND OF EVERY CONTEST AND CODE TO MY FULL POTENTIAL ......
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#define ll int
#d... | 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"
] | // Don't Quit O_O
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#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<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_upd... | 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;
void solve(){
int n; cin>>n;
int cs;
vector <int> s,c;
for (int i = 1 ; i <= 2*n ; i ++){
s.push_back(i);
}
for (int i = 0 ; i < n ; i ++){
cin>>cs;
c.push_back(cs);
remove(s.begin(),s.end(),cs);
... | cpp |
1290 | E | E. Cartesian Tree time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIldar is the algorithm teacher of William and Harris. Today; Ildar is teaching Cartesian Tree. However, Harris is sick, so Ildar is only teaching William.A cartesian tree is a rooted tree, that can be... | [
"data structures"
] | // LUOGU_RID: 102594139
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200010
#define inf (1e9)
ll n;
ll a[N];
ll ans[N];
ll pos[N];
struct sgt{
ll sum[N<<2],tag1[N<<2],tag2[N<<2],mx[N<<2],smx[N<<2],cn[N<<2],cnmx[N<<2];
inline void pushup(ll x){
sum[x]=sum[x<<1]+sum[x<<1|1]... | 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 int long long
int n, m, k;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
int all = 4 * n * m - 2 * n - 2 * m;
if (k > all) {
cout << "NO\n";
return 0;
}
n--;
m--;
// else there is al... | 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;
#pragma GCC optimize ("Ofast")
#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
#define mp(x , y) make_pair(x , y)
#define wall cout<<"--------------------------------------\n";
typedef long long int ll;
typedef pair<ll , ll> pll;
typedef pair<... | cpp |
1296 | F | F. Berland Beautytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn railway stations in Berland. They are connected to each other by n−1n−1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.You have a map of ... | [
"constructive algorithms",
"dfs and similar",
"greedy",
"sortings",
"trees"
] | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include<boost/algorithm/string.hpp>
//pragmas
#pragma GCC optimize("O3")
//types
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ull unsigned long long int
#define vec vector<... | 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>
#define int long long
using namespace std;
signed main()
{
int u, v;
cin >> u >> v;
if (u > v) {
cout << -1;
} else if (u == v && u != 0) {
cout << 1 << endl;
cout << u;
} else if (u == v && u == 0)
cout << 0;
else {
... | 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"
] | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define fi first
#define se second
#define space " "
#define endl "\n"
#define mp make_pair
#define pb push_back
#define pf push_front
#define md 1000000007
#define inf 1000000000
#define li 105
#define lo long long
using namespace std;
int T,n,m,k,a[li]... | 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"
] | /*
わんわん……わんだほーいっ☆
Wonderhoy!
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
char buf[1<<21],*p1=buf,*p2=buf;
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<18,stdin),p1==p2)?EOF:*p1++)
LL read()
{
LL x=0,f=1;
char c=getchar();
while(c<'0' || c>'9') f=(c=='-'?-1:f),... | 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"
] |
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned long long int
#define int long long int
#define vi vector<int>
#define ub upper_bound
#define lb lower_bound
#define vp vector<pair<int,int>>
#define pb push_back
#define po pop_back()
#define pii pair<int,int>
#define mod 1000000007
int... | 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<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5+10, M = 1050, inf = 1e6, mod = 1e9+7;
ll add ( ll a , ll b)
{
return (a + b) % mod;
}
ll mul ( ll a , ll b)
{
return 1LL * a * b % mod;
}
ll fp( ll b , ll p)
{
if(!p)
return 1;
ll temp = fp(b,p/2);
temp = m... | 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 ll long long
using namespace std;
const int N=2e6+10;
int n,m,z[N],za[N],zb[N];
char a[N],b[N],s[N],t[N];
void Z(char *s,int n){
z[1]=n;
for(int i=2,l=0,r=0;i<=n;i++){
if(i<=r)z[i]=min(z[i-l+1],r-i+1);
else z[i]=0;
while(i+z[i]<=n&&s[i+z[i]]==s[z[i]+1])++z[i];
if(i+z[i]-1>r)l=i,r=i+z[i]... | 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 <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 all(v) ((v).begin()), ((v).end())
#define siz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i <... | cpp |
1284 | A | A. New Year and Namingtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputHappy new year! The year 2020 is also known as Year Gyeongja (경자년; gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Ko... | [
"implementation",
"strings"
] | #include <iostream>
#include <iterator>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<ld> vld;
typedef std::vector<std::vector<ll>> vvll;
typedef std::vecto... | cpp |
1303 | B | B. National Projecttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour company was appointed to lay new asphalt on the highway of length nn. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip... | [
"math"
] | #include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
using namespace std ;
void solve() {
ll n,g,b ;
cin>>n>>g>>b ;
ll good_days = n/2/g*g + (ll)(ceil(n/2.0) - n/2/g*g);
ll bad_days = ((n/2/g-1)*b) + (ceil(n/2.0) - n/2/g*g != 0 ? b : 0);
ll rem_days = max(0L... | 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<iostream>
using namespace std;
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ... | cpp |
1290 | E | E. Cartesian Tree time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIldar is the algorithm teacher of William and Harris. Today; Ildar is teaching Cartesian Tree. However, Harris is sick, so Ildar is only teaching William.A cartesian tree is a rooted tree, that can be... | [
"data structures"
] | // LUOGU_RID: 101586530
#include <bits/stdc++.h>
using LL = long long;
const int inf32 = 1e9;
struct SNode {
SNode* son[2]{0};
LL sum{0};
int tag1{0}, tag2{inf32};
int cnt{0}, len{0}, max[2]{-inf32, -inf32};
};
#define L(p) p->son[0]
#define R(p) p->son[1]
void SBuild(SNode* &p, int l, ... | cpp |
13 | E | E. Holestime limit per test1 secondmemory limit per test64 megabytesinputstdinoutputstdoutLittle Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:There are N holes located in a single row and numbered from left to right with numbers from 1 to N. ... | [
"data structures",
"dsu"
] | #include <bits/stdc++.h>
typedef int32_t ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, m;
cin >> n >> m;
const ll c = 990;
ll nt[n];
for (ll i = 0; i < n; i++) {
ll e;
cin >> e;
nt[i] = i + e;... | 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>
#define ll long long
using namespace std;
int main(){
int t ;
cin>>t;
while(t--){
string a;
int k=0 ;
cin>>a;
for(int i=a.find('1') ;i<a.find_last_of('1');i++){
if(a[i]=='0'){
k++;
}
}
... | 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>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define vi vector<int>
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin>>t;
while (t--)
{
int n,p,c;
cin>>n>>p>>c;
int a[c];
for(int i=0;i<c;i++)cin>>a[i]... | 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;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll tc = 1;
// cin >> tc;
while (tc--) {
ll n;
... | 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>
using namespace std;
long long n , x , y , z , dp [10004][4] , arr [300005];
vector < int > bt [4];
int grundy ( long long x , int y )
{
if ( x < 2e3 ) return dp [x][y];
else
{
int xx = ( x - 1000 ) % bt [y] . size ();
return bt [y][xx];
}
}
int main(... | 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
#define inf INT_MAX
#define N 100005
ll q,n,m,k,ans=0,x,y,l,r,s,z;
ll lg[N],fa[N][21];
ll dep[N];
ll cnt=0,head[N];
bool flag;
struct edge{
ll x,y;
}e[2*N];
template<typename T>inline void read(T &n){
T w=1; n=0; char ch=getchar();
whil... | cpp |
1299 | A | A. Anu Has a Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9f(11,6)=(11|6)−6=15−6=9. It can be proved that for an... | [
"brute force",
"greedy",
"math"
] | #include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define ff first
#define ss second
#define forw(i,a,b) for(int i=a;i<b;i++)
#define backw(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int M=998244353;
void solve(){ ... | 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 |
1303 | B | B. National Projecttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour company was appointed to lay new asphalt on the highway of length nn. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip... | [
"math"
] | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define endl "\n"
const int N=1e5+2 , inf=2e9;
void solve ()
{
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int test; cin >> test;
whi... | cpp |
1286 | F | F. Harry The Pottertime limit per test9 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputTo defeat Lord Voldemort; Harry needs to destroy all horcruxes first. The last horcrux is an array aa of nn integers, which also needs to be destroyed. The array is considered destroyed if all its e... | [
"brute force",
"constructive algorithms",
"dp",
"fft",
"implementation",
"math"
] | #include<bits/stdc++.h>
#define Cn const
#define CI Cn int&
#define N 20
#define LL long long
using namespace std;
int n,f[1<<N],p[1<<N],c[1<<N];LL a[N+5],s[1<<N];
int main()
{
int i,j;for(scanf("%d",&n),i=1;i<=n;++i) scanf("%lld",a+i),a[i]?s[1<<i-1]=a[i]:(--i,--n);
int l=1<<n;for(i=0;i^l;++i) c[i]=c[i>>1]+(i&1);for(j... | cpp |
1305 | B | B. Kuroni and Simple Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow that Kuroni has reached 10 years old; he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifical... | [
"constructive algorithms",
"greedy",
"strings",
"two pointers"
] | #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);
string s;
cin >> s;
int n = s.size();
vi c(n);
vvi r;... | 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"
] | #pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#defi... | cpp |
1292 | D | D. Chaotic V.time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputÆsir - CHAOS Æsir - V."Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time."The emotion samples are now suffici... | [
"dp",
"graphs",
"greedy",
"math",
"number theory",
"trees"
] | // #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 |
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;
struct edge{
int to,cap;
int cst;
int rev;
};
vector<edge>g[53];
void add_edge(int x,int y,int cap,int cst){
g[x].push_back((edge){y,cap,cst,g[y].size()});
g[y].push_back((edge){x,0,-cst,g[x].size()-1});
}
int prevv[53],preve[53];
int dist[53];
int min_co... | 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 all(x) x.begin(),x.end()
const int INF=1e9;
struct edge{
int to,idx,val,id;
edge(){}
edge(int a,int b,int c,int d){
to=a,idx=b,val=c,id=d;
}
};
struct qry{
int a,b,c;
qry(){}
qry(int a1,int b1,int c1){a=a1,b=b1,c=c1;}... | cpp |
1292 | D | D. Chaotic V.time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputÆsir - CHAOS Æsir - V."Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time."The emotion samples are now suffici... | [
"dp",
"graphs",
"greedy",
"math",
"number theory",
"trees"
] | //#pragma GCC optimize(3)
#include<iostream>
#include<climits>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<complex>
#include<random>
#include<chrono>
#define int long long
//#define double lo... | cpp |
1311 | F | F. Moving Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn points on a coordinate axis OXOX. The ii-th point is located at the integer point xixi and has a speed vivi. It is guaranteed that no two points occupy the same coordinate. All nn points mo... | [
"data structures",
"divide and conquer",
"implementation",
"sortings"
] | #include <bits/stdc++.h>
using namespace std;
template<typename T>
struct fenwick{
int N;
vector<T> sums;
fenwick(int _N){
N = _N + 5;
sums.resize(N, 0);
}
T query(int i){
T res = 0;
for(; i; i -= i & (-i)) res += sums[i];
return res;
}
... | cpp |
1286 | A | A. Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVadim loves decorating the Christmas tree; so he got a beautiful garland as a present. It consists of nn light bulbs in a single row. Each bulb has a number from 11 to nn (in arbitrary order), such that all th... | [
"dp",
"greedy",
"sortings"
] | // ඞ
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include "debug.h"
#define dbg(...) debug_out(splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...)
#endif
#defin... | cpp |
1299 | A | A. Anu Has a Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnu has created her own function ff: f(x,y)=(x|y)−yf(x,y)=(x|y)−y where || denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9f(11,6)=(11|6)−6=15−6=9. It can be proved that for an... | [
"brute force",
"greedy",
"math"
] | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[100010];
int main(){
ll n,i,j,c,k,t;
cin>>n;
for(i=1;i<=n;i++) cin>>a[i];
for(j=30;j>=0;j--){
c=0;
for(i=1;i<=n;i++)
if((a[i]>>j)&1)c++,k=i;
if(c==1)break;
}
if(c==1) swap(a[1],a[k]);
for(i=1;i<=n;i++) cout<<a[i]<<" ";
} | cpp |
1301 | C | C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu... | [
"binary search",
"combinatorics",
"greedy",
"math",
"strings"
] | #include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 1010;
void solve(){
int n , m;
scanf("%d%d",&n,&m);
long long ans = (long long)n * (long long)(n + 1) / 2LL;
int z = n - m;
int k = z / (m + 1);
ans -= (long long)(m + 1) * (long long)k * (long ... | 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"
] | // LUOGU_RID: 102289206
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
vector<int> G[maxn];
int T;
int fa[maxn], dep[maxn];
vector<int> ans;
class Node {
public:
int u, dep;
Node() = default;
Node(int u, int dep) : u(u), dep(dep) {}
const bool operator<(c... | cpp |
1296 | E2 | E2. String Coloring (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a hard version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format a... | [
"data structures",
"dp"
] | /// What are you doing now? Just go f*cking code now dude?
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define TASK "codin"
//#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0... | 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>
using namespace std;
set<int> kit;
int main(){
int t;
cin>>t;
int n,s,k;
while(t--){
cin>>n>>s>>k;
kit.clear();
int x;
for(int i=1;i<=k;i++){
cin>>x;
kit.insert(x);
}
int minx=1e9;
for(int i=max(1,s-1005);i<=min(n,s+1005);i++){
if(!kit.count(i)) minx=min(minx,abs(i-s));
}
cout<<minx<<endl;
}
} | cpp |
1290 | F | F. Making Shapestime limit per test5 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputYou are given nn pairwise non-collinear two-dimensional vectors. You can make shapes in the two-dimensional plane with these vectors in the following fashion: Start at the origin (0,0)(0,0). Choose a ve... | [
"dp"
] | #ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
#else
#include "headers.h"
#endif
namespace IO {
std::ostream& fmtbase(std::ostream& out, const char* format) {
for (; *format; format++) {
if (*format == '{' && *(format + 1) == '}') {
throw std::invalid_argument("Error Number of Parameters!");
}
... | 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>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define W while
#define I inline
#define RI int
#define LL long long
#define Cn const
#define CI Cn int&
#define gc getchar
#define D isdigit(c=gc())
#define pc(c) putchar((c))
using namespace std;
name... | 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"
] | ///
/// ♪ Hashire sori yo ♪
/// ♪ Kaze no you ni ♪
/// ♪ Tsukimihara wo ♪
/// ♪ PADORU PADORU ♪
///
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::... | 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 lll pair<long,pair<long,long>>
#define ll pair<long,long>
#define st first
#define nd second
const long N=5e3+10;
long n,x,y,ans[N],D[N],H[N],C[N][N],m,cnt;
vector<long> ds[N];
lll Q[N];
void DFS(long a,long p){
for(long v: ds[a]){
if(v!=... | cpp |
1311 | F | F. Moving Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn points on a coordinate axis OXOX. The ii-th point is located at the integer point xixi and has a speed vivi. It is guaranteed that no two points occupy the same coordinate. All nn points mo... | [
"data structures",
"divide and conquer",
"implementation",
"sortings"
] | #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 |
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 <cstdio>
#include <iostream>
#include <queue>
using namespace std;
const int M = 1005;
const int inf = 0x3f3f3f3f;
int read()
{
int x=0,f=1;char c;
while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
return x*f;
}
int n1,n2,m,R,B,s1,t1,S,T,d[M];ch... | 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;
using pii=pair<int,int>;
using ll=long long;
const int N=5e3+10,logn=15;
pii f[logn+1][N<<1];
int dep[N],tot,first_pos[N];
vector<int>e[N];
int g[N][N];
int par[N];
void dfs(int u,int fa)
{
first_pos[u]=++tot;
dep[u]=dep[fa]+1;
f[0][tot]={dep[u],u... | 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;
string a,b,c;
int t;
int main()
{
cin >> t;
while(t--){
cin >> a;
cin >> b;
cin >> c;
bool f = true;
for(int i=0; i<a.size(); ++i){
if(c[i] != a[i] && c[i] != b[i]){
f = false;... | cpp |
1304 | C | C. Air Conditionertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong owns a bulgogi restaurant. The restaurant has a lot of customers; so many of them like to make a reservation before visiting it.Gildong tries so hard to satisfy the customers that he even memor... | [
"dp",
"greedy",
"implementation",
"sortings",
"two pointers"
] | /***********
MK-1311
***********/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define nl '\n'
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
/*
*/
#define int long long
void solve() {
int n, it;
cin... | cpp |
1296 | E2 | E2. String Coloring (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a hard version of the problem. The actual problems are different; but the easy version is almost a subtask of the hard version. Note that the constraints and the output format a... | [
"data structures",
"dp"
] | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
#define pb push_back... | cpp |
1301 | C | C. Ayoub's functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyoub thinks that he is a very smart person; so he created a function f(s)f(s), where ss is a binary string (a string which contains only symbols "0" and "1"). The function f(s)f(s) is equal to the nu... | [
"binary search",
"combinatorics",
"greedy",
"math",
"strings"
] | #include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=998244353;;
long long mod(long long x){
return ((x%M + M)%M);
}
long long add(long long a, long long b){
return mod(mod(a)+mod(b));
}
long long mul(long lon... | cpp |
1322 | E | E. Median Mountain Rangetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputBerland — is a huge country with diverse geography. One of the most famous natural attractions of Berland is the "Median mountain range". This mountain range is nn mountain peaks, located on one... | [
"data structures"
] | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
const int N = 5e5 + 55, LN = 20;
template <typename comp>
struct ST {
inline static int lg2(int n) { return 31 - __builtin_clz(n); }
inline static int _(int x, int y) { return comp()(x, y) ? x : y; }
int st[LN][N];
void init... | cpp |
1141 | F2 | F2. Same Sum Blocks (Hard)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is given in two editions; which differ exclusively in the constraints on the number nn.You are given an array of integers a[1],a[2],…,a[n].a[1],a[2],…,a[n]. A block is a sequence ... | [
"data structures",
"greedy"
] | // LUOGU_RID: 101967713
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::vector<int> s(n + 1);
for (int i = 0; i < n; i++) {
s[i + ... | cpp |
1316 | F | F. Battalion Strengthtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn officers in the Army of Byteland. Each officer has some power associated with him. The power of the ii-th officer is denoted by pipi. As the war is fast approaching, the General would ... | [
"data structures",
"divide and conquer",
"probabilities"
] | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <queue>
#include <cstring>
#include <set>
#include <bitset>
#include <map>
#include <chrono>
#include <random>
#include <unordered_map>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef long do... | 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 REP(i,n) for(int i = 0; i< (n);i++)
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define SZ(a) (int)a.size()
#define bit(x,i)(((x)>>(i))&1)
typedef long long ll;
using namespace std;
// Graph problem
void solve(){
string s, t; cin >> s >> t;
int n1 = SZ(... | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.