### vilcheuski's blog

By vilcheuski, 15 months ago, translation,

Hello, Codeforces!

We invite you to Codeforces Round #765 (Div. 2), which will take place in Jan/12/2022 15:05 (Moscow time). 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:

The scoring distribution: 500-1000-1500-2000-(2000+1250)

Good luck to everyone!

UPD: Finally the editorial is available.

• +297

| Write comment?
 » 15 months ago, # |   +50 Wish you all good luck & high rating!
•  » » 14 months ago, # ^ |   +16 thanks, you too
•  » » » 14 months ago, # ^ |   -13 I laughed at this more than I should've, XD. Newbies are so cute at times.
•  » » 14 months ago, # ^ |   -38 Hey can you help me, I accidentally submitted code for A problem while thinking about pretests and now the time shows after 2h, but I had solved it before 10 min. It's a huge decrease in rank. Please a help will be great, I just commented after the contest so it can be considered. Please if that submission could be removed and my score revaluated.
•  » » » 14 months ago, # ^ |   0 Don't be too much greedy with ratings.
•  » » » » 14 months ago, # ^ |   +26 Yeah sorry, I didn't mean it but just wanted to know if there was such a correction or not, it didn't feel good to go down this way. Sorry, but isn't it too harsh to get so many downvotes asking for help :(. Anyways won't do this again.
 » 15 months ago, # |   +2 Good luck! I wish every grey become green!
•  » » 15 months ago, # ^ |   +40 Can you please also wish for green to become cyan?
•  » » » 15 months ago, # ^ |   +10 OK! I wish every green become cyan!
•  » » » » 15 months ago, # ^ | ← Rev. 2 →   +33 Can you please also wish for every cyan to become blue?)
•  » » » » » 15 months ago, # ^ |   +33 Ok, i wish every cyan to become blue!!
•  » » » » » » 15 months ago, # ^ |   +36 and how about for every blue to become purple?
•  » » » » » » » 14 months ago, # ^ |   -19 I wish Every blue becomes grey. Every cyan becomes grey with lower rating and every green becomes grey with 386 rating .
•  » » » » » » » » 14 months ago, # ^ |   +8 I wish every P_key25dec become red.
•  » » » » 15 months ago, # ^ |   -11 I don't want to go back to cyan!
•  » » » » 15 months ago, # ^ |   0 Thanks, I join this wish.
•  » » » » 14 months ago, # ^ |   +19 shrek tomorrow
•  » » 14 months ago, # ^ |   +9 Don't know about greys but i was green and now became grey.
 » 15 months ago, # | ← Rev. 2 →   +4 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.
•  » » 15 months ago, # ^ |   0 I think it will have standard codeforces problems, but the ideas of the problems are based from the Belarusian Regional olympiad
•  » » » 14 months ago, # ^ |   +22 Yes, the contest will have a usual Codeforces format. For example, on the Regional Olympiad we have partial scoring for the problems, and there will be no such thing on the round itself.
 » 15 months ago, # | ← Rev. 3 →   -15 Finally a good old div2 with 5 problems. Can't wait for it!Wish everyone good luck
•  » » 15 months ago, # ^ |   -15 THank you CODEFORCES for round with 5 problems.
 » 15 months ago, # |   -8 Wish everyone good luck!
 » 15 months ago, # |   -11 It's a pity that I can't participate, good luck everyone who can!
 » 15 months ago, # |   +2 Oh, i will solve this problems tomorrow at 9:00 AM(i from belarus):D
•  » » 14 months ago, # ^ |   0 Good luck then :)
 » 15 months ago, # |   0 Two contests on the same day damnn!!
•  » » 15 months ago, # ^ |   0 what is the second contest?
•  » » » 15 months ago, # ^ |   0 One of Codeforces and other of Codechef
 » 15 months ago, # |   0 Looking forward to participating and performing well.
 » 15 months ago, # |   +28 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)
 » 15 months ago, # |   +20 Yey,First div2 contest in the new year,Wish everyone good luck! Meme
 » 15 months ago, # |   +174 all Belarusian pupils all Belarusian specialists can do whatever they want
•  » » 15 months ago, # ^ |   +6 Also div1 pupils.
 » 15 months ago, # |   +7 Why has the Magic tab not disappeared yet ?
•  » » 14 months ago, # ^ |   +47 it's gone, hope you're happy now :D
 » 14 months ago, # |   +11 Are the problems completely the same as the Belarusian Regional Olympiad or they are just based on them?
 » 14 months ago, # |   -66
•  » » 14 months ago, # ^ |   -48
 » 14 months ago, # |   0 Great! The score distribution announced very early!
 » 14 months ago, # |   -24 Please, make problem B easy, so newbies can solve it
•  » » 14 months ago, # ^ |   +5 You will see on the contest whether it's easy or not :) We cannot change the problem, as it is already prepared.
•  » » » 14 months ago, # ^ |   -13 Really hope it's not about bitmasks or dp
•  » » » » 14 months ago, # ^ |   +3 B problem rare bitmask or dp
•  » » » » 14 months ago, # ^ |   +19 LOL! A was bitmask.
 » 14 months ago, # |   +65 Wish you all good luck & high rating!
 » 14 months ago, # |   +1 Nyaharoo~~
 » 14 months ago, # |   +41 essayforces!
•  » » 14 months ago, # ^ |   +41 Am i the only one who read it as easy forces.
 » 14 months ago, # |   +30 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?
•  » » 14 months ago, # ^ |   0 It really took me around 10 mins just to understand the statement of A....due to which this contest became the first div 2 contest in which I solved B faster than A xD
 » 14 months ago, # |   +10 I want to bid for the modern art painting of Problem C.
 » 14 months ago, # |   +5 What was that with problem A man? Almost gave me a heart attack xD
•  » » 14 months ago, # ^ |   +11 Essay Forces!!
•  » » 14 months ago, # ^ |   0 I participated in olympiad, this problem there today, so it's really easy
 » 14 months ago, # | ← Rev. 2 →   +2 Also, I hate Jupiter & its moons now XD
 » 14 months ago, # |   +13 Why so strict memory limit for problem C? :(
 » 14 months ago, # |   0 not able to solve single problem :/
•  » » 14 months ago, # ^ | ← Rev. 2 →   -45 ruined by kids downvoting and crying over it
•  » » » 14 months ago, # ^ |   +15 Participating in contests is a form of practice.
•  » » » » 14 months ago, # ^ | ← Rev. 4 →   -40 ruined by kids downvoting and crying over it
•  » » » » » 14 months ago, # ^ |   +1 what do you mean? div2 is rated for newbies to
•  » » » » » » 14 months ago, # ^ | ← Rev. 2 →   -27 ruined by kids downvoting and crying over it
•  » » » » » » » 14 months ago, # ^ | ← Rev. 2 →   +8 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.
•  » » » » » 14 months ago, # ^ | ← Rev. 2 →   +13 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.
•  » » » » » » 14 months ago, # ^ | ← Rev. 4 →   -12 in this contest really bad problem statement , thats the main reason :/ hopefully in future contest not like that long essay.
•  » » » » » » » 14 months ago, # ^ |   +27 You didn't solve the problem not because of statements. Don't lie to yourself.We had only 45 questions in a contest, which is far less than the average. Statements were crystally clear.
 » 14 months ago, # |   +40 I hate long statements
 » 14 months ago, # |   +5 thanks to problem A i could now probably go to sleep with 0 submissions
 » 14 months ago, # |   +5 I love pretest 5 on problem C
•  » » 14 months ago, # ^ | ← Rev. 2 →   +1 I love pretest 5 and MLE on problem C.
•  » » 14 months ago, # ^ |   0 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).
•  » » » 14 months ago, # ^ |   +18 This was made on purpose to make you write 2D DP.
•  » » » 14 months ago, # ^ |   +1 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.
•  » » » » 14 months ago, # ^ |   +4 Really enjoyed that, being new to DP, it was fun to optimize from 3D to 2D. Great contest you guys :) Thanks!
 » 14 months ago, # |   +31 Long statements really consumes lot of time.
•  » » 14 months ago, # ^ |   -73 Yes, but they are more clear and contain more explanations, so you most likely will understand the problem from the first read.
•  » » » 14 months ago, # ^ |   +40 actually they are not more clear the story is not useful, i mean shorter statement is better
•  » » » » 14 months ago, # ^ |   +28 Would it be better if we rewrote the statements as Given an array $a$ of $n$ $\ell$-bit integers, find an $\ell$-bit integer $y$ such that $\sum\limits_{i=1}^n d(a_i, y) \to \min$, where $d(x, y)$ is Hamming distance. I tried my best to make the rewrite above as short as possible, without omitting essential details.
•  » » » 14 months ago, # ^ | ← Rev. 2 →   +13 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.
•  » » » » 14 months ago, # ^ |   +42 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.
 » 14 months ago, # |   +81 Anyone else ? problem A
•  » » 14 months ago, # ^ | ← Rev. 2 →   +9 That's why i solved it in 7 minutes xD
 » 14 months ago, # |   +8 Why is the memory limit for C so strict?
 » 14 months ago, # |   +20 ReadAlotForces
 » 14 months ago, # |   +7 Is it just me or contest these days are really hard?
 » 14 months ago, # |   +10 Is there any greedy solution for problem C?
•  » » 14 months ago, # ^ |   0 With a simple greedy solution (eliminate a sign which is causing the largest delay at each step), I came till pretest 8.
•  » » » 14 months ago, # ^ |   0 Can anyone tell what is wrong in this approach? Link to my solution by this approach: https://codeforces.com/contest/1625/submission/142540240
•  » » 14 months ago, # ^ |   +1 I don't know such solutions. Use dynamic programming.
•  » » 14 months ago, # ^ | ← Rev. 8 →   +15 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 3 the 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.
 » 14 months ago, # |   +9 How to solve D?
•  » » 14 months ago, # ^ | ← Rev. 2 →   +18 Special case: if $k = 0$, the answer is all indices from $1$ to $n$ inclusive. Hereafter we assume $k \neq 0$.Partition the values $a_i$ into groups according to the prefix of bits higher than $k$'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 $k$'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 $k$'s most significant bit, thereby producing a value less than $k$.To find out if we can choose two values from a group, we find the pair with the maximum xor and compare it with $k$. 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(m \log k)$, where $m$ is the number of values in the group. Therefore the total time taken over all groups will be $O(n \log k)$.
•  » » » 14 months ago, # ^ |   0 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???
•  » » » » 14 months ago, # ^ |   +9 Say $k = 5 = 101_2$, and $a = [27, 31, 17, 13] = [\color{red}{11}011_2, \color{red}{11}111_2, \color{red}{10}001_2, \color{red}{1}101_2]$. 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 $k$'s most significant one-bit.
•  » » » » » 14 months ago, # ^ | ← Rev. 3 →   0 I get it thanks a lot
•  » » » » » 14 months ago, # ^ |   0 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
•  » » » » » » 14 months ago, # ^ |   0 From what I can tell you are indexing by bits $\geq msb$ rather than $> msb$, and I don't see anything recognizable as a max-xor-find there.142559786 Here's my solution for reference, it's in Rust though.
•  » » » 14 months ago, # ^ |   0 Damn, I was stuck at that "well known problem". Thanks for the clarification!
•  » » » 14 months ago, # ^ | ← Rev. 3 →   0 Should we also add one number whose MSB is less than k's MSB? And also one number whose MSB is equal to k's MSB?EDIT: nevermind. I guess these numbers will be in the group with prefix 00..0
•  » » 14 months ago, # ^ |   +1 Observation is that a minimum value of $a_i \oplus a_j$ is achieved at some two adjacent numbers after sorting.After sorting, you can write simple dynamic programming, $dp_i$ — the length of the longest subsequence that ends with $i$. Transitions are very simple $dp_i = max$ {$dp[j]+1$}, where $a_i \oplus a_j \geq k$. It can be optimized using trie.
•  » » » 14 months ago, # ^ | ← Rev. 2 →   0 But why only $a_i\oplus a_j\geq k$?It is possible that whatever subsequence $dp_j$ is storing in has a xor value $x$ and $x\oplus a_i\lt k$.Does this have something related to the optimization using trie?
•  » » » » 14 months ago, # ^ |   0 It is possible that whatever subsequence. No, because of the first observation.
 » 14 months ago, # |   +16 That 128MB memory limit on Problem C was tricky.
 » 14 months ago, # | ← Rev. 2 →   0 What's the expected time complexity for problem c ? my O(n*k^2) dp solution was giving tle.
•  » » 14 months ago, # ^ |   0 my solution passed with this complexity.
•  » » 14 months ago, # ^ |   0 I have $O(n^2 \cdot k)$ and I passed pretests. $500^3$ should fit if you don't do expensive operations.
 » 14 months ago, # |   +127
•  » » 14 months ago, # ^ |   -23 A was easy, It was based on bits and count of which is more 0 or 1, My submission My sub
•  » » » 14 months ago, # ^ |   +18 Man , I am saying Statement is way too complicated for A . BTW I have solved it
•  » » » 14 months ago, # ^ |   0 I read problem-A for 20 mins..... So so complicated and there are lots of new words for me.
•  » » 14 months ago, # ^ |   +1 Me reading all problems after 2 hours
 » 14 months ago, # |   +1 Can someone please give me hint for C?
•  » » 14 months ago, # ^ |   +3 Hint : Try to think of 3 state Dp transition and optimize space complexity
•  » » 14 months ago, # ^ |   +2 dp[i][j] = minimum time to reach L from ith speedpost (this speedpost is not removed) provided you are allowed to remove j speedposts in the middle.
•  » » » 14 months ago, # ^ |   0 So.. is dp[i][j] = min (dp[i+1][j], dp[i+2][j-1], dp[i+3][j-2],... dp[i+1+j][0])? That's O(n*k*k) right?
•  » » 14 months ago, # ^ |   0 Dynamic Programming. Lets iterate over the stops only. M(i,s) = minimum time to reach ith stop. ans = min {M(n,s')} where n-k <= s' <= n.
 » 14 months ago, # |   0 why aren't you allowing $log(n)^2$ solutions to pass in D?
•  » » 14 months ago, # ^ |   0 it depends on how efficient your implementation is. I'm pretty sure that my 142503668 is $\log^2$, and it got AC in 1.6s
 » 14 months ago, # |   0 Has anyone solved B via Binary search ?
•  » » 14 months ago, # ^ |   0 142482987 Here
 » 14 months ago, # |   0 Why did I pass the code sample locally, but not in codeforces ? Spoiler#include #include #include #include #include #include #include #include #define x first #define y second #define mp make_pair using namespace std; const int N = 2e5 + 10, inf = 0x3f3f3f3f; typedef long long ll; int n, t[N]; void solve(){ cin >> n; for(int i = 1; i <= N; ++ i) t[i] = -1; int ans = -1, id; for(int i = 1; i <= n; ++ i){ cin >> id; if(t[id]!=-1){ ans = max(ans, t[id]+n-i); } t[id] = i; } cout << ans << endl; } int main(){ ios::sync_with_stdio(false),cin.tie(nullptr); int p; cin >> p; while(p--){ solve(); } return 0; } 
•  » » 14 months ago, # ^ |   0 problem B
•  » » » 14 months ago, # ^ |   0 int t[N + 1]; 
•  » » » » 14 months ago, # ^ |   0 what ？
•  » » » » » 14 months ago, # ^ |   0 change ~~~~~ int n, t[N]; ~~~~~ into ~~~~~ int n, t[N + 1]; ~~~~~
 » 14 months ago, # |   +6 Some hints for D please.
•  » » 14 months ago, # ^ |   +14 bit trie
•  » » » 14 months ago, # ^ |   0 can anyone of you please tell in problem B why it is sufficient to check only two consecutive indexes?
•  » » » » 14 months ago, # ^ |   +3 because you can use all the elements before the previous one to be your prefix, so at any position it's always better to maximize that number.
•  » » » » 14 months ago, # ^ | ← Rev. 2 →   0 Let's say two numbers that are equal have index $l1$ and $l2$.Consider $l1$<$l2$ Now we'll see what is the length of the segment, for number at position $l2$ to be at the $l1$ position in its segment, segment must start at index $l2-l1$.As we have to maximize the length we can take the endpoint of the segment to be $n-1$.Now length of the segment becomes $(n-1) - (l2-l1) + 1$. You can see that if $l2$ and $l1$ will not be nearest index of some number then answer will become worse.
•  » » 14 months ago, # ^ | ← Rev. 5 →   +8 I think the below approach is correct. SpoilerLet $t$ be the minimum $i$ such that $k$ < $2^i$.Now, let's divide a number $a_{i}$ into two parts: prefix and suffixprefix: $a_{i}$>>$t$suffix: $a_{i}$%$t$Now, it's easy to see that there can only be almost 2 numbers in our result with the same prefix. If possible, find those two numbers for every prefix.
•  » » » 14 months ago, # ^ |   0 Thank you!
•  » » » 14 months ago, # ^ |   0 Yes you are right! After seeing your approach, I modify my code and it AC, thank you!
 » 14 months ago, # |   +71 I like problem D, but why $k=0$...
•  » » 14 months ago, # ^ | ← Rev. 2 →   -9 damn, I don't know how I missed that :(I hope this is not my mistake
 » 14 months ago, # |   +3 A hint for Problem E2: SpoilerFor operations of type 1, there're only '.' between the left and right brackets.(Many of my peers didn't see this and so didn't me. T_T)
•  » » 14 months ago, # ^ |   0 Maybe an interesting extension for type 1 queries is to guarantee that $s[l+1 \dots r-1]$ is an RBS. SpoilerThen instead of removing a leaf, we may have to delete a node and reattach its children to the parent. Thus we need to update who is the new parent of these children efficiently. If we keep a node's children in ordered sets, we can merge smaller sets into larger ones and have the merging take $O(n \log^2 (n))$ overall.I think this should work but I could be wrong.
•  » » » 14 months ago, # ^ |   +5 fun fact: actually expending queries of type 1 to even not guaranteeing the deleted brackets are paired can still be reduced to the problem you said above
 » 14 months ago, # |   0 Can you solve E1 with MO's algorithm?
•  » » 14 months ago, # ^ |   +6 Yes, here is my code: 142512011
•  » » » 14 months ago, # ^ |   +3 Could you please explain the approach? How does the add/remove function work for this problem?
 » 14 months ago, # |   +12 Cheater in my room. She his/her code for C: here
 » 14 months ago, # | ← Rev. 3 →   -6 The most miserable thing for python users during the contest: Figure
•  » » 14 months ago, # ^ |   0 Exactly, I also faced the same issues. in the end, I had to write the code in C++ ( which has the same time complexity and space complexity as of python code) and it got AC.
 » 14 months ago, # |   +18 A very nice contest ruined with long problem statements
 » 14 months ago, # | ← Rev. 2 →   0 Can anyone help me in problem B,wrong answer at pretest 4Basically selecting minimum difference indices of same character than adding count of elemnts before first appearence and after elements of second appearenceans = x[0] + n — x[1]; Codevoid solve() { ll n, a; cin >> n; unordered_map> umap; for (int i = 0; i < n; i++) { cin >> a; if (umap[a].size() == 2) { int diff = umap[a][1] - umap[a][0]; int diff2 = i - umap[a][1]; if (diff2 < diff) { umap[a][0] = umap[a][1]; umap[a][1] = i; } } else { umap[a].push_back(i); } } int ans = -1; for (auto y : umap) { vector x = y.ss; if (x.size() == 2) { if (x[0] + n - x[1] > ans) { ans = x[0] + n - x[1]; } } } cout << ans << "\n"; } 
•  » » 14 months ago, # ^ |   0 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
•  » » » 14 months ago, # ^ |   0 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
•  » » » » 14 months ago, # ^ |   0 This is the issue I guessLet say indices for a number are 1 3 10 11U will initially store 1 3 then u will ignore 10 as 3-1 < 10 -3 But u need 10 to take 10 -11
•  » » » » » 14 months ago, # ^ |   +7 ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh, bruh marry me
 » 14 months ago, # |   -14 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 = 0$ is tricky. The technique required to solve D0/1 Trie
•  » » 14 months ago, # ^ |   +15 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 $k$, we can make use of this to check whether there exist a pair of numbers whose xor exceeds $k$, and if otherwise we just pick any random number.
•  » » » 14 months ago, # ^ | ← Rev. 3 →   0 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 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 the maxXor function in this solution.
•  » » » » 14 months ago, # ^ |   0 My submission 142523115 was able to pass in 1560ms using set though.
•  » » » » » 14 months ago, # ^ |   0 That is very close to the time limit, so my guess is that you have lower constant factor than my solution did, since you are using printf/scanf instead of cout/cin and also you are using __builtin_clz which I didn't know about before. Thanks for sharing your solution.
 » 14 months ago, # |   0 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.
•  » » 14 months ago, # ^ |   0 Hint — you can take at most 2 elements from a group of unique elements, not 1. Think about it.
 » 14 months ago, # |   0 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...
•  » » 14 months ago, # ^ |   +1 Hope this helps https://codeforces.com/contest/1625/submission/142530775
•  » » 14 months ago, # ^ | ← Rev. 3 →   +5 Let $dp(i,j)$ = min time to reach $d_i$, by removing $j$ signs. Assuming $d_n=l$, the answer is minimum of $dp(n,j)$ over all $j<=k$.Recursion: Consider computing $dp(i,j)$. One candidate for $dp(i,j)$ is $dp(i-1,j) + a_{i-1}*(d_i-d_{i-1})$. But it's possible that we removed the $(i-1)$th sign, so we drove at speed $a_{i-2}$ from $d_{i-2}$ all along, so $dp(i-2,j-1) + a_{i-2}*(d_i-d_{i-2})$ is another candidate. Continuing with this reasoning, and also noting that we could not have removed more than $j$ signs, we get the recurrence:$dp(i,j) = min_{p<=j} dp(i-1-p,j-p)+(d_i-d_{i-1-p})*a_{i-1-p})$.Base case is of course $dp(0,*)=0$.
 » 14 months ago, # |   +1 pretests were deadly :(
 » 14 months ago, # |   0 Why is my solution for C giving WA verdict? 142521905
•  » » 14 months ago, # ^ |   +1 Among all possible (ans, prev) in dp[i-1][j-1], there might be such pair that the ans is bigger while the prev is smaller and it is better to transition from that pair.
•  » » » 14 months ago, # ^ | ← Rev. 2 →   0 Will you please elaborate more? Will this case arise only when temp1==temp2 has been happened previously?
•  » » » » 14 months ago, # ^ | ← Rev. 2 →   +1 4 100 2 0 1 5 6 1 2 3 100 Your dp[3][1] should be 8(5+3, removing the 2nd), because if we remove the 3rd, the ans will be 1+2*5, which is worse.And prev[3][1] will be 3 because the 3rd is not removed. But the best transition is when dp[3][1]=11 and prev[3][1]=2.
•  » » » » » 14 months ago, # ^ |   +1 Thank you Ji_Kuai, I was also struggling with the same thinking what's wrong in it. Thanks to nyet for replying me with the link of this comment.But I am curious, like can't we do anything to this approach to get it better. Like at any (i,j) if we store all the possible (ans,prev) pair and using the one to calculate for further states. Tho it's more complex and inefficient. But can we do that? Will that give the right answer?And making the conclusion that "for calculating some new dp state, the stuff we are using for it must be unique in the sense that that stuff should be only valid stuff for that previous state" is right or wrong?
•  » » » » » » 14 months ago, # ^ |   0 For the first question. It is obvious that for any pair (ans, prev), (a, b) is always better than (c, b) if a < c (the ans is smaller and prev is equal).If we use dp[i][j][prv] instead of dp[i][j] and store the smallest ans, it will be correct(But this will get MLE in this problem).
•  » » » » » » » 14 months ago, # ^ |   0 Okay, one more, Just the last one Ji_Kuai, please! Why can't we make dp[currBoard][prevBoard] storing the minimum time currently on currBoard and the last board taken be prevBoard && maxCan[currBoard][prevBoard] storing the k value when we were there. Now my claim is that dp[currBoard][prevBoard] will update only when currMaxCan is greater the maxCan[currBoard][prevBoard] or when it is not updated yet!My code link -> 142507920
•  » » » » » » » » 14 months ago, # ^ |   +1 I think your claim is correct. But it doesn't mean that you can return dp[curBoard][prevBoard] when curMaxCan is less than maxCan[curBoard][prevBoard].When the curMaxCan is less than maxCan[][], the return value for that should be greater since you can not close as much station as the stored dp value.
 » 14 months ago, # |   +32 Ratings updated preliminarily. We will remove cheaters and update the ratings again soon!
 » 14 months ago, # | ← Rev. 2 →   0 If you were stuck at a problem <=C, Here are the video solutions,
 » 14 months ago, # |   +52 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.
•  » » 14 months ago, # ^ |   +62 for red guys only :)
•  » » 14 months ago, # ^ | ← Rev. 3 →   +1 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.
•  » » » 14 months ago, # ^ |   0 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.
•  » » » » 14 months ago, # ^ |   +9 Yes, there is educational contest, although the frequency is not much. But since problem D is a master level problem (difficulty rating > 2100), I think it's OK to use it in the div 2 since red and orange users are unrated.
•  » » 14 months ago, # ^ |   0 Hello, no, I don't realize that. When I solved this problem, I did not remember anything like that. Moreover, I liked this problem more than all the others I have solved in the original contest.
 » 14 months ago, # |   0 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)
•  » » 14 months ago, # ^ |   +6 These are original statements from BelOI.
•  » » » 14 months ago, # ^ |   0 To be more precise, Russian version of the statements is the original version, and English statements are just translation near to the original. Also, there was partial scoring on the olympiad, but it was removed for Codeforces to allow only full solutions.
 » 14 months ago, # |   0 Video Editorial for Problem C: Road OptimizationI 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.
 » 14 months ago, # | ← Rev. 2 →   0 https://codeforces.com/contest/1625/submission/142524915Want to know what is wrong with my approachMy 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 option1.)either choose to remove(insert index in a set named removed)2.)Ignore and move to next candidateELSE Ignore and move to next candidatefor 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.
•  » » 14 months ago, # ^ |   0 If $a=[1,99,3]$ and $k=2$, do you include $3$ in your candidates? (Clearly, removing both 99 and 3 is optimal.)
•  » » » 14 months ago, # ^ |   0 YES
 » 14 months ago, # |   +19 Here is slightly harder version of problem D. Source: this comment.
 » 14 months ago, # |   -19 printf("Codeforces Round #765 (Div. 2)");
•  » » 14 months ago, # ^ | ← Rev. 2 →   +14 Are u okay?
 » 14 months ago, # |   0 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.
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 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.
•  » » » 14 months ago, # ^ |   +14 You didn't see statements with really long legends :) The problem here is in Russian.
 » 14 months ago, # | ← Rev. 2 →   0 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.)
•  » » 14 months ago, # ^ |   0 Solve dp problems on timus for 3 days straight prior to the contest lol, totally not me
•  » » 14 months ago, # ^ |   0 The simple answer is that if you can't prove your greedy solution, you can't be sure it works. In this case it's reasonably easy to construct a counter-example; in other cases it's more difficult. If you can't prove greedy and you can see a DP solution, it's likely to be safer.
 » 14 months ago, # |   +5 Problem E2 is very interesting! I love this problem.
 » 14 months ago, # |   0 where tutorial? in tourist's stream?
 » 14 months ago, # |   0 Can problem C use Convex Hull Optimisation to solve it?
•  » » 14 months ago, # ^ |   +21 Yes, I solved it with convex hull after the contest.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
 » 14 months ago, # |   +10 thrilling round :) Spoiler
 » 14 months ago, # |   +14 excellent round with strong samples and pretests.
 » 14 months ago, # |   0 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.
•  » » 14 months ago, # ^ |   +11
 » 14 months ago, # |   0 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;Code
 » 14 months ago, # |   +27 where can i get editorials to this contest
 » 14 months ago, # |   -19 Can anyone guide / help / suggest me on how to reach expert (1600+) rating at codeforces...... I am currently specalist.
•  » » 14 months ago, # ^ |   +4 Just try to solve 3 problems in div 2 contest.After the round read the editorial and solve D and E problems.Keep doing this, then you can nearly always solve at least 3 problems in div2 contests.You can be blue even purple then.
•  » » 14 months ago, # ^ |   0 in my experience, you need to consistently solve ABC problems div.2 in 1 hour
 » 14 months ago, # |   0 Could someone please explain why greedy wouldn't work for C?
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 About why greedy is not working on problem C, take a look at my reply: https://codeforces.com/blog/entry/98913?#comment-877347I hope this will help.
 » 14 months ago, # |   +9 Some hints for people stuck at debugging problems C and D.anonymouspegion Input4 5 2 0 1 2 4 1 2 3 2  Expected Output6  Your Output9  CommentThe optimal move is to remove the signs at the index $1$ and $2$, resulting in the signs/cost of $0 \ 4 \\ 1 \ 2 \\$The cost would then be $(4 - 0)*1 + (5 - 4)*2 = 6$.Dev_Manus Input4 5 1 0 1 3 4 1 2 1 2  Expected Output6  Your Output7  CommentThe optimal move is to remove the sign at index $1$, resulting in the signs/cost of $0 \ 3 \ 4 \\ 1 \ 1 \ 2$The cost of travel would then be $(3 - 0)*1 + (4 - 3)*1 + (5 - 4)*2 = 6$._Enginor_ Input3 3 2 1 0  One Valid Output2 2 1  Your Output2 1 3  CommentSince the pairwise $xor$ should be at least $3$, and $a[1] \oplus a[3] = 2$, you violate the constraints.
•  » » 14 months ago, # ^ |   0 @variety-jones Can you please work your magic to show what goes wrong with this submission (failing on test 14). Thanks!
•  » » » 14 months ago, # ^ |   +1 So I'm a personal assistant now? XD. Input3 3 10 9 8  A Valid Output2 2 1  Your Output-1  Comment$10 \oplus 9 = 3$, hence an answer definitely exists.
•  » » » » 14 months ago, # ^ |   0 Apologies if it sounded like I took you for granted. You are the savior!
•  » » » » » 14 months ago, # ^ |   0 No, it didn't. Happy to help as long as someone has put in decent effort to debug the problem by themselves first.
 » 14 months ago, # |   0 Any hint for Problem D
•  » » 14 months ago, # ^ |   0 You can see my solution:-> https://codeforces.com/contest/1625/submission/142628388 I have provided necessary comments to make it easy to understand.
 » 14 months ago, # |   0 when is the editorial? i think beluorusian regional olympiad has it, because for example in russia, we have editorials right after the contest
•  » » 14 months ago, # ^ | ← Rev. 3 →   0 Yes, but we have only Russian editorial now.
•  » » » 14 months ago, # ^ |   0 so u are going to wait for the official English editorial instead of publishing your own?
•  » » » » 14 months ago, # ^ |   -10 There is no such thing as "official English editorial" in our Regional Olympiad, so we need to translate it.The editorial is going to be published today (considering UTC+3). Sorry for long delay.
•  » » » 14 months ago, # ^ |   0 sorry but it's two days after the contest and there is still no editorial.coue any one explain how to solve E2, please?
•  » » » » 14 months ago, # ^ |   0 We hope to publish the editorial today (i.e. before 00:00 UTC+3). Sorry for long delay.
•  » » » » » 14 months ago, # ^ |   0 Thank you for your effort anyway.Can't wait to read the editorial
•  » » » » » » 14 months ago, # ^ | ← Rev. 2 →   0 It's available now. Thanks for your patience.
 » 14 months ago, # |   0 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.
 » 14 months ago, # |   +3 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.
 » 14 months ago, # |   0 Is it possible to do C in O(n^2)?
 » 14 months ago, # |   0 Where editorial ? Where banana?
•  » » 14 months ago, # ^ |   +39 Apparently all their limited time got used up in storytelling about Martians. Priorities, you see.
 » 14 months ago, # |   0 Why is the editorial so slow?