Handles | A | B | C | D | E | F1 | F2 |
---|---|---|---|---|---|---|---|
Proof_by_QED | 800 | 1000 | 1500 | 2200 | 2400 | 1800 | 2600 |
chromate00 | 800 | 1100 | 1500 | 2100 | 2300 | 1800 | 2700 |
redpanda | 800 | 900 | 1400 | 2000 | 2400 | ||
larush | 800 | 1100 | 1600 | 2100 | |||
FairyWinx | 800 | 900 | 1500 | 2000 | 2400 | 1800 | 2500 |
priyanshu.p | 800 | 1200 | 1500 | 2000 | 2500 | 2000 | |
Intellegent | 800 | 1000 | 1400 | 2000 | 2200 | 2000 | 2600 |
redheadphone | 800 | 1200 | 1400 | 2000 | |||
hashman | 800 | 1100 | 1500 | 2100 | 2100 | 2000 | 2500 |
Mukundan314 | 800 | 1000 | 1600 | 2000 | 2300 | 1900 | 2400 |
Yugandhar_Master | 800 | 1000 | 1500 | 1900 | 2200 | 1900 | 2400 |
b00s | 800 | 1100 | 1500 | 2000 | 2300 | ||
-firefly- | 800 | 1100 | 1500 | 1900 | 2400 | 1800 | 2500 |
temporary1 | 800 | 1000 | 1500 | 2100 | 2300 | 2000 | 2600 |
cry | 800 | 1200 | 1400 | 2100 | 2300 | ||
Average | 800 | 1060 | 1486.67 | 2033.33 | 2315.38 | 1900 | 2533.33 |
Average (Round) | 800 | 1100 | 1500 | 2000 | 2300 | 1900 | 2500 |
Median | 800 | 1100 | 1500 | 2000 | 2300 | 1900 | 2500 |
The editorial for each task is written by me, chromate00. I tried to explain each task with as much detail I could fit in. Brace yourselves, it is going to be LONG. Please don't try to open all spoilers at once, it lagged my browser. Also, I apologize for not telling you strongly enough to read every problem, almost every tester thought F1 is easy if you read it well...
Also, our fellow wuhudsm told me there will be another community contest in the Gym soon, details will be posted on https://codeforces.me/blog/entry/138706 shortly :catThink:
UPD: Added solution codes to all solutions.
2063A - Minimal Coprime
Author: chromate00
Well, we gave you enough hints in the examples. I believe you can already guess it.
for i in range(int(input())):
x,y=map(int,input().split())
if x==y==1:
print(1)
else:
print(y-x)
2063B - Subsequence Update
Author: Yugandhar_Master
Assume that you chose some two indices $$$i$$$ and $$$j$$$ included in the subsequence, such that $$$i<l$$$ and $$$j>r$$$. Does this actually help decrease the answer in any way?
import sys
input=lambda:sys.stdin.readline().rstrip()
for _ in range(int(input())):
n,l,r=map(int,input().split());l-=1
arr=[*map(int,input().split())]
brr=arr[:l]+sorted(arr[l:])
crr=sorted(arr[:r])[::-1]+arr[r:]
print(min(sum(brr[l:r]),sum(crr[l:r])))
2063C - Remove Exactly Two
Author: chromate00
The answer after choosing two vertices is decided by the degrees of the two vertices, and whether the two vertices are adjacent. Can you find a clean solution where you don't have to care about the latter?
Sure, you can do DP on tree, but that's not what we want you to use. Think easier.
import sys
input=lambda:sys.stdin.readline().rstrip()
for i in range(int(input())):
n=int(input())
deg=[0]*n
adj=[[] for i in range(n)]
for i in range(n-1):
u,v=map(int,input().split())
u-=1;v-=1
deg[u]+=1
deg[v]+=1
adj[u].append(v)
adj[v].append(u)
ans=1
mans=0
sdeg=sorted(deg)
for i in range(n):
ans=deg[i]
ideg=[]
for v in adj[i]:
ideg.append(deg[v])
ideg.append(deg[i])
ideg.sort(reverse=True)
rem=[]
mx=-1
for d in ideg:
if sdeg[-1]==d:
sdeg.pop()
rem.append(d)
rem.reverse()
if sdeg:
mx=max(mx,sdeg[-1])
for v in adj[i]:
mx=max(mx,deg[v]-1)
for d in rem:
sdeg.append(d)
mans=max(ans+mx-1,mans)
print(mans)
2063D - Game With Triangles
Author: wuhudsm (Original Idea) & chromate00 (Modified Idea)
The maximum score $$$g(x_a,x_b)$$$ after performing $$$x_a$$$ times with two points on $$$y=0$$$, and $$$x_b$$$ times with two points on $$$y=2$$$, can be easily computed in $$$\mathcal{O}(1)$$$ time. But naively checking all possible number of operations takes $$$\mathcal{O}(nm)$$$ time. Is there a property we can abuse so that we can solve for each $$$k$$$ faster?
$$$g(x_a,x_b)$$$ is a function consisting of two prefix sums, each for a strictly decreasing sequence.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int t;cin>>t;
while(t--)
{
int n,m;cin>>n>>m;
vector<ll>arr(n),brr(m);
for(ll&i:arr)cin>>i;
for(ll&i:brr)cin>>i;
sort(begin(arr),end(arr));
sort(begin(brr),end(brr));
vector<ll>asum(n+2),bsum(m+2);
for(int i=1;i<=n;i++)asum[i]=asum[i-1]+(arr[n-i]-arr[i-1]);
for(int i=1;i<=m;i++)bsum[i]=bsum[i-1]+(brr[m-i]-brr[i-1]);
vector<ll>ans{0};
// maximize asum[ka]+bsum[kb]
// s.t. ka+kb = x
// ka*2+kb <= n -> ka*2+(x-ka) <= n -> ka+x <= n -> ka <= n-x
// ka+kb*2 <= m -> ka+2*(x-ka) <= m -> 2*x-ka <= m -> ka >= 2*x-m
// ka >= 0, x-ka >= 0
for(int x=1;2*x-m<=n-x;x++)
{
ll L=max(0,2*x-m),R=min(x,n-x);
if(L>R)break;
auto f=[&](int ka){return asum[ka]+bsum[x-ka];};
while(R-L>3)
{
ll mL=(L*2+R)/3,mR=(L+R*2)/3;
if(f(mL)>f(mR))R=mR;
else L=mL;
}
ll mans=0;
for(int i=L;i<=R;i++)
{
mans=max(mans,f(i));
}
ans.push_back(mans);
}
int kmax=(int)size(ans)-1;
cout<<kmax<<"\n";
for(int i=1;i<=kmax;i++)cout<<ans[i]<<" \n"[i==kmax];
}
}
2063E - Triangle Tree
Author: Yugandhar_Master
When $$$(u,v)$$$ is a good pair, $$$f(u,v)$$$ is actually simply represented as follows.
Naively calculating this for all good pairs takes $$$\mathcal{O}(n^2)$$$ time. Can you find a different representation where we can count wiser?
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int t;cin>>t;
while(t--)
{
ll n;cin>>n;
vector<ll>d(n,0),s(n),dc(n),dcs;
vector<vector<ll>>adj(n);
for(int i=1;i<n;i++)
{
int u,v;cin>>u>>v;
u--;v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
auto dfs1=[&](auto dfs1,int v,int p=-1)->void
{
dc[d[v]]++;
ll sz=1;
for(int w:adj[v])if(w!=p)
{
d[w]=d[v]+1;
dfs1(dfs1,w,v);
sz+=s[w];
}
s[v]=sz;
};
dfs1(dfs1,0);
dcs=dc;
for(int i=n-2;i>=0;i--)dcs[i]+=dcs[i+1];
ll ans=0,ans2=0;
auto dfs2=[&](auto dfs2,int v,int p=-1)->void
{
// v is min
ans+=2*d[v]*(dcs[d[v]]-s[v]);
// v is lca
ll subcnt=s[v]-1,lcnt=0;
for(int w:adj[v])if(w!=p)
{
lcnt+=(subcnt-s[w])*s[w];
dfs2(dfs2,w,v);
}
ans2+=(2*d[v]+1)*(lcnt/2);
};
dfs2(dfs2,0);
for(int i=0;i<n;i++)
{
ans2+=i*dc[i]*(dc[i]-1);
}
cout<<ans-ans2<<"\n";
}
}
2063F1 - Counting Is Not Fun (Easy Version)
Author: chromate00
The subproblem where you find the number of different balanced bracket sequences of length $$$2k$$$ is already well-known.
Now recall everyone's favorite data structure to solve problems related to balanced bracket sequences — the stack!
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll md=998244353;
int main()
{
int t;cin>>t;
vector<ll>ctl(5050);
ctl[0]=1;
for(int n=1;n<5050;n++)
{
for(int i=1;i<=n;i++)
{
ctl[n]=(ctl[n]+ctl[i-1]*ctl[n-i]%md)%md;
}
}
while(t--)
{
int n;cin>>n;
ll ans=ctl[n];
cout<<ans<<" ";
string s(2*n+2,'.');
s[0]='(';s[2*n+1]=')';
for(int a=0;a<n;a++)
{
int i,j;cin>>i>>j;
ans=1;
s[i]='(';
s[j]=')';
string stk;
for(char c:s)
{
if(c==')')
{
int cnt=0;
while(stk.back()!='(')
{
cnt++;
stk.pop_back();
}
stk.pop_back();
ans=(ans*ctl[cnt/2])%md;
}
else stk+=c;
}
cout<<ans<<" \n"[a+1==n];
}
}
}
2063F2 - Counting Is Not Fun (Hard Version)
Author: chromate00
In the solution of the easy subtask, we manually enumerated the minimal balanced subsequences, each time in $$$\mathcal{O}(n)$$$.
You can show that most minimal balanced subsequences do not change when a new clue is added. What data structure will you choose in order to utilize this fact as much as possible?
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll nil=-1;
const ll md=998244353;
ll pw(ll a,ll b)
{
ll c=1;
while(b>0)
{
if(b&1)c=c*a%md;
a=a*a%md;
b>>=1;
}
return c;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
vector<ll>fac(1010101,1),ctl(505050);
for(int i=1;i<1010101;i++)fac[i]=fac[i-1]*i%md;
for(int i=0;i<505050;i++)
{
ctl[i]=fac[i*2]*pw(fac[i]*fac[i+1]%md,md-2)%md;
}
ll t;cin>>t;
while(t--)
{
ll n;cin>>n;
vector<ll>L(n*2,nil),R(n*2,nil),P(n*2,nil),S(n*2);
auto update=[&](ll x)
{
S[x]=1;
if(L[x]!=nil)S[x]+=S[L[x]];
if(R[x]!=nil)S[x]+=S[R[x]];
};
auto rotate=[&](ll x)
{
ll dummy;
ll p=P[x];
ll b=nil;
if(p==nil)return;
if(x==L[p])
{
L[p]=b=R[x];
R[x]=p;
}
else
{
R[p]=b=L[x];
L[x]=p;
}
P[x]=P[p];P[p]=x;
if(b!=nil)P[b]=p;
(P[x]!=nil?p==L[P[x]]?L[P[x]]:R[P[x]]:dummy)=x;
update(p);update(x);
};
auto splay=[&](ll x)
{
while(P[x]!=nil)
{
ll p=P[x];
ll g=P[p];
if(g!=nil)
{
if((x==L[p])==(p==L[g]))rotate(p);
else rotate(x);
}
rotate(x);
}
};
update(0);
for(int i=1;i<n*2;i++)
{
L[i]=i-1;
P[i-1]=i;
update(i);
}
splay(0);
ll ans=ctl[n];
cout<<ans<<" ";
for(int i=0;i<n;i++)
{
ll li,ri;cin>>li>>ri;
//li=(li+ans%(2*n))%(2*n);
//ri=(ri+ans%(2*n))%(2*n);
li--;ri--;
splay(li);
ans=ans*pw(ctl[S[li]/2],md-2)%md;
ll lli=L[li];
if(L[li]!=nil)P[L[li]]=nil;
if(R[li]!=nil)P[R[li]]=nil;
L[li]=nil;
R[li]=nil;
update(li);
// now L[li] separated from tree
// should not be affected in splay ri
splay(ri);
ll lri=L[ri];
ll rri=R[ri];
if(L[ri]!=nil)P[L[ri]]=nil;
if(R[ri]!=nil)P[R[ri]]=nil;
L[ri]=nil;
R[ri]=nil;
update(ri);
if(lri!=nil)
{
splay(lri);
ans=ans*ctl[S[lri]/2]%md;
}
if(lli!=nil&&rri!=nil)
{
while(L[rri]!=nil)rri=L[rri];
splay(lli);
splay(rri);
P[lli]=rri;
L[rri]=lli;
update(rri);
ans=ans*ctl[S[rri]/2]%md;
}
else if(lli!=nil||rri!=nil)
{
if(lli!=nil)
{
splay(lli);
ans=ans*ctl[S[lli]/2]%md;
}
else
{
splay(rri);
ans=ans*ctl[S[rri]/2]%md;
}
}
L[ri]=li;
P[li]=ri;
update(ri);
// make dummy tree (for invariant maintaining)
cout<<ans<<" \n"[i+1==n];
}
}
}
UPD: People pointed out that the intended solution in the tutorial is overkill. Yes, I acknowledge this. Please look into the newly added alternative solution if you want a more elegant idea.
Consider maintaining the MBSes directly, but instead of using a complex data structure, we will use a small-to-large trick with linked lists. Precisely, every time we have to split a linked list, we will identify the smaller section and split it out in $$$\mathcal{O}(|small|)$$$ time, and then the amortized time complexity will be $$$\mathcal{O}(n \log n)$$$. In this solution, we do not consider bracket pairs as MBSes, for a specific reason.
Given a linked list of indices and two nodes on it, we can identify the smaller section in $$$\mathcal{O}(|small|)$$$ by iterating over both lists at the same time, interlacing the operations. The list which hit the end earlier will be the smaller one, and then we immediately know the value of $$$|small|$$$.
The issue is that you cannot identify the size of both lists in $$$\mathcal{O}(|small|)$$$ time. This is hard to fix using only a linked list. Instead, we will also maintain the implicit rooted tree structure of the bracket sequence. The MBSes correspond to vertices, and the bracket pairs correspond to edges. Initially, the tree just consists of one vertex of $$$2n$$$ brackets.
Now, for each list node, we add a pointer to the corresponding tree vertex. Now we can know which tree vertex the list node corresponds to immediately, and if we bookkeep size informations in the tree vertices, we can also find the sum of two list sizes in $$$\mathcal{O}(1)$$$. Therefore we can now know the size of both lists in $$$\mathcal{O}(|small|)$$$ time.
The only issue is with how to maintain the pointers to the tree vertices. But no problem, you can just do the small-to-large for this also. After splitting the tree vertex into two vertices and one edge, redirect the smaller list to the new smaller vertex. Theoretically there are enough ways to do this, such as swapping vertex indices. Also it is notable that it is not necessary to maintain the whole tree in this process, it is quite sufficient to just maintain it implicitly by just maintaining a sequence of sizes.
The problem is solved online with $$$\mathcal{O}(n \log n)$$$ amortized time complexity.
#pragma GCC optimize("O3,unroll-loops")
#include <iostream>
#include <numeric>
#include <vector>
constexpr int MAX_N = 3e5;
constexpr long long MOD = 998244353;
struct _inv_small {
long long data[MAX_N + 2] = {0};
constexpr _inv_small() {
data[1] = 1;
for (int i = 2; i <= MAX_N; i += 2) {
data[i] = MOD - (MOD / i) * data[MOD % i] % MOD;
data[i + 1] = MOD - (MOD / (i + 1)) * data[MOD % (i + 1)] % MOD;
}
}
};
constexpr _inv_small __inv_small;
#define inv_small(x) __inv_small.data[x]
#define inv(x) (x < MAX_N ? inv_small(x) : data[(x) - MAX_N])
struct _inv {
long long data[MAX_N + 3] = {0};
constexpr _inv() {
for (int i = 0; i <= MAX_N + 1; i += 2) {
data[i] = MOD - (MOD / (i + MAX_N)) * inv(MOD % (i + MAX_N)) % MOD;
data[i + 1] = MOD - (MOD / (i + MAX_N + 1)) * inv(MOD % (i + MAX_N + 1)) % MOD;
}
}
};
#undef inv
constexpr _inv __inv;
#define inv(x) (x < MAX_N ? inv_small(x) : __inv.data[(x) - MAX_N])
struct _catalan {
long long data[MAX_N + 2] = {1};
constexpr _catalan() {
for (int i = 1; i <= MAX_N; i += 2) {
data[i] = (4 * i - 2) * data[i - 1] % MOD * inv(i + 1) % MOD;
data[i + 1] = (4 * i + 2) * data[i] % MOD * inv(i + 2) % MOD;
}
}
};
constexpr _catalan __catalan;
#define catalan(x) __catalan.data[x]
struct _catalan_inv {
long long data[MAX_N + 2] = {1};
constexpr _catalan_inv() {
for (int i = 1; i <= MAX_N; i += 2) {
data[i] = inv(2) * inv(2 * i - 1) % MOD * data[i - 1] % MOD * (i + 1) % MOD;
data[i + 1] = inv(2) * inv(2 * i + 1) % MOD * data[i] % MOD * (i + 2) % MOD;
}
}
};
constexpr _catalan_inv __catalan_inv;
#define catalan_inv(x) __catalan_inv.data[x]
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int t;
std::cin >> t;
for (int _ = 0; _ < t; ++_) {
int n;
std::cin >> n;
std::vector<bool> used(2 * n + 2);
std::vector<int> point(2 * n + 2);
std::iota(point.begin(), point.end(), 1);
std::vector<int> size(2 * n + 2);
std::vector<int> parent = {0};
std::vector<int> parent_idx(2 * n + 2);
used[0] = true;
point[0] = 2 * n + 2, point[2 * n + 1] = 2 * n + 1;
size[0] = 2 * n;
long long ans = catalan(n);
std::cout << ans << " ";
for (int i = 0, l, r; i < n; ++i) {
std::cin >> l >> r;
point[l] = r + 1, point[r] = r;
used[l] = true;
int p = parent[parent_idx[l]];
int out_ptr = p + 1, ins_ptr = l + 1;
int out_size = 0, ins_size = 0;
while (point[out_ptr] != out_ptr && point[ins_ptr] != ins_ptr) {
out_size += !used[out_ptr];
ins_size += !used[ins_ptr];
out_ptr = point[out_ptr];
ins_ptr = point[ins_ptr];
}
ans = (ans * catalan_inv(size[p] / 2)) % MOD;
int upd_ptr;
if (point[out_ptr] == out_ptr) {
upd_ptr = p + 1;
parent.push_back(p);
parent[parent_idx[l]] = l;
ins_size = size[p] - 2 - out_size;
size[p] = out_size, size[l] = ins_size;
} else {
upd_ptr = l + 1;
parent.push_back(l);
out_size = size[p] - 2 - ins_size;
size[p] = out_size, size[l] = ins_size;
}
ans = (ans * catalan(size[p] / 2)) % MOD * catalan(size[l] / 2) % MOD;
while (point[upd_ptr] != upd_ptr) {
parent_idx[upd_ptr] = parent.size() - 1;
upd_ptr = point[upd_ptr];
}
std::cout << ans << " ";
}
std::cout << '\n';
}
}
Lightning fast! But I think your problems are not good enough for this historic round.
Why do you believe this?
I explained my reasons in the comments above: everyone has high expectations for this game, But I think although there were no serious issues in this contest, the problem setter did not do anything very well. So lots of people (including me) doesn't like it.
Maybe 1024th round is more historic for a programmer.
You are right, but this is historic too! (Wish CodeForces can hold a better contest in the 1024th round!)
Great blog!
Because many people think Round $$$10^3$$$ should be made of awesome problems as an historic round. Clearly the problems aren't good enough.
Deeply sorry if you thought the tasks weren't awesome, I think we have different thoughts. I think most tasks were great.
Well, you promised something epic, that might not be in a "normal div2 round".
No hate, but imho normal div2 rounds usually have more interesting problems on positions A-D.
Problem E's intended solution is really nice, but why did noone spot that it can be killed with normal small-to-large? To me E was also "read and immediately know how to solve"
You managed to make interesting problem F, but intended solution using splay trees is also not in the list of epic things to me :/
I did notice that E can be killed with small-to-large. I thought that the problem still is worth it, but it wasn't a surprise that it is "killed". I was thinking that depth-wise small to large is not a common topic for Div. 2.
F has A LOT of solutions. Please don't be discouraged, any solution that works is a great solution for it.
I think my E just used common small to large which i implemented in at least 5 other cf problems back from the times when I was div2, though it's not the point
Yeah, problem is still worth it, I'd be very happy to see such in div2 2 years ago when I was CM (as it was my fav trick then), but I'm speaking from a div1 perspective (perhaps, even if we're not rated auditory, we're still looking forward to 1000th round)
For problem F you're right, just was discouraged after looking for a nice way to find the "outter" bracket pair for the last 20 minutes of the contest, and then seeing that in editorial...
There are much cleaner ideas for F2.
My solution was to maintain a segtree initially of all 0, then each time a bracket pair is added, you update each value in the interval by 1.
Then, the left bound of the interval you are contained in is simply the first element to the left of your position that has a smaller value.
Yep, that's exactly what i thought of in the contest! Just didn't manage to finish it, as i had roughly 2 minutes left when i was done with that segment tree xD
Thanks for explaining!
Log squared?
log
Could someone explain this (submission) for F2 please. It looks very elegant but I'm struggling to understand that backwards pairs processing.
Also i have solution only with linked list and small-to-large
If you don't mind, can you please explain your solution?
O_o
Could you share the submission please?) This sounds very cool
Added to the editorial. Sorry for adding this a bit late, it took me some time to understand this. It is indeed very cool
We must divide the length of the smaller part into 2 parts.
but we don't need to maintain the sizes, we can iterate over both parts at the same time.
But it hard to implementation)))
I wrote a small-to-large independently after FairyWinx solved it with small-to-large (I believe the core idea was the same), submission: https://codeforces.me/contest/2063/submission/302551553 (ignore the compile time catalan)
thanks!
Hi, can you describe how are you calculating the answer using Problem's E small to large. I tried to keep an prefix sum array of frequency of depths, or something similar, but I don't know how I would keep it updated in the small to large.
Hi!
I store arrays of frequency of depths, but with a trick:
cnt[u][cnt[u].size() — k] = number of vertices in its subtree on the depth (k-1).
Respectively, when we merge two children, say U and V, we iterate over this array for smaller one, say V is smaller:
Could you explain the formula: tot*cnt[v][dv-i]*(2*i-1)? I don't get how we know that we get a nondegenerate triangles from this if we have set only one length
I realised I was stupid cuz if you have a b sides and we dont know l you have b-a<l<a+b and if you do a+b-b+a+1-2 you get 2*a-1,bruuh
yes, exactly. The code fixes the smallest (out of the two) length and calculates the desired value.
here u have , swapped by comparsion of dp[node].size(), but here dp[node] store information of all vertices at node subtree , on various depths thus , dp[node].size() indirectly gives node subtree depth , so how does time complexity is still NlogN ? By comparison of node subtree size , would have surely mainitned this time complexity
Please refer to this blogpost by ntherner.
Yeah I wonder why they don't like speed forces for abc and bullshit geometry and greedy+ bullshit implementation for d, and an E which is just standard problem where u added also bullshit geometry to make it Cool but all u did was make a standard problem worse
Even for a normal div2, this would've been a shitty contest, let alone round 1000
cope
the inclusion of "triangle" doesn't make a problem geometry. D and E has absolutely nothing to do with geometry unless you have not encountered the triangle inequality or area of a triangle formula, which you hopefully would've learned in middle school.
I get ur point, I honestly get it, they aren't geometry problem, they're geometry knowledge is at elementary school level, the point is when u use geometry terms, the problems automatically get shit, I promise if the problem didn't include anything about geometry, mainly using words that are Abt geometry, the problems were probably way more liked and better, also the last div2 b this holds, if the question was find a 4 element tuple with 2 equal elements such that the other two's absolute difference is less than 2*x, the problem would have had a lot more solves a lot faster, by using geometry words and phrases, u just make the problems more annoying, not better
Actually, the problems are more motivated and intuitive if triangles are included, rather than a pure mathematical statement. Unless, of course, you can’t visualize a triangle.
definetely not in the people I know
Personally I thought the problems were all great, didn't get all of them but the main idea for CDE required some clever insights and were interesting to me. I also like that F was actually doable for div 2 contestants.
I thoroughly enjoyed the problems. This might be my favorite round ever.
I leave contest just as soon as I read problem C and you say they were good? Or me just not enjoy chromate00 / cry rounds
isn't it a good thing if you were able to read problem C when your average solve count is $$$1$$$
if it's 1 then it's probably C
I know dogshit about how to solve A i just implemented according to testcases
+++++
Both A and B were copy from test case and it passes lol. I didn't even read the whole problem just test case should pass XD
on B selecting just the minimum $$$r-l+1$$$ and printing the sum passed sample (I apologize for that, oh well)
I got penalty 2 times for that ;/
$$$>=-7$$$ because I solved 2 poorly authored problems. Interesting.
Noice Problem set. Especially C
A was easy but B's pretest 2 destroyed me! I was absolutely shocked why it didn't work.
My approach was sorting the array and then outputting the sum of [1, (r — l) + 1] and I thought that's what is going to be the minimum but unfortunately, it failed on pretest 2 or I think I was also gonna solve C.
Play with the maximum values in the [L,R] with the minimum values of both the subarrays to left and to right of [L,R]
Hey I didn't understand the intution behind it. Can u please explain why it works?
the values at the range[l,r] will be swaped with values in the range[1,l-1] or range[r+1,n].you can't take from both sides
The subsequence you have selected either contains $$$[1,l)$$$ or $$$(r,n]$$$, simple sorting can result in mixing together.
obviously 1 2 2 1 is not going to work when l,r=2,3
thanks for explaining this But I'm curious to know why 1 2 2 1 testcase is used by many people to counter the newbie logic. Like why everyone thought of that as their first thought as a counter? I've seen 3 people use it already.
Suppose you have the following input
Your approach would yield $$$1+1=2$$$, but this is not correct. You can't get to swap both $$$2$$$s with both $$$1$$$s. You wish to swap costly items in $$$a[l:r+1]$$$ with cheaper items.
You can only - swap with elements left from the segment $$$[l,r]$$$, or - swap with elements right from the segment $$$[l,r]$$$.
You can iterate over $$$i$$$ and try to swap the $$$i$$$ most costly elements from $$$[l,r]$$$ with the $$$i$$$ least costly elements from $$$[r+1,n]$$$, or from $$$[1,l-1]$$$.
I give you a easier Approach Just see my solution https://codeforces.me/contest/2063/submission/302470981
Thanks!! Very helpful
Great set of problems ! Clear description, nice test cases, no mistake ... Kuddos to all organizers. I will enjoy taking more time to solve D and E.
I have been stuck on C, but I don't understand why my submission got WA : 302435615. Could someone give me a hint ?
Consider this test:
Your code outputs $$$4$$$, the correct answer is $$$5$$$.
My logic is correct, but my code is wrong. Because I modify the unordered_set I'm iterating on, the loop stops after the first iteration. I wasn't aware of this behavior ...
can you tell me why my code fails
WA :302491912(https://codeforces.me/contest/2063/submission/302491912)
You are identifying the three highest degree nodes. It is not enough to find the best nodes. You can always think of an example where three highest degree nodes are connected, and a fourth with same degree is somewhere else in the tree. You should remove it, and one of the three, but by only searching for three nodes you might miss it.
Can anyone help explain how my answer is wrong, I'm just searching for highest degree node, removing it, then finding the highest degree node again: 302462038
edit: I didn’t realize they can give the edges not in order, sorted levels then did same algo and ac
Consider this test:
Your code outputs $$$4$$$, the correct answer is $$$5$$$.
I ran it locally and got 5
Your code seems to go to an infinite loop in 'Custom invocation' section. o.O
I followed a similar approach but my code is a bit different, the testcase that you gave passes on my code, can you maybe provide a TC where my code is failing?
My code
https://codeforces.me/blog/entry/138593?#comment-1240057
I think for me it involves that you should search for the deepest node with 2 children, like for example: 7 1 2 2 3 2 4 1 5 5 6 5 7 Kind of silly, this was my initial observation I just forgot
I also realized I literally typed this in a comment in my code just didn’t make > -> >=
counter test case:
nodes = 5 & edges: 2 1, 1 4, 4 3, 3 5,
My algorithm worked the entire time, I just didn't realize the edges could be given out of order. All I had to do was sort levels accordingly and it AC.
I did terrible on this contest
On B, I took 2 subs to realize that I was checking [1,l+1] instead of [1,l].
I will get negative on this round
your name is a bigger concern than your performance
dont mind about that lol
I will change it next year
Wow my prediction was correct
I got -38
code for problem C
https://codeforces.me/contest/2063/submission/302448973
can anyone point out why it failed on test 4?
Consider this case at this comment
the test you are referring to isn't relevant to why my submission fails. thanks anyway
Can someone explain why I am getting WA: on my submission 302454358 in problem C. I am doing brute force. I am first greedily picking the first vertice and then removing it after picking second vertice.
Check this case
mine was passing on this as well don't know why it failed
I guess the key thing was that the node with largest indegree and decrease the indegree by 1 for each neighbour and then found largest indegree overall and we are done
Consider that if you remove a vertex $$$v$$$ with maximum degree $$$d$$$ that contains at least two childs with degree $$$d$$$, you will get rid of the possibility to split the tree to $$$2\cdot d - 1$$$.
Because if you remove $$$v$$$, you will get $$$d$$$ components, but your maximum degree will decrease to $$$d-1$$$. If you remove one of the childs of $$$v$$$ with degree $$$d$$$, you maintain the maximum degree as $$$d$$$.
can you give an example ?
example: 1-2-3-4-5 Vertex 3 cannot be erased.
but it would still result same no
see what i am doing is taking maxi indegree first and then after subtraction of 1 again maxdegree 2 and subtract 1 from both of them i tried your case but it fails as well
see this is the submission if you could provide a tc where it fails
my submission
So hard:(
E much simpler than D. For real.
Agreed!
Yeah, there's no way everyone predicted it to be > 2100 :/
I thought E was easier than D but chromate00 held me at gunpoint for the rating predictions.
what
Hahaha
i do agree that E is only slightly harder than D, if at all. but at its position in the problemset it was kind of expected to be >= 2200 (especially with a harder than average D before it). it would probably be a different story if it was instead a div1C or had an easier D preceding it
Yeah, though as was mentioned in other thread above, it couldn't happen as div1c as it's kinda too known for div1. I was probably just wrong to judge it not from the rated participants' perspective
are they worth upsolving for my rating?
https://codeforces.me/contest/2063/submission/302459815
why this is wrong can someone explain ?
i have simply done the process told by the editorial and it is giving wa on 4
you choose the first vertex incorrectly. you take the vertex with the highest degree, but maybe if there are several such vertices, you take a non-optimal vertex.
how to find that given vertex with highest degree is optimal or not ?
https://codeforces.me/blog/entry/138593?#comment-1240120
you can search the 1st vertex and look for the maximum degree among the remaining ones using multiset. the asymptotics will be O(nlog(n)). that's what I did. or as it is written in the solution in point 2, search 2 vertices as the first one
historical round, cool problems
Problem C can be solved using DP without any observation, but the state transition is a little bit complicated.
Can you explain your DP approach?
Seems that F2 can be solved much more easily by solving reversely (with a disjoint set union to maintain the father-son relationship)
oh well, it was initially forcing online, and the coordinator thought offline is not too much easier. If offline makes it cleaner for you, you can solve it offline.
hi everyone! i understand each one of you might've had super high expectations since this was round #1000, i get it, but it's not right to belittle or humiliate other people just because they didn't exactly meet your super high expectations, right? i believe B and C were really nice tasks! also overall the round was enjoyable, the editorial also seems very informative, kudos to the authors + testers for this round. let's not get blinded by our subjective views and insult other people (by downvoting their blogs) who tried their best :) thanks
For C I tried getting the maximum degree, adding that to the answer, removing that node and decreasing degree for each neighbour node and then getting the maximum degree again. Why does this fail, any counter case?
Also great round!!
same here.
there's a slight issue with this. let M be the maximum degree of a vertex present in the tree, and V be the set of all vertices with such degree M. there can be a case where you can remove a vertex from this set and still have another vertex of degree M present, which is the optimal way. however, in your case you aren't considering this and would remove a vertex which would affect the degrees of all remaining vertices in V, and hence, give a sub-optimal answer.
for example: for a tree of 8 nodes with these edges: -
1 2 1 3 1 4 2 5 2 6 3 7 3 8
here you'd end up removing (1, 2) or (1, 3) which would give 4 components, but ideally you should remove (3, 2) and have 5 components.
hope that helps
This helps a lot!! Thanks!!
you're welcome!
ThankFully rating can not go below 0.....
it can
https://codeforces.me/contest/2063/submission/302390551
Could anyone please explain why this approach is wrong? I just sorted a and printed the sum for l-r+1 elements.
i was not able to think this so i just used two pointer.
oh god i was so dumb i was onto this problem for an entire hour no!!!!
This would fail. Consider the test case
3 6 6 4 3 2
l = 3, r = 5
Here, by your logic, the answer should be
8
, but clearly notice that the answer for this test case is9
.Could someone give me a hint why my D solution gives WA3
There are nothing amazing question in this contest. And just for me , F1 is much more easier than E. Anyway , I'm glad to participate in this 1e3 round. May be it'll be better in 1024 round ? :)
[user:chromate00][user:MikeMirzayanov] I have submitted A in the contest. It is showing submitted in the official standings, however it is not showing submitted in the unofficial standings. Kindly rectify the situation. Submission- [submission:https://codeforces.me/contest/2063/submission/302363475]
chromate00 MikeMirzayanov I have submitted A in the contest. It is showing submitted in the official standings, however it is not showing submitted in the unofficial standings. Kindly rectify the situation. Submission-
302363475
Editorial seems quite overkill for many of the problems, like binary search for D, and forest of splay trees for F. That being said I also solved F with link-cut tree lmao, though I'm not sure why the editorial doesn't mention that the forest of splay trees kinda just is a link-cut tree?
Anyway, very happy to AK and get rank 27 on such a special round. Screencast here for those who are interested.
Splay in F — overkill)
can anyone tell me whats wrong with mine approach
https://codeforces.me/contest/2063/submission/302431234
i am finding the vertex with highest indegree and then recalculating indegrees and then taking and removing the highest again. i am taking the case of line graphs separately
Edit : found the mistake
1 2 1 3 1 4 2 5 2 6 3 7 3 8
+++
.
I don't get why my following logic failed in problem C,
My approach:
Initially ans = 1, and store the number of edges in an array sz.
First, find the vertex with most edges, let's say vertex u with sz[u] edges, then answer increase by sz[u]-1, then decrease sz[x] by 1 for all vertext adjacent to u. Also set sz[u]=0
Then repeat the process to get second vertex v. Then ans again increase by sz[v]-1
Submission:
https://codeforces.me/contest/2063/submission/302433943
Consider this situation: the tree has five nodes —— 1-2-3-4-5
Vertex 3 is one of the vertices with most edges, so possibly you tried to remove vertex 3. But the only optimal method is to remove vertex 2 and 4.
Totally missed this one, thanks.
despite doing horribly i think the problems are slightly better than your avg div 2 , and more balanced , not the quality i expected for the 1000th , still nice tho
edit : i havnt seen problem F , maybe it'll change my view of the contest
again messed up B and solved C before B. Also why downvotes, why do you think the problems aren't "awesome" ?
F1 was predicted to be easier than D ?! :(
yes, we gave less scores on it and it turns out that people don't read :(((((((((((
can anyone help me this in problem B for the test case
according to the solution given in tutorial the answer is coming out to be 45 but like in range 3 to 6 even if we try reverse any subsequence of the array the interval sum is not coming out to be 45 but it is accepting the solution I do not know how that sorting logic is working here I got this thing like why we are trying for 1 to r or l to n so can anyone please explain this
also any advice for how should i maintain my rating range i am getting a lot of -ve delta nowadays though i am solving 1200, 1300,1400
Okay got this
302471253 why does this not work for C?
I don't know that experts can set most of the questions in a Div2 round before :|
The above is just my opinion, because after a while, I will become an expert :(
guys, did nobody solve C using dp/ dfs ?
I have used Eular tour and dp rerooting to find out the answer if I remove the ith node.... and to find this I did something like this. At every node, I am updating the segment tree which stores the count of edges at each node. So as I am removing the ith node I am setting the value to 0 for the ith node and subtracting 1 from my child value and then I am finding the maximum edge of any node using the segment tree.... although this is very overkill for 1500 rated problem this is the solution which comes to my mind so it didn't waste time to think of any case work.
In the second question (Subsequence Update), can we just sort the given array and give output the sum of the first (r — l + 1) elements as we can swap any elements with any other element ? I followed this logic it passed the test case 1 but failed in test case 2 , Help ?
This would fail. Consider the test case
3 6 6 4 3 2
l = 3, r = 5
Here, by your logic, the answer should be
8
, but clearly notice that the answer for this test case is9
.Failed to solve problem C, Can somebody please point out my mistake
My idea was that when I remove a node and its edges, it creates new components equal to the degree of that node, and when I have to choose the second node, it would be from one of the new components. so the result would be (Degree of first node — 1 + degree of second node)
I first took the node with highest degree, and decreased the degree of its negibouring nodes by 1, then again chose the node with highest degree(highest degree after removal of edges of first node)
WA4 : https://codeforces.me/contest/2063/submission/302459466
consider graph like 1-2-5-3-4 In this if you remove 5 first then answer will be 2 but if u remove 2 or 3 first then answer will be 3 .
Thank you, Understood my mistake.
It works until you don't have a graph which has three nodes with a maximal degree which form a tree subgraph. Then, if you pick the "root" of this tree as the first node (which can happen as you don't check which of the nodes having equal degrees to pick), its removal will decrease the degrees of both other nodes of that degree, so no nodes to pick at second step will have that maximum degree. And if you pick a "leaf" of this tree as the first node to remove, the second leaf will still have the maximum degree after removal as it wasn't adjacent to the first node, so you can pick the second leaf as the second node.
Thank you, I never saw it that way, need to work on trying more testcases.
Here is my 2 post contest accepted submission for C..
302473806. (using inclusion exclusion property)
302476948 (initial approach with more operations)
can anybody hack these submissions??
During contest I guessed that, checking the first 10 or 20 nodes with higher in degree will do the work.. But I did not implement & I stuck with my initial solution.. Sed,, i missed as always...
Actually, I think it's correct. We can see that the wrong solution fails when there are $$$3$$$ connected vertices with the same largest degree, and we can't pick the middle one as the first to remove. However, when there are $$$4$$$(or more) such vertices, we can pick the first one arbitrarily because it won't affect answer anymore. Therefore, checking 10 nodes(in fact, 3) should be enough.
Why is this Showing TLE on the first pretest on problem C, what's wrong , can anyone help me out[submission:302460657],
In the last for, in this line:
It's getting out of bounds. 302523195
OH! Thank you
I thought the problems were great, also I appreciate that F was doable even for div 2 participants. I found CDE all very interesting problems, but that's probably because they're at my level.
Great problemset.
In C you can simply output $$$d_{max} * 2 - 1$$$ when there are three or more nodes with the same maximal degree without simulation and otherwise just simulate picking two best nodes greedily.
In D, when computing the $$$k$$$-th answer, you can just check if the number of point pairs (segments) picked from one of the two lines exceeds the possible maximum which is $$$n - k$$$ and $$$m - k$$$ for the first and second line, respectively. If it does, knock the last segment length from the answer and add two lengths from another line. If it doesn't, just add the length from that line that allows it (i.e. from which the number of already picked segments is strictly less than the possible maximum) and yields maximal of two results (if both are allowed). The only thing you need for prepocessing is to sort segment lengths in decreasing order like shown and proven in the editorial.
Could anyone explain the 2 pointers approach in problem D please?
https://codeforces.me/contest/2063/submission/302728494
You can see this. Take the values from favorable array until the allows you then continue by removing elements the elements you already chose(from favorable array) and adding the elements from the other(unfavorable) array.
I had a similar solution for problem D.
https://codeforces.me/contest/2063/submission/303740949
I had the same direction as editorial for C but couldn't figure it out completely and then had to go back to DP because DP made sense to me quickly but the editorial approach needs some casework to be done.
302483202
Will please someone help me analyse where this code is going wrong on testcase4?
I take the vertex with highest vertex and add deg-1 and decrement degrees for all connected nodes then again take the highest deg and add to ans.
302483202
Will please someone help me analyse where this code is going wrong on testcase4?
I take the vertex with highest vertex and add deg-1 and decrement degrees for all connected nodes then again take the highest deg and add to ans.
same
i also did exactly but it doesn't worked out
i check which testcase is causing it but can't see that testcase
302487313
bro How did you conclude that there are two nodes with maximum degree?
if you read the code properly then you will find that ->
case : 1 -> if the two nodes with maximum degree are not equal(by deg), then the first max node is unique and for the second node i tried all possible other nodes
case : 2 -> if there are multiple equal maximum degree nodes, then the first max node is not unique in this case and we have to try all the max first nodes for the case 1 -> this will lead to TLE but there's a catch, we don't need to try all possible nodes in place for the first node instead it is enough to try for any 2 max first node (proof it by pen and paper yourself)
Thank you chromate00 for the round, I had a fun time!
It seems that problems F1 and F2 are very similar to problem E of the recent 997 round.
We noticed this. F1 is similar to that E, but it is quite overkill to apply the same thinking process. Meanwhile, F2 is harder than that E. Therefore, we decided to keep both, for balance and completeness of problemset.
or well I HOPED F1 will balance things but THEY DIDN'T READ
good Round
Problem C : extreme brute force solution (302504107)
In the editorial of D, shouldn't it be concave instead of convex? Prefix sum of a decreasing sequence should be concave right?
Depends on upwards or downwards. Usually in terms of optimization we call it convex in this situation.
I think in both cases, it should be concave. The definition of a convex sequence says $$$2a_n \leq a_{n-1} + a_{n+1}$$$. Which translates to either $$$a_{n+1}-a_{n} \geq a_{n}-a_{n-1}$$$ or equivalently, $$$a_{n}-a_{n+1} \leq a_{n-1}-a_{n}$$$. This can be understood as follows, for an increasing sequence, the increments are increasing, or for a decreasing sequence, the decrements are decreasing. Intuitively, this also captures the U shape that is commonly associated with convex functions. The function in here, say $$$h(x) = g(x,k-x)$$$, is the opposite of what I described above. Hence I believe its more accurate to call it concave (it also follows the inverted U associated commonly with concave functions).
Even for the same graph people call it either convex upwards or concave downwards. It's just terminology difference
I actually used DP on trees and i don't know why but my solution is failing on Test case 2 C ripped my whole contest. missed D by 5 minutes.
here is my submission if someone would like to help 302414968
P.S.-I personally liked the contest problems
Hey, your DP state is the same as mine. You can refer to my code :)
F1 is easy. I solved it much earlier than D, the scoring distribution tells enough
can anyone help me understand what's wrong with my approach on C?
i chose and removed the vertex with most neighbors, then i removed all the edges. Finally i chose again the vertex with the most neighbors.
302514363
PS: great contest!
Overkilled E by narrow-mindedly focussing on a solution with treaps, then saw the editorial lol! Great round tho, befitting of the 1000th round, only wished it were a Div. 1 + 2 :)
The official F2 solution using splay tree was way more complicated than what I did so I decided to share it here.
Simple solution to F2 where the most complicated technique being used is max segtree: https://codeforces.me/contest/2063/submission/302526177
Equivilent quadratic solution: https://codeforces.me/contest/2063/submission/302525268
Note that
in the quadratic solution is equivilent to
in the fast solution. I also made
len[i]
include the start and end parenthesis in the fast solution but not in the slow (since it made it easier to code).OK,but this got TLE and this got AC. I thought it's meaningless to make it TLE since their difference is only the way to save edge.You'd better try some other correct way to do your problem in order to avoid such terrible things.
Sorry for my poor english:(
Good contest.
Thanks for the round! I'm pretty happy with problem F, I managed to solve it with a normal segment tree and binary searching in it the smallest closing bracket to the left of the query.
Thanks for hosting codeforces 1000th round!!
The test cases for C are not comprehensive; my own solution for a fact is wrong. I'll try to explain what I am saying. Say if 3 vertices each have the maximum degree and are connected in a line, and the middle one has many 1 degree neighbours, more than the left and right ones, then we should still remove the left and right vertices
Consider the following test case:
1
22
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 2
17 4
17 6
17 8
18 10
18 12
18 14
18 16
17 19
18 19
19 20
19 21
19 22
On this test case, my code gives 8 as the answer, whereas the actual answer is 9. Idk how my code passed all the test cases!
Actually, you can transform Problem F2 into a tree, and solve the problem from the back to the front. In that way, it is all about merging components together, which can reduce the time complexity from $$$\mathcal{O}(n\log n)$$$ to something like $$$\mathcal{O}(n\alpha(n))$$$ (the time complexity of a dsu).
The detail that is worth noticing is that if two subtrees with the same parent are both visited, you should merge them too. You can use a virtual node representing the "parent" to solve this case.
Here is the Python implementation (not optimized fully because I wrote it in about 15 minutes): My Submission.
Can you explain how to find the "outer" bracket in O(n alpha(n))? Thanks.
Each bracket sequence can be transform into a tree, it's just about parents / ancestors.
But what I'm doing here is nothing about "outer" brackets. It's just merging nodes in a tree from the back to the front.
In Problem C, this code is according to the solution provided in editorial
Can anyone help understand why this code does not work ?
https://codeforces.me/contest/2063/submission/302540075 Edit : found it :)
Can someone tell me what did I do wrong in this one: Problem D 302546078. I think it is not passing be reference. Please give inputs to fix it.
second one was really good question.
I had a very funny and implementation-heavy solution for problem D. I put x-coordinates of the bottom line in the ordered_set and same for the top line. Then, I did some greedy, I chose min and max point on either bottom or top line (wherever the difference between the coordinates is greater), then I chose a middle point on the opposite side using ordered_set. However, it won't be maximum amount of operations because there can be a case where there will be a lot of points on one side and <2 on another. Therefore, I reverted once last operation and chose points from another side. I don't really know how to prove it, but I got AC by on the first try.
My submission: 302423073
Same, but a much cleaner code XD
Hey everyone, My first comment here :)) I am not getting why my solution for C is incorrect. I am just choosing the nodes with maxdegree and second max degree and checking cases where if maxdegrees are more than 1 and are they connected or not etc. pls help:( my submission: 302456927
include <bits/stdc++.h>
define ll long long
using namespace std; int main() { int t; cin >> t; while(t--){ int n; cin >> n; vector<vector> adj(n + 1); vector degree(n + 1, 0); for(int i = 0; i < n — 1; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); degree[u]++; degree[v]++; } int maxDegreeNode = -1, secondMaxDegreeNode = -1; int maxDegree = -1, secondMaxDegree = -1; vector maxDegreeNodes,secondMaxDegreeNodes; int maxDegreecount = 0,secondMaxdegreecount = 0; int count = 0; for (int i = 1; i <= n; i++) { if (degree[i] > maxDegree) { secondMaxDegree = maxDegree; secondMaxDegreeNode = maxDegreeNode; maxDegree = degree[i]; maxDegreeNode = i; } else if (degree[i] > secondMaxDegree) { secondMaxDegree = degree[i]; secondMaxDegreeNode = i; } } for(int i=1;i<=n;i++){ if(degree[i] == maxDegree){ maxDegreecount++; maxDegreeNodes.push_back(i);} } for(int i=1;i<=n;i++){ if(degree[i] == secondMaxDegree){ secondMaxdegreecount++; secondMaxDegreeNodes.push_back(i);} }
}
Did i post the comment correctly?? idk:\
Definitely not
You should put the block in a spoiler div, so that you don't flood.
< spoiler summary="Code">
~~~~~ Your code here... ~~~~~
</spoiler>
Use the "Preview" button to make sure you get a satisfactory result
Thankyou ;) also, Can u tell me where I did wrong in C?
Can anybody explain me in C question second approach why only trying two vertices of highest degree gave the right answer.
1st problem was a piece of cake
Well, F2 can be solved in O( N log MOD ) ( log MOD for calculating inverse mod). I only need to observe the brackets as a tree (assuming that (0, N + 1) is also a good pair)) and then "removing" the brackets (by reversing the queries), which I can maintain by DSU.
4th problem "Observe that the value dependent on p is a prefix sum of a strictly decreasing sequence, and thus is convex." can someone please explain above sentence form editorial of 4th question. Suppose we take array containing values 1/i where i being index (talking about 1 based indexing) and we take prefix sum then we do not get convex function. Please tell me where I am going wrong. If someone has done 2 pointer method or binary search then please share your solution.
as the value is summation(An-i-1) — summation(Ai) , as both are strictly increasing subtraction of one will be decreasing and the net graph would be a convex
Submission
What is wrong with this? Can someone explain
A simpler solution for 2063D — Game With Triangles without binary search, in O(n+m):
At a step with chosen p,q, the next step will be one of ((p+1,q),(p,q+1),(p+2,q-1),(p-1,q+2)). Greedily choose the best next step and assign new value of p,q
https://codeforces.me/contest/2063/submission/302430925
Hey! I feel like we have the same approach to the question. Can you check why I didnt get some test cases passed? 302546078
Your code has time complexity O(n*n*n) and didn't even pass test case 1. In the 3rd test case for 1 operation need to choose a, 2 operations need to choose 2 b.
this still requires sorting, which makes it $$$O(n \times log(n) + m \times log(m))$$$ instead.
you're right
in c if we go by dp then we have to modify adj list at each for destroying the ele? am i right?
in c question why is it deg[x]+deg[y]-1 can anyone explain me better
A,B,C,D,E Video Solutions here: https://www.youtube.com/watch?v=v4Dt37mBIBA
A,B,C,D,E Video Solutions here: https://www.youtube.com/watch?v=v4Dt37mBIBA
saw the video still did not unterstand the reason of first case second is easy to understand
It is really terrible. F1<<E<<D.
E<D can happen if you are better at math, F1<D is intended. Did you really not read the score distribution before calling bullshit
But I think F2 is easier than D too. D is so difficult. If I start the contest at E/F instead of D,I will be a Candidate Master.
D is a regret-greedy that I haven't saw it on Codeforces before.
People can be so rude on this platform. I really appreciated the contest and had a lot of fun upsolving up to D. I hope you continue with creating more contests in the future!
But obviously there is a offline method can solve F2 in $$$O(n\alpha(n))$$$ with dsu, and u can use this skill to optimize it to $$$O(n)$$$.
Yes, we understand that this exists. Anyways, it is very fascinating that the small to large solution can solve it online in $$$\mathcal{O}(n \log n)$$$.
can any one help me please why i am getting wrong answer for C. Remove Exactly Two , here is my submission submission.
Can someone explain the following things more clearly in Problem E's editorial?
I didn't understand why the first summation would count the pairs $$$ d_u = d_v $$$ twice? Hence, I also didn't understand its fix.
in the second summation, i didn't understand the logic behind the summation. the above paragraph is very clear which explains the consideration of vertex $$$w$$$ as $$$LCA$$$ but I didn't understand what $$$s_u(S - s_u)$$$ means logically. Hence, the part after it is also unclear.
Explanation would be very appreciated from soneone who knows the answers to these confusions.
Thanks in advance 🧡
If there is some node $$$ v $$$ on the path $$$ w => u $$$, then won't it be counted in $$$ S - s_u $$$? If it will be counted then it violates the conditions of good pairs, no?
The sum is over $$$u$$$ that are direct children of $$$w$$$.
I'm confused about this part with Problem D.
Let us define a function $$$g(p,q)$$$ as the maximum score after performing "Operation A" $$$x$$$ times and "Operation B" $$$y$$$ times, assuming it is possible.
Do you mean $$$p$$$ times and $$$q$$$ times? I'm not sure where $$$x$$$ and $$$y$$$ are suddenly coming from.
In Problem C, Why it is not optimum to remove the node with maximum number number of edges, then remove the 2nd node with the maximum number of edges after removing the edges from the first operation? like this solution, why it fails? https://codeforces.me/contest/2063/submission/302950582
Try this test case :
10
8 9
4 3
4 2
10 9
1 9
2 10
2 5
6 10
5 7
How are people solving problem E with small to large merging?
I want to get more familiar with that concept but I am not able to come up with the solution from that approach
Solution Link Can someone please tell me what might be missing here, or give me a counter example so I could debug further. My idea is that max_child stores the maximum of all children of the current node and max_non_child stores the maximum of all the nodes visited so far except the sibling of the current node. Thanks a lot
F2 can be solved in O(n). Consider the tree whose hash is s. The reverse process merges a node with its children, parent/siblings hence can be handled using dsu. Link.
Greedy solution for D if anyone finds above difficult to understand.
https://codeforces.me/contest/2063/submission/303715832
where it is giving wrong answer?
F2 is actually a very standard offline reverse query + DSU trick, took me an incredibly long time to observe...
can anyone debug my code I just looked the most 3 degree nodes for all possibilities and if there is a edge between the nodes the answer is the sum of degree sum-2 if there is not the answer is degree sum-1 My submission: https://codeforces.me/contest/2063/submission/304652149
304654404 304653426 304652776
2063C — Remove exactly two
Can someone please explain why any of them gives wrong answer ?
Apologies, did not initialize ans = 0 for each test case ;))
I assumed something was wrong with my map approach