Codeforces Round #850
source link: https://codeforces.com/blog/entry/112291
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.
Codeforces Round #850
Hello!
Welcome to Codeforces Round #850 (Div. 1, based on VK Cup 2022 - Final Round) and Codeforces Round #850 (Div. 2, based on VK Cup 2022 - Final Round) that will start on Sunday, February 5, 2023 at 12:05UTC. Both rounds will be rated.
This round is a mirror of VK Cup 2022 Final — annual programming championship for Russian-speaking competitors organized by VK. VK Cup started in 2012 and has grown to be a five-track competition in competitive programming, Mobile, ML, Go, and JavaScript.
All the problems of Div. 1 round are authored and prepared by me, while KAN authored and prepared two problems for Div. 2. Thanks to errorgorn, irkstepanov, qwerty787788, Merkurev, IgorI, PavelKunyavskiy, izban, Alexdat2000, I_Remember_Olya_ashmelev, Akulyat, mike_live, Ekler, Kalashnikov for making this round better.
You will be given 6 problems and 3 hours to solve them.
The comment is hidden because of too negative feedback, click here to view it |
7 days ago, # | note: the unusual duration for 6 problems |
7 days ago, # | inb4 long wait for the editorial |
7 days ago, # | Note the unusual time (⓿><⓿) |
7 days ago, # | omg lazy editorial round! |
7 days ago, # | Will you post editorial this time? |
7 days ago, # | |
7 days ago, # | stO tourist Orz But I'm going to start school this Sunday. |
7 days ago, # | |
7 days ago, # | I don't know Russian but is it okay to participate and use google translation? Anybody doing it? |
7 days ago, # | I think Benq will not participate in this contest. |
7 days ago, # | Unfortunately,rating should be between 1,900 and 9,999 in order to register for the contest of div1. |
7 days ago, # | Let's go! |
7 days ago, # | Second time seen that there is no thanks to MikeMirzayanov for Codeforces and Polygon platforms,from the same author blog,hoping it never get repeated. |
7 days ago, # | I am really afraid of tourist rounds. This is where my downfall starts |
7 days ago, # | Why this time seperated Div1,2 round though the elimination round was Div1+2? I guess Div1 and the final are the same problem set and some easier problems were added for Div2. |
-
Guess because there is no need to make combined round in this situation. On the contrary, elimination round should indeed be combined to allow div2 participants pass to the final stage.
-
Not really. The only way to pass to the final stage was to make into top 16 of elimination round. Combined round #844 was just kind of mirror of elimination round for CF users and it has nothing to do with official tournament (except the same problems). And the question from physics0523 was why the author didn't repeat the same approach for today's contest, but decided to make two separate rounds based on finals instead of single combined round.
-
-
Why this time seperated Div1,2 round though the elimination round was Div1+2?
Final round problems are heavily focused on very strong competitors, so giving the same problemset as combined round fot both divisions didn't make any sense.
I guess Div1 and the final are the same problem set and some easier problems were added for Div2.
That's exactly what happened :)
7 days ago, # | Hope this won't be an overrated round again from tourist |
7 days ago, # | Ahh yes a short announcement concisely thanking all people responsible for the betterment of the contest and that amazing chad energy coming off from the announcement. Is it possible this is a tourist round? |
If no mention of interactive problems is made, does it always imply that they will not be present? |
7 days ago, # | my first div2 contest. hope to solve at least 2 problems |
7 days ago, # | Great, Another Cock and ball torture!!!!!!!! |
7 days ago, # | This round is going to be difficult) |
7 days ago, # | First time to take part in div1 only round, in which problem A could be as hard as problem D in div2. Perhaps I'll not be able to solve any problem. |
7 days ago, # | Do take note of the unusual time of the contest. |
afk btw i' |
7 days ago, # | Yet Another tourist round |
6 days ago, # | Will it be codeforces mode or ICPC mode? |
6 days ago, # |
|
6 days ago, # | Finally a contest on a convenient time. It will be at 5pm for me. |
6 days ago, # | I forgot the unusual start time, I guess this will be a no-sleep-forces round for me :') |
6 days ago, # | omg Lantern Festival round! |
6 days ago, # | what about Score distribution ?! |
6 days ago, # | I don't know about tourist, but one piece is real! |
6 days ago, # | Let us enjoy the contest without thinking much about ratings changes.Hoping to do atleast 2-3 problems. |
The comment is hidden because of too negative feedback, click here to view it |
6 days ago, # | Candidate Masters in div 1 will be cooked |
6 days ago, # | The time of the round is perfect for Chinese participants. Usually the codeforces rounds start at 22:35 CST (UTC+8), and I have to stay up late to participate. This round starts at 20:05 CST, which is much better. |
6 days ago, # | No score distribution again! |
6 days ago, # | Hoping for 18 plus points... |
6 days ago, # | Yup it's Tourist round and i have accepted my fate here (Don't have good past experiences despite of problems being too good). |
6 days ago, # | Guts Feeling, It will be a hard round. |
6 days ago, # | Did you do it on purpose or accidentally? |
6 days ago, # | While attempting problems you can feel that this is tourist round. |
6 days ago, # | BORING CONTEST I QUIT |
6 days ago, # | Div 2 Speedforces |
6 days ago, # |
|
The comment is hidden because of too negative feedback, click here to view it |
6 days ago, # | Present passed 1A and 1B for 30 minutes, then sitting for 2.5 hours. So painful tourist round. |
-
well I spent about 1.5 hours on 1B and when I saw 1D I thought I should solve that problem in the first place instead of 1B. My solution to 1B is horrible and I rewrote my code twice, once because of my algorithm is incorrect and the other because I got sick of the rubbish code I had written.
-
So I'm really interested in how to solve 1B so fast.
-
I used six vectors to maintain the indices with a more and without a .
An element in and an element in could be erased in one exchange. This type of exchange can be applied as much as possible. Then there remains only tuples shaped like , each of which can be erased in two exchanges.
It's not so hard to implement =)
-
Hi, can you help me prove why this strategy is optimal regarding number of exchange times?
-
It is easy to see that we would only transform two elements shape like and into , or simply erase two elements and , where are different letters. One exchange will decrease the total number of elements by or . So one can just maximize the number of exchanges of and .
If there are elements and but we don't exchange them, then we will exchange and to and , respectively. Obviously, it's worse than simply erase and with one exchange. So if there are elements and , we can just erase them.
If there isn't a pair of elements shaped like and , there are the same number of elements . We can only transform into since are equivalent, and then erase and with one exchange.
-
6 days ago, # | This round was a bit unbalanced. At least for div2 When 766 participants solved C, D was solved by 1 When 143 participants solved D, E was solved by 5 |
6 days ago, # | just thought about problem B Seems like binary search but I still don't know why it didn't work and give me tle I wonder if the complexity I guess is nlog(w — h) where the worst case is nlog(100000) I create coordinates by a[i] + w and a[i] — w, b[i] + h and b[i] — h. First I put the first cake and first dispenser on the same x first coordinate then move only the first dispenser and check all n other ones if it fits. If one dispenser needs to move on the right and one on the left, it would be a no. Otherwise, if only one dispenser needs to move right, "lo = mid + 1", if only one move left, "hi = mid — 1", if none move, then it would be a yes. Btw my Eng is not too good so hope you guys understand. |
Speedforces or Implementation-forces |
Spent 3 hours and only solved the problem A of div1. Game Over. By the way, as a former HearthStone player, problem A and C are pretty familiar for me. Update: Now I've find a easy solution for div1B/div2D (look at this comment ). Very easy to implement but I've not come up with this idea for 2.5 hours. Although it's logic is easy, I've used over 100 lines of code to implement it. Code (Now this code has got AC) |
-
For This, I guess my logic is same but there is actually no need to harcode stuff, though It is something very tedious. Here is my code 192350442
6 days ago, # | Finally -100 :-) |
6 days ago, # | I got a thousand of WA and I wanna kill myself!!! |
6 days ago, # | Is D graphs or just super ugly implementation? Or both? |
-
I used a super ugly implementaion with upto 30 lines hardcoded data.
I don't want to solve problems like this again.
It seems that here's a pretty good solution with graph theory:
build a three-node graph. when it's 'wwi', link w to i, when it's 'www', link w to i and w to n. and so on.
Finnally match edges with same endpoints but different directions firstly. then cycles with length 3 remain.
-
I've simulated this approach for some example cases. Maybe we should add an adge pointing from a "extra" char to a "lack" char, for example, "www"-->(w->i),(w->n), "iiw"-->(i->n), where (char1->char2) is an edge pointing from char1 to char2.
Then we would get a directed graph with nodes {w,i,n}, each node has equal in-degree and out-degree. We can regard a exchange as cancelling 2 edges with same nodes and different direction, like (w->i),(i->w) --> nothing; or merge a path of 2 edges into 1 edge, like (w->i),(i->n) --> (w->n). We need to store the index of people in edges. To achieve the minimun number of operations, we need to use as more the first operation as possible. Therefore, first we cancel every pair of (w->i),(i->w) until one of them runs out, similar for (i->n),(n->i) and (n->w),(w->n). Then if there're edges remained, by the property of in-degrees and out-degrees, they must form some cycles like (w->i),(i->n),(n->w), or reversely, (w->n),(n->i),(i->w), we need to do 2 operations for each cycle.
-
6 days ago, # | I hate the ROUND.... Unusual and confusing 1B and 1C... |
6 days ago, # | time for tourist to settle down. |
6 days ago, # | this was the first time i saw an easy version and a hard version as a different problem code (the letter thingy) |
6 days ago, # | Is Div 2 D just a case work or is there a elegant method? |
6 days ago, # | wow, my first div1 round and I havent lost 100+ rating))) btw could anybody please tell how to solve 1C & 1D? |
6 days ago, # | Predictor: my (now). DON'T FST!!! |
6 days ago, # | If my solution failed for a HIDDEN PRETEST, (like Pretest 2), how much time after the contest can i see that testcase? Because the contest has ended, but I cant see the testcase which went wrong. |
6 days ago, # | very hard problems |
6 days ago, # | Does the problem 2D involves case work on bitmask? or this is graph problem? |
6 days ago, # | Really interesting div 1 contest, thanks! |
6 days ago, # | Why did you put a trivial 12D DP (= easy idea, looooong implementation) as Div1E? It's not funny. |
6 days ago, # | Was Div1C a seg tree + binary search (based on the idea that after some time some numbers are fixed)? I could not come up with easier solution. |
6 days ago, # | C was too hard for me ;) |
6 days ago, # | Please give some hint how to solve problem 2D. |
6 days ago, # | my suggestion after this,1782,1561: avoid vk cup rounds for boring implementation problems and random performance |
6 days ago, # | why I am not able to submit solutions, it says contest is over even though 80 mins are left? Is it so that you have to participate in initial rounds so as to participate in the Final Round? It does display System Check is Pending. |
I just wrote the ugliest code of my life for problem D (B for div1): 192346636 Didn't really like this problem, and C was too easy, it should have been B. Other that these, I enjoyed the contest, although I would have loved to have time for E :( |
Especially liked F |
6 days ago, # | My worst performance in a while T-T |
6 days ago, # | My username is pretty much how i felt during the entire 3 hrs.Last tourist round for me. |
6 days ago, # | So when will system test begin? |
6 days ago, # | C, D and F are interesting, E is quite standard, and B is too hard for me. |
-
How t solve 1D?
-
You do a dp of size , where number of ways that the number leads (is the highest value) a group of size , and will lose all matches after this. Solve this dp top down.
Here's a snippet of the solution
Codecouldn't get ac because coded too slow... :(
-
If problem setter is tourist, We expect better Contest, but I can say, this is the worst contest, I have ever given. Respect to tourist but Worst Contest ever seen... Mainly Problem D |
6 days ago, # | where editorial? |
6 days ago, # | Cool round!)) |
Can anyone explain to me how to solve problems E and F on Div2? Thank you so much. |
6 days ago, # | is this approach correct for B? align the first cake with the first dispenser, such that a1-w=b1-h, then for the rest of n-1 cakes check if you can move them to the left by less or equal to (a1+w)-(b1+h) so that they are aligned with their dispensers, if ever needed to move the cake to the right the answer is "no" otherwise "yes" |
-
For me, I shifted every cake by the same amount . Note that . This means that . So iterate over every and check that there is some that satisfies all the conditions for all by maintaining an overall lower bound and upper bound of the possible values of . Clearly, if the lower bound required to satisfy the conditions is larger than the upper bound required to satisfy the conditions, then there is no such , so the answer is no. Otherwise, the answer is yes.
Was div2D ugly implementation?? There was a huge gap no of solves for b and d. I have no idea how to even start approaching D |
-
My solution of D is a very ugly implementation
-
Can you tell your approach? I thought this was similar to the question where we had to distribute equal number of ones among all rows, but just with 'w','i' and 'n'. But I had no idea how to implement it, if it even is correct in first place
-
I tried using bit-masking (coding needs and excesses as bits, 64 possible states in total, the first 3 bits for needs of w, i, and n and the other 3 for excesses). The observation I made was that there can be only 2 kinds of moves, i-j and i-j-k.
My implementation however got the better of me considering there were 9 unique cases in total, the code could have easily exceeded 600 lines if I had continued, lol.
Could you share your approach?
-
6 days ago, # | One of the most unbalanced rounds (Div. 2) in a while. |
Any hints / elegant approaches on solving div2-d? |
-
Idea
-
If I understand correctly, all the people are nodes and an edge is connected between someone who needs and has excess of the same letter? In this case why can't the size of the cycle be more than 3?
-
For cycle of length 2: If suppose person needs and it has an extra and if the person needs an and it has extra , we can perform the swap and both will be satisfied in 1 operation. We can do this for all possible combinations of letters.
For cycle of length 3: If suppose person needs and it has an extra and if the person needs an and it has extra , and if the person needs and it has an extra , we can first perform the swap between and person so now person needs and it has an extra , then we can perform the swap between and person. So all three will be satisfied in 2 operations.We can also do this for all possible combinations of letters.
-
-
6 days ago, # | Here is a problem with same idea as today's Div1B/Div2D in case anyone is interested. |
6 days ago, # | Problem D writing a perfect code, to getting RE on test 19 Reason: I wrote an assert statement to debug the TLE cause in the local machine Locking the problem and realizing I can't change this |
6 days ago, # | Is div1-A's sample2 made by tourist himself?? I'm astounded him using Japanese internet meme how did he know that??(I know that it's well-known in Chinese...) |
-
I don't get it.
-
the second testcase is
4 1 5 4 1 1
and rearranging it we get1 1 4 5 1 4
.
-
6 days ago, # | Why i can't upsolve? |
6 days ago, # | omg tourist round!!! |
6 days ago, # | In DIV2 C, the only observation is that we should perform the query of 2 as the last move, right? **Proof : ** Let's suppose we make a "chain" of 1, 2, 3, .., x and we have some element remaining y(y > x + 1) then after the operation 2 we'll be left with only y — x and if we'll need y — x type 1 operations now but if had we made it x + 1 earlier then y — x — 1 type 1 operations would've been needed lemme know if something seems wrong. |
6 days ago, # | How to solve the "Letter Exchange"? |
6 days ago, # | my first div2. really good |
6 days ago, # | 1B's implementation is too horrible. I think there is no need to output the sequence of exchanges, it does no good but making this problem a lot more difficult to implement. |
6 days ago, # | Tgod!!!i love you.This is my first time to reach the top 600. |
6 days ago, # | Excellent Contest,Thanks for Tourist Cooperation For this Wonderful contest And especially for the first 4 problems |
6 days ago, # | amazing round! |
why my submission page is not loading? When I am opening the page it shows Your text to link here... . This happened after the contest. |
6 days ago, # | Can anyone see their rating changes using any rating predictor? |
6 days ago, # | Why my solution for the problem B get tle is only O(2*n) I think is too closed time. The problem is that solutios work in real contest 192310034 |
6 days ago, # | for Problem : Div1B / Div2D My idea is to first just ignore all strings that are perm of win. Then i tried to group the pair's that combindely take 1 swap (wwi <-> nni, wwn <-> iin, wnn <-> iiw). After this for all the strings that are left either 1 swap or 2 swaps required. On every iteration we can convert 2swap string to 1swap string and 1swap string to perm of win. I didn't code this because of lack of time and implementation would be bigger but is my approach correct? |
5 days ago, # | Finally! pupil. lot more to go, my goal is to become red. wish me luck!!! |
5 days ago, # | What is the point of testcases where the same input is repeated 50000 times? And how to deal with TLE arising in these test cases? |
5 days ago, # | |
5 days ago, # | nice round. The problems are interesting that I didn't stop coding and thinking last night. |
5 days ago, # | Can someone explain this testcase for div2 b to me? 3 10 25 7 23 27 The correct answer is NO but aren't all cakes getting chocolate and none is spilling over? The dispenser at position 7 gives chocolate to the cakes at position 3 and position 10 and the dispensers at 23 and 27 give chocolate to the cake at position 25. |
5 days ago, # | 1B can be done by brute force.Here's my ugly code code |
-
My brute force solution with less ugly code and less time :)
-
Is there any elegant solution for 1B/2D is present which handle all the cases without writing explicitly if else conditions?
-
Well, you can look at my submission
https://codeforces.com/contest/1786/submission/192325004
It is still ugly though but at least solves this issue with ifs
-
-
5 days ago, # | Hello Friends!!! |
5 days ago, # | Short and easy implementation for div.2D, only 30 lines of processing needed, using the same idea of detecting cycles of length 2 and 3: Press me |
5 days ago, # | Oh, by the way, this round put the ♰tourist♰ back in first place! |
5 days ago, # | Can someone please explain me Solution of B problem div2 , because I don't get the logic while seeing other code |
-
b'_i=b_i+x
a_i-w<=b'_i-h
a_i+w>=b'_i+h
a_i-(w-h)<=b'_i<=a_i+(w-h)
(a_i-b_i)-(w-h)<=x<=(a_i-b_i)+(w-h)
if max(a_i — b_i) — (w-h) <= min(a_i — b_i) + (w-b) : "YES" else : "NO"
i got idea from his code : https://codeforces.com/contest/1786/submission/192315809
5 days ago, # | I really like 1C. But 1E is just stupid implemention. |
5 days ago, # | |
5 days ago, # | Nice D task, thanks |
5 days ago, # | Am I the only person who did binary search in div-2 B ? |
-
I also thought of binary searching for a value in range that we are going to add to every and see if every is OK. But it turned out that I don't know binary search so I started making another solution and wrote AC code 5 minutes after the end of the contest.
-
I did bs on first cake's position ,
then if for some i — i th cake is getting past i th dispenser then answer is on the left if it exists and right if no cake is getting past its dispenser and some haven't reached its dispenser
otherwise I have answer
192329929 Here's My Binary Search Solution
-
5 days ago, # | When will editorial be released? worthy of being tourist XD |
5 days ago, # | I keep getting runtime error of status access violation . I don't know what's wrong in my code, it runs fine on my compiler. https://codeforces.com/contest/1786/submission/192349129 |
-
I don't know why it's not working but it seems to be working on cf if you use C++ 20. After trying to debug it for a bit it seems the problem is in this line.
vector<pair<pair<char,ll>,pair<char,ll>>> while(a[i]<b[i]) { cerr << a[i] << " " << b[i] << "\n"; if(ab[a[i]].first != ab[b[i]].first)
It seems the stderr is 0 4294967295 which is wrong, locally it gives me 0 1.
3rd edit:
This was the problem. Since ab, bc, and ac was empty 0 — 1 would equal 4294967295, casting it to int fixes this problem.b[0]=int(ab.size())-1; b[1]=int(bc.size())-1; b[2]=int(ac.size())-1;
4th edit:
If you want the compiler to warn you about this in the future add this flag on compilation -Wconversion.5th edit:
I would recommend these flags https://codeforces.com/blog/entry/79024 since -Wconversion can be excessive sometimes.
Solution idea of div1D/div2F: First, WLOG we can assume we arrange the tournament in such way: In every matches, the left player wins. We can achieve this by doing the following operation to the binary tree of the tournament: for each non-leaf node of the binary tree, if the winner of this node is its right child, we "flip" this node by swapping its left subtree and right subtree. Since fliping doesn't change the winner of each match, this will not change the "wooden spoon", and after this operation, the "wooden spoon" is the right-most node. Since there are nodes in the binary tree, we can merge situations into one by this operation. For example, we can do operation to this tree: _________1 _____3_______1 -__5___3___1___2 __7_5_3_6_1_8_4_2 --> _________1 _____1_______3 -__1___2___3___5 __1_8_2_4_3_6_5_7 Where (the left-most node) is the champion, and (the right-most node) is the "wooden spoon". Then we assume the right-most node is k, and there's different arrangements (after operation). If is the -th smallest element in the right half of the tree, then we have ways to arrange the left half, and ways to arrange the right half (since is also the right-most node in the right-subtree). But in how many ways we can distribute elements into halves? Well, since is the left-most element, there are elements we could put in the right part (which are in the range ), and there are actually elements of them in the right part, so we have ways to choose them. Similarly, we have ways to choose elements from . Therefore, we can get such formula: Then we can calculate them by FFT. The answer is Code example |
-
Could you please elaborate on how to set the coefficients of the polynomials to get the result after the convolution for each ?
I'm struggling with the binomial coefficients, they seem too dependent on the pairs
-
In fact, , so you can rewrite the original formula like this:
This formula contains a term of convolution. We can calculate the convolution part first, and for each terms of the convolution, we multiply the terms containing k on the left.
-
-
I have similar formula, albeit no nested sum involved. Is it possible to calculate dp[n][k] without summoning monsieur Fourier?
-
Maybe you can look at this comment.
-
4 days ago, # | Still Waiting:( |
4 days ago, # | Can anyone explain Div2D to me, please? Thanks. |
-
First you count all the distinct characters in the strings of each individual. If all have 3 distinct characters then you print 0. Else then you see all the permutations of 3n characters possible among n people like they could have been www, iii, nnn, iiw, iwi, wii... and etc etc. Then for each such strings where you don't have 3 distinct characters you store them in a map<pair<char,char>, set> like in pair u store the characters to be replaced with what and in store you store the person who wanna exchange. Like mp['i', 'w'] will contain set of people who want to exchange 'w' with 'i'. Then after storing them you take two inverses together like mp['i', 'w'] with mp['w', 'i'] and inverse them until one becomes 0 and similarly for any another pair. Then you will see two types of cycle. Do same procedure in that cycle CW and ACW. Store them in a vector. And print the answer. You can see my submission for the reference. During contest I wasn't able to see the two cycles and only considered one. Have a good day:)
4 days ago, # | chronological order threw me off, i don't know why but i thought lexical order and kept on sorting my answer! |
4 days ago, # | Does anyone know when the tutorial will arrive? |
3 days ago, # | Can Someone please give an idea on how to solve Div2 E problem (Monsters: Hard version) |
-
This Chinese guy has a super good explanation and drawing here. You can try to understand it using your smart brain and some translation tools.
My implementation is based on his idea.
-
-
You might first try your best to read it, and if you have anything difficult to understand, you might contact me again.
-
-
3 days ago, # | Can anybody help me find why am I getting WA on this submission for Div2-C. I don't know maybe there is something silly that is escaping my eye, in which case I'm sorry. But, I just can't figure out where am I getting WA. (can't see the test case either). |
My code for question A1 has been plag[submission:192289748]iarised falsely with someone else whom I don't even know. It was a pretty simple question and it was just a near coincident that my solution coincided with that person. @MikeMirzayanov |
38 hours ago, # | Where is official editorial? I want to see solution of Div2-B |
Hey MikeMirzayanov I got a plag message for 1786B for my solution 192337404 but other than making an array of the differences I fail to see how it is similar to 192329389,192335667,192338432. Is there any other solution for div2B because this was just a simple code I did by seeing and analysing the test cases. Can you please look into it |
20 hours ago, # | I misunderstood problem B initially during the contest and I'm currently wondering if the "modified" version I understood can be solved. It's the same problem but with a small twist, you can make any cyclic shift to the cakes assuming that the conveyor's length is not infinite (assume that the conveyor's length is at least ** means maximum element over all elements in the array , similarly , etc. |
4 hours ago, # | I can not participate in this contest but I hope others will get a good delta |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK