Codeforces Round #765 (Div. 2)
source link: http://codeforces.com/blog/entry/98913
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
By vilcheuski, 3 days ago, translation,
Hello, Codeforces!
We invite you to Codeforces Round #765 (Div. 2), which will take place in Wednesday, January 12, 2022 at 12:05UTC. Note the unusual contest start time. This round will be rated for all the participants whose ratings are lower than 2100.
You will have to solve 5 problems in 2 hours. One of the problems will be divided into easy and hard version. The round is based on the problems from Belarusian Regional olympiad. We kindly ask all Belarusian pupils who participated in this olympiad, to refrain from taking part in this round and discussing the problems publicly before the round ends.
Thanks to everyone who helped to prepare this contest:
- Our coordinators, KAN and isaf27 for good coordination.
- Wind_Eagle, gepardo, VEGAnn, andrew for help in preparing the round.
- programmer228, Vladik for testing the round.
- MikeMirzayanov for making nice systems Codeforces and Polygon.
The scoring distribution: 500-1000-1500-2000-(2000+1250)
Good luck to everyone!
UPD: Finally the editorial is available.
3 days ago, # |
Interesting, Can't wait to attempt again at going for green!
3 days ago, # |
Wish you all good luck & high rating!
-
The comment is hidden because of too negative feedback, click here to view it
-
Don't be too much greedy with ratings.
-
3 days ago, # |
Good luck! I wish every grey become green!
-
Can you please also wish for green to become cyan?
-
OK! I wish every green become cyan!
-
Can you please also wish for every cyan to become blue?)
-
Ok, i wish every cyan to become blue!!
-
-
-
The round is based on the problems from Belarusian Regional olympiad.
Does it mean that the round has many OI-style problems?
If someone can answer me, thanks in advance.
-
I think it will have standard codeforces problems, but the ideas of the problems are based from the Belarusian Regional olympiad
Finally a good old div2 with 5 problems. Can't wait for it!
Wish everyone good luck
3 days ago, # |
Wish everyone good luck!
3 days ago, # |
It's a pity that I can't participate, good luck everyone who can!
3 days ago, # |
Let's go, good luck!
3 days ago, # |
Looking forward to participating and performing well.
3 days ago, # |
Thank you for this amazing round!
3 days ago, # |
Every Monogon follower after seeing a recent CF Round Announcement: 'Not gonna lie, I spent the last one hour thinking of a smart comment that would get many upvotes.'
Together we can stop this. Donate by upvoting my comment.
(I may or may not be a Monogon Follower)
3 days ago, # |
Are the problems completely the same as the Belarusian Regional Olympiad or they are just based on them?
2 days ago, # |
Someone used an alternative!
MikeMirzayanov for making ** nice** systems Codeforces and Polygon.
2 days ago, # |
Great! The score distribution announced very early!
2 days ago, # |
good luck
2 days ago, # |
hoping for a good round.5 problems in div 2 are hard to find these day XD
2 days ago, # |
Wish you all good luck & high rating!
2 days ago, # |
Nyaharoo~~
2 days ago, # |
By looking at the score distribution, it seems like it will gonna be a very well balanced round.
2 days ago, # |
Wish you all good luck and high rating!!!.
2 days ago, # |
good luck to all
2 days ago, # |
who all like non-theme based contests wherein the problem statements are easy to understand and one dont have to spent extra 10-15 just to grasp the statement fully?
2 days ago, # |
I want to bid for the modern art painting of Problem C.
2 days ago, # |
Why so strict memory limit for problem C? :(
2 days ago, # |
not able to solve single problem :/
-
The comment is hidden because of too negative feedback, click here to view it
-
Participating in contests is a form of practice.
-
The comment is hidden because of too negative feedback, click here to view it
-
what do you mean? div2 is rated for newbies to
-
The comment is hidden because of too negative feedback, click here to view it
-
You're not enough eligible to advice others, go practice yourself and gain some ratings. And about demotivation, it's your theory that you are explaining to others, maybe for others things doesn't work that way. When i lose rating i feel little happy about it coz in some other contest i'm gonna get a huga +ve delta and also for current contest which i couldn't solve, will give me something new to learn.
-
-
-
Losing ratings is just because you did not perform well enough during the contest and also because of some hard problems in it. That might be a motivation for you to keep practicing and getting better to solve these hard problems to gain more ratings.
And about quitting CP just because you can't solve problems and depressed because you have lost your ratings, I think it didn't really come from ratings, but you didn't keen on CP enough.
-
in this contest really bad problem statement , thats the main reason :/ hopefully in future contest not like that long essay.
-
-
-
-
2 days ago, # |
I hate long statements
2 days ago, # |
thanks to problem A i could now probably go to sleep with 0 submissions
2 days ago, # |
I love pretest 5 on problem C
-
Wish the memory limit were 512Mb.
Tried really weird things to make my 3D dp ~476Mb solution pass (array of maps and maps of vectors, lol).-
This was made on purpose to make you write 2D DP.
-
array of maps and maps of vectors, lol
Sounds quite complex. The intended solution uses just a 2D array, and the memory limits were adjusted for this solution.
-
2 days ago, # |
Long statements really consumes lot of time.
-
The comment is hidden because of too negative feedback, click here to view it
-
actually they are not more clear the story is not useful, i mean shorter statement is better
-
Would it be better if we rewrote the statements as
Given an array aa of nn ℓℓ-bit integers, find an ℓℓ-bit integer yy such that ∑i=1nd(ai,y)→min∑i=1nd(ai,y)→min, where d(x,y)d(x,y) is Hamming distance.
I tried my best to make the rewrite above as short as possible, without omitting essential details.
-
-
Yes, but they are more clear and contain more explanations.
Exactly, but this applies only if statements actually contain explanations, rather than random planet's moon.
-
I know that I don't hold the popular opinion here. Still, I want to show that the problem A mostly contained detailed explanations, rather than "random planet's moon". See yourself:
ImageAs you can see, the legend part is no more than a third of the statements, while the other part is actually explanations.
To prove my point about clearer statements further, I want to say that this contest had much smaller amount of questions than other recent rounds I helped setting. The number of questions was even ~1.5 times smaller than my old Codeforces Round from five years ago, where the number of participants was ~3 times smaller than now.
-
-
2 days ago, # |
Why is the memory limit for C so strict?
2 days ago, # |
ReadAlotForces
2 days ago, # |
Is it just me or contest these days are really hard?
2 days ago, # |
Is there any greedy solution for problem C?
-
With a simple greedy solution (eliminate a sign which is causing the largest delay at each step), I came till pretest 8.
-
Can anyone tell what is wrong in this approach? Link to my solution by this approach: https://codeforces.com/contest/1625/submission/142540240
-
-
Greedy is not feasible for problem C.
try this test case:
10 18 3
0 1 3 4 6 7 9 10 11 12
2 3 2 3 2 3 2 3 4 3the answer is 42, meanwhile greedy approach is likely to give 45.
Take a look at the illustration:
So use dynamic programming, I hope my submission 142583078 may help you.
2 days ago, # |
How to solve D?
-
Special case: if k=0k=0, the answer is all indices from 11 to nn inclusive. Hereafter we assume k≠0k≠0.
Partition the values aiai into groups according to the prefix of bits higher than kk's most significant bit. Observe that you can consider each such group individually, as any two values from two different groups will xor into a prefix that's greater than kk's most significant bit.
Now in each group, we can always choose at least one member, and at most two members, because if we choose more than two, there will be two values that will xor to zero in the position of kk's most significant bit, thereby producing a value less than kk.
To find out if we can choose two values from a group, we find the pair with the maximum xor and compare it with kk. Finding the maximum xor of two numbers in an array is a well-known problem (but you'd need to modify the algorithm on this page so that you know the indices of the pair) and can be done in O(mlogk)O(mlogk), where mm is the number of values in the group. Therefore the total time taken over all groups will be O(nlogk)O(nlogk).
-
can u give me an example how to partition such groubs. I think in each group the xor between its elements must make the bits that greater than most significant bit in k equal to zero, right???
-
Say k=5=1012k=5=1012, and a=[27,31,17,13]=[110112,111112,100012,11012]a=[27,31,17,13]=[110112,111112,100012,11012]. The first and second element would be in one group, the third element would be in another, and the fourth in yet another, according to the bits highlighted in red, which is anything above kk's most significant one-bit.
-
I created strings for those bits like "11", "11", "10","01" and stored them in a map so that only unique ones are stored and then printed all the unique strings' corresponding index, but it didn't work, any idea why? 142643010
-
-
-
Observation is that a minimum value of ai⊕ajai⊕aj is achieved at some two adjacent numbers after sorting.
After sorting, you can write simple dynamic programming, dpidpi — the length of the longest subsequence that ends with ii. Transitions are very simple dpi=maxdpi=max {dp[j]+1dp[j]+1}, where ai⊕aj≥kai⊕aj≥k.
It can be optimized using trie.
-
But why only ai⊕aj≥kai⊕aj≥k?
It is possible that whatever subsequence dpjdpj is storing in has a xor value xx and x⊕ai<kx⊕ai<k.
Does this have something related to the optimization using trie?
-
2 days ago, # |
That 128MB memory limit on Problem C was tricky.
-
hey! can you please explain these lines in your submission of B
int dist1 = val1;
int dist2 = (n — val2);
ans = max(ans, dist2 + dist1);
why are you only considering dist. left to val1 and right to the val2?
What's the expected time complexity for problem c ? my O(n*k^2) dp solution was giving tle.
-
A was easy, It was based on bits and count of which is more 0 or 1, My submission My sub
-
Man , I am saying Statement is way too complicated for A . BTW I have solved it
-
Did you get B bro, Some hint would be nice
-
Hey, check my solution. It's quite simple. if you don't get it DM me. I'm on codeforces for the next 2 hours.
Edit: I can't reply to my DM because of some restrictions by codeforces. It's showing You exceeded your quota of 3 distinct recipients per hour. so, sorry guys. dukhi_insaan.
This is a small explanation: Take every pair of equal numbers (I did this by sorting and taking i and i+1) and place them in the same position of 2 arrays (hypothetical arrays). Now assume their positions in the actual array be a and b. A number of elements that can come in an array hypothetical array on the left of our number are a-1 and on left can be at max n-b-1. hence the length of the hypothetical arrays can be a-n-b-1.
I hope you get some idea from this.
-
-
-
2 days ago, # |
Can coordinators please cancel my last submission for the problem A, I had already solved it before 10 min but accidentally pressed submit while thinking and now the answer shows submitted after 2h. You can check my code, please remove that submission, so I can get points for original submission.
2 days ago, # |
Has anyone solved B via Binary search ?
2 days ago, # |
Some hints for D please.
-
bit trie
-
can anyone of you please tell in
problem B
why it is sufficient to check only two consecutive indexes?-
Let's say two numbers that are equal have index l1l1 and l2l2.
Consider l1l1<l2l2 Now we'll see what is the length of the segment, for number at position l2l2 to be at the l1l1 position in its segment, segment must start at index l2−l1l2−l1.
As we have to maximize the length we can take the endpoint of the segment to be n−1n−1.
Now length of the segment becomes (n−1)−(l2−l1)+1(n−1)−(l2−l1)+1. You can see that if l2l2 and l1l1 will not be nearest index of some number then answer will become worse.
-
2 days ago, # |
A hint for Problem E2:
-
Maybe an interesting extension for type 1 queries is to guarantee that s[l+1…r−1]s[l+1…r−1] is an RBS.
Spoiler
The most miserable thing for python users during the contest: Figure
2 days ago, # |
A very nice contest ruined with long problem statements
Can anyone help me in problem B,wrong answer at pretest 4
Basically selecting minimum difference indices of same character than adding count of elemnts before first appearence and after elements of second appearence
ans = x[0] + n — x[1];
-
I didn't get why you want to maintain the size of map entry to 2.
I just collected all the indices and did the max among every two consecutive indices https://codeforces.com/contest/1625/submission/142480649
-
yeah i did the same after my frnd told me to simply run for all, basically looping for all indices am already selecting two indices of minimum diffrence
-
2 days ago, # |
The idea of Problem D is good. Not only observation but also a specific technique is required to solve it. However, I think it is too hard for Div.2D. Due to the difficulty of this technique, it should be somewhere around Div.2E. Also, the corner case k=0k=0 is tricky.
-
Trie is not needed if you make use of the observation that choosing elements with different msb (most significant bit) are independent and to consider which elements of the same msb should be chosen, we just need to switch off the msb and consider the subproblem recursively.
At the last step, when the msb becomes smaller than or equal the msb of kk, we can make use of this to check whether there exist a pair of numbers whose xor exceeds kk, and if otherwise we just pick any random number.
-
To handle groups of elements with MSB <= k, I also used the technique in the GeeksforGeeks article you linked during the contest, but I got TLE. I even tried replacing the
set<int>
that they use with an efficient hashmap, but still got TLE. In order to get AC when upsolving, I realized it was faster to use a 0/1 trie to figure out what the maximum XOR of any pair of numbers is. See themaxXor
function in this solution.-
My submission 142523115 was able to pass in 1560ms using
set<int>
though.
-
-
2 days ago, # |
What is wrong with this logic for D: let i = leftmost set bit of k, right shift each element by i-1. Output the no. of unique elements after the right shifts.
2 days ago, # |
Can anyone, who was able to solve Problem C walk me through the recursive->Memoization->Top-Down/Bottom-Up solution? I am learning DP right now and could not understand the code of other participants. Would really help me a lot...
-
Let dp(i,j)dp(i,j) = min time to reach didi, by removing jj signs. Assuming dn=ldn=l, the answer is minimum of dp(n,j)dp(n,j) over all j<=kj<=k.
Recursion: Consider computing dp(i,j)dp(i,j). One candidate for dp(i,j)dp(i,j) is dp(i−1,j)+ai−1∗(di−di−1)dp(i−1,j)+ai−1∗(di−di−1). But it's possible that we removed the (i−1)(i−1)th sign, so we drove at speed ai−2ai−2 from di−2di−2 all along, so dp(i−2,j−1)+ai−2∗(di−di−2)dp(i−2,j−1)+ai−2∗(di−di−2) is another candidate. Continuing with this reasoning, and also noting that we could not have removed more than jj signs, we get the recurrence:
dp(i,j)=minp<=jdp(i−1−p,j−p)+(di−di−1−p)∗ai−1−p)dp(i,j)=minp<=jdp(i−1−p,j−p)+(di−di−1−p)∗ai−1−p).
Base case is of course dp(0,∗)=0dp(0,∗)=0.
2 days ago, # |
pretests were deadly :(
2 days ago, # |
Is system testing done?
2 days ago, # |
Why is my solution for C giving WA verdict? 142521905
-
Among all possible
(ans, prev)
indp[i-1][j-1]
, there might be such pair that theans
is bigger while theprev
is smaller and it is better to transition from that pair.-
Will you please elaborate more? Will this case arise only when temp1==temp2 has been happened previously?
-
2 days ago, # |
i think not too much care about story or long statement during the contest , during training it will be fun , it was amazing round thanks
2 days ago, # |
Ratings updated preliminarily. We will remove cheaters and update the ratings again soon!
If you were stuck at a problem <=C, Here are the video solutions,
2 days ago, # |
- Suggestions on problem D: Stop making ORIGINAL PROBLEMS.
I think testers should realize that, because this problem is very classical and is obviously an original problem.
-
I don't think problem setters should avoid classical problems in div2 and div3. Div 2 and 3 are "educational" contest. Although problem D uses classical idea, not everyone (especially experts and below) have seen it before, and they can learn in this contest, which is good for them to study.
The problem is good to use if only you are not able google the problem by the statement online.
-
I don't think problem setters should avoid classical problems in div2 and div3. Div 2 and 3 are "educational" contest.
I thought Educational Codeforces rounds were created as "educational" contests, not the regular Div. 2 rounds.
-
2 days ago, # |
Can anyone tell why my recursive+memoized solution for problem C is giving WA on test case 5?
submission: 142506652
47 hours ago, # |
In case anyone else is struggling with TLE in problem D with Java, I needed to do both of the following to make it fast enough:
- Don't store each number once for each bit i.e. each trie node should only contain a single number. During the step where you need to find all the numbers under a node, you'll need to run a separate DFS to get them all.
- Don't use objects. Use preallocated arrays as "fake" objects (e.g. https://codeforces.com/contest/1625/submission/142532132)
47 hours ago, # |
LONG STATEMENTS made bad reading experience.
A good contest anyway.
-
These are original statements from BelOI.
47 hours ago, # |
Video Editorial for Problem C: Road Optimization
I explain my 2 dimensional dynamic programming solution along with the intuition for why DP is used (and not greedy) and how one can come up with the recurrence.
https://codeforces.com/contest/1625/submission/142524915
Want to know what is wrong with my approach
My approach for C was as follows:
I find the index of all the signs, which when removed decrease the total time.
Now I just need to choose at max k of these candidates for removal.
this is where DP comes in, I apply it on the preselected candidates.
IF while choosing value of current k>0 than I have 2 option
1.)either choose to remove(insert index in a set named removed)
2.)Ignore and move to next candidate
ELSE Ignore and move to next candidate
for base case after completely going through all the candidates , I have a set of chosen sign's indices(i.e signs which should be removed). So considering that these set of removed signs as not being present, I calculate the total time taken and return it.
I memozized this using a dp[501][501] array.
46 hours ago, # |
Here is slightly harder version of problem D. Source: this comment.
44 hours ago, # |
bruh imagine waking up at 4am on US west coast to do div2 contest, just to give up after 15' of trying to read problem A.
-
That's similar to my experience: I woke up at 6:30 AM (normally I wake up at 8 AM or later) on US east and after reading problem A's long statement I started feeling dizzy and then gave up.
-
You didn't see statements with really long legends :) The problem here is in Russian.
-
How do you quickly find out whether we should use greedy algorithms or DP for optimization problems like C? The only clue that I found for C is the input size: 500. This might imply that we can use O(n^3) DP. If I don't know this size, I might spend time on thinking about possible greedy solutions.
(By the way, I didn't participate in this contest but I read and solved A, B, and C. I think they are interesting problems.)
38 hours ago, # |
Problem E2 is very interesting! I love this problem.
38 hours ago, # |
where tutorial? in tourist's stream?
36 hours ago, # |
Can problem C use Convex Hull Optimisation to solve it?
-
Yes, I solved it with convex hull after the contest.
Code : https://codeforces.com/contest/1625/submission/142559648
dp[i][j] is min time required to reach ith city using j road signs. So the transition is like dp[i][j] = min (m<i) dp[m][j-1] + (d[i]-d[m])*a[m]
The transition part can be written as a line like y = dp[m][j-1]-d[m]*a[m] + d[i]*a[m]
The slope is a[m] and the intercept is dp[m][j-1]-d[m]*a[m]. We can pass in d[i] and get the minimum using convex hull trick.
36 hours ago, # |
How to solve D problem?
36 hours ago, # |
thrilling round :)
34 hours ago, # |
excellent round with strong samples and pretests.
33 hours ago, # |
I could attempt only 2 problems and now my rating went down ;-;. How2 time management on easy questions. Aaaaaaa I wanna get to green so bad.
32 hours ago, # |
can anyone find problem in my code for problem D i am getting WA on test case 14. I am using bit trie, sorting and segment tree. after sorting if i am at indx i than first i will find the maximum element such that it's xor with current element is greater than or equal to k. Now i used dp since we can select any element which is less than maximum element(mx) so i made a segemnt tree on values of dpi's. dp[i]=max(dp[j]+1) for all j such that a[j]<=mx Then to update value of current element we just query of the prefix from 0 to mxid(index of maximum element) dp[i]=query(0,mxid)+1;
32 hours ago, # |
where can i get editorials to this contest
31 hour(s) ago, # |
Can anyone guide / help / suggest me on how to reach expert (1600+) rating at codeforces...... I am currently specalist.
31 hour(s) ago, # |
Could someone please explain why greedy wouldn't work for C?
-
About why greedy is not working on problem C, take a look at my reply: https://codeforces.com/blog/entry/98913?#comment-877347
I hope this will help.
26 hours ago, # |
Some hints for people stuck at debugging problems C and D.
-
@variety-jones Can you please work your magic to show what goes wrong with this submission (failing on test 14). Thanks!
-
So I'm a personal assistant now? XD.
InputA Valid OutputYour OutputComment
-
23 hours ago, # |
Any hint for Problem D
-
You can see my solution:-> https://codeforces.com/contest/1625/submission/142628388 I have provided necessary comments to make it easy to understand.
23 hours ago, # |
when is the editorial? i think beluorusian regional olympiad has it, because for example in russia, we have editorials right after the contest
-
Yes, but we have only Russian editorial now.
-
so u are going to wait for the official English editorial instead of publishing your own?
-
sorry but it's two days after the contest and there is still no editorial.
coue any one explain how to solve E2, please?
-
22 hours ago, # |
I don't know if the authorities can see it. It is the first time FOR me to play CodeForces, because I handed in the same code with this number and my trumpet and was targeted by the authorities. I hope you can listen to my sincere explanation.
22 hours ago, # |
I don't know if the authorities can see it. It is the first time FOR me to play CodeForces, because I handed in the same code with this number and my Tuba and was targeted by the authorities. I hope you can listen to my sincere explanation.
19 hours ago, # |
Is it possible to do C in O(n^2)?
7 hours ago, # |
Really nice div. 2 contest. Awesome set of problems.
3 hours ago, # |
Why is the editorial so slow?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK