Hi Codeforces,
We're excited to invite you to Codeforces Round 809 (Div. 2), which will take place at Jul/18/2022 17:35 (Moscow time). All problems were created and prepared by lunchbox, lce4113, and me. It will be rated for all participants with ratings lower than 2100.
Thanks to the people that made this round possible:
- IgorI for coordinating the round, patiently guiding us through the preparation process, and translating all statements to Russian.
- KAN, for guiding and assisting IgorI in the coordination.
- Apple_Method, izhang, lethan3, moo., null_awe, and ezraft for proposing problems that didn't make it to the final version of the round.
- PurpleCrayon for feedback and suggestions in the early stages of the round.
- Our testers, for their time and feedback: EnDeRBeaT, Queue, AlperenT, FairyWinx, ak2006, TheScrasse, sus, SirPh, litesam, asrinivasan007, Igorbunov, Runtime-Terr0r, timreizin, and Aaeria.
- MikeMirzayanov for the excellent platforms Codeforces and Polygon.
You will be given 2 hours to solve 5 problems, one of which will be divided into 2 subtasks. The scoring distribution will be announced later.
UPD: The scoring distribution will be $$$500 - 1000 - 1250 - (1000 + 1250) - 2250$$$.
UPD2: The editorial has been posted at https://mirror.codeforces.com/blog/entry/105008.
UPD3: Winners
As a tester...
As a contestant ...
As a man...
As a person...
As a coder
As a developer
As a shit
As a human...
As a as
As
a
As a loser
As a massive fan of hugs, cosy blobs, and the problem-setting team, I am looking forward to the contest!
As a tester, tester is just a premutation of setter
Damn
As a contestant, contest is just a prefix of contestant
As a useless problemsetter, I hope you enjoy this round!
As a contestant, waiting for the score distribution...
As an author, BucketPotato orz.
BucketPotato round orz
BucketPotato orz.
As a tester, I can confirm that the problems are very interesting and would recommend everyone to participate in the contest.
Can I have your upvotes please?
So you want to say I won't loose cm first round after I reached it? :thinking:
Congratulations for CM!
Yeah, hopefully you will not lose CM just after you reached it.
Thanks, then I'm like 2 times calmer to participate xdd
BucketPotato hard carry orz
As a tester this round is extraordinary
Take it or BucketPotato will come to your house and enact his revenge
As a CFer, BucketPotato orz
Seeing sus as a tester makes me feel really excited about this round!!
Through the last two competitions, I have reached “pupil”. I hope my rating can reach 1300 in this competition!
Can anyone tell me how to become a tester for cf contest? What are the criteria for it ?
How to become a CodeForces tester 101:
Step 1. Become friends with some setters
Step 2. Profit
How to become friend with some setters?
Seduction works
Unspoken rizz
I don't know how to seduce :( probably just gonna make myself an e-girl
As a contestant I hope I can become Specialist
as a contestant I hope I can become expert :D
Nice we are far 31 exactly. Good luck today!
good luck <3
BucketPotato orz
I hope this Div2 gets easier!
Good luck everyone. I hope this round is easier than the last round.
Ahahahahhahahahha. U made my day, get like XD
Ahahahahahahahha
hhhhhh
Best of luck everyone! Lets's give our best in this contest.
Ok but please stop cheating
:pkinghi: BucketPotato Orz. Master of hugs.
You will be given 2 hours to solve 5 problems, one of which will be divided into 2 subtasks Can someone explain what divided into 2 subtasks means.
I think we could have same two problems with different constraints as b1 b2 for example
It doesn't always mean different constraints. That means we will have 6 problems, but two of them will be very similar.
as a participant I am participating
I hope all participants will write this round good! I also wish good luck everyone!
I hope this is a Codeforces round and not a Mathforces one.
As a Rating-rapid-decline-er, I hope I can enjoy this round.
As a Master, I hope today is not still a Candy Date.
Candydate Master orz
Hope there will be more contests in the near future <3
I think codeforces have best userInterface amongs all comptetive coding platform.
Scoring distribution when
It's time for Pupil :)
Good luck
How do I become a tester?
for proposing problems that didn't make it to the final version of the round. XD XD.
hoping not to become pupil again
Looking forward to this round! After this round, I should become green.
I like B.
What's the backstory of naming D1 as Chopping Carrots?
Originally, the statement looked something like this (this is a very condensed version of it):
The flavor text was ultimately taken out since testers found it made the statement more confusing.
B is way harder than C to me.
B is greedy
How? I see only dp solution.
How can you please explain your approach?
difference between index of 2 same colors should be odd so that we can put them in same tower
We need to have odd distances between indexes of each frequency to build
Yes, wiered named friend, but how is this greedy?
The dp is more or less simple:
It's dp because you solved it using dp and its greedy because I solved it using greedy.
How to solve D1?(Just some hint)
Fix the maximum (or minimum) element.
https://mirror.codeforces.com/contest/1706/submission/164793681 I did that! But WA on pretest 3 :(((
The minimum element is not necessarily of the form $$$\frac{a[0]}{j}$$$...
Take a look at Ticket 15890 from CF Stress for a counter example.
I got TLE by doing that but may be inefficiently. I stored all possible values for a number in a 2-D array and iterated 1 to 3000 fixing it as maximum and got maximum possible number of each element less than fixed maximum using binary search!
How did you do that?
Is the main idea for $$$E$$$ to maintain a DSU and for each 'root' node mantain the set of intervals covered and then merge them appropriately?
This wasn't my approach. I used DSU with small-to-large merging to find the earliest time at which vertex v is connected to vertex v+1, for all v. Then, queries can be answered by storing these times on a segtree and storing the maximum values within the range [L, R-1].
This is exactly what I did, only difference is I used when v is connected to v-1.
That was what I thought of during contest (164782058), but realized only after that a much simpler solution exists.
Hi, I have a hard time debugging my code. For example, today's Div2D1, I felt I had made it but then I had WA on pretest 3 and I couldn't debug fast. Here is my submission. https://mirror.codeforces.com/contest/1706/submission/164793681 Any tips on fast debugging? Thanks!
Take a look at Ticket 15890 from CF Stress for a counter example.
In problem C when n=6 there will be 3 possibilities right (2,4) or (2,5) or (3,5)?
if n = odd, it becomes trivial. If n = even: For every tower we want to make cool we can pick it up from 2 array:
1) 2,4,6,8,... 2) 3,5,7,9,...
Suppose you pick i from 1) then you need rest (n/2-1-i) from 2). Just iterate over i and take the min.
I saw many guys use dp to solve problem C, i don't know why. The problem description says "maximize the number of cool buildings."
I think we have 1 option for n % 2 == 1, and 2 options for n % 2 == 0.
n == 6 is a special case and has 3 options.
So what I missed?
You can "skip" a building in case of n % 2 == 0
Consider the case of
10 9 7 7 7 7 9 10
"odd" and "even" options use 2 + 1 + 3 = 6 floors
10 (9->11) 7 (7->8) 7 (7->10) 9 10
10 9 (7->10) 7 (7->8) 7 (9->11) 10
while optimal solution
10 (9->11) 7 (7->8) 7 7 (9->11) 10
uses only 2 + 1 + 2 = 5 floors.
If n is even: For some building x, choose all odd indexed in the left to x, and all even indexed buildings to the right of x. So there is a gap of two non-cool buildings near x.
10 9 7 7 7 7 9 10
0 1 0 1 0 1 0 0
0 0 1 0 1 0 1 0
there are only two options, right? I need an example which has more than 2 options except n == 6, cause (6 — 2)/2 = 6-4
3 options:
01010100 (6 floors)
00101010 (6 floors)
01010010 (5 floors)
Easier Div2?
Linear memory is intended I think. My submission with $$$3n$$$ integers on a BST (instead of heap) only used 6MB, so if anything I think it could have been 32MB
Agreed re: D2. The process of solving D2 was very unpleasant for me--I came up with/recognized the main observation in <2m, then took the vast majority of my time dealing with the memory optimization. In particular, because $$$\sum a_n$$$ was unbounded, my approach to optimizing the memory was dependent on the fact that the number of tests was small, as it leads to a time complexity of $$$O(n \sqrt{n}) + a_n)$$$ per test case. The problem is solvable in linear memory, but the process of optimizing to linear memory is not at all interesting, and the linear memory solution doesn't feel any more clever than the $$$n \sqrt{n}$$$ memory solution.
Sorry for the trouble, there is a $$$n \sqrt n$$$ two-pointers memory solution in D2 that we wanted to cut off. We decided it would be fine since all of the correct $$$O(n)$$$ memory solutions (from testers, authors, and the coordinator, including in Python and Java) use less than 1/6 of that memory without any optimizations.
As for the difficulty, there was originally a problem F, but testing suggested that up to E was hard enough.
My O(n) memory solution requires me to change std::vector to std::list, or free the memory of std::vector correctly (.clear() doesn't free the memory).
It's a bit annoying. :(
I also MLEed once due to clear().
Sorry to hear :(
Our correct intended solutions take some more thinking, but have clean and easy implementations (no optimizations needed).
So I guess the difficulty of this task was in, do you want to optimize your code or think of a cleaner solution?
I believe the core idea of mine (the one changed to std::list 164802621) and the posted solution doesn't differ a lot. (to me, it's just some computation order)
Are there any more clever solutions?
I know knowing the programming language I used is also a part of CP, but just don't like it to be kinda the only point of a problem.
btw, what do u mean by optimizing my solution?
Anyway, other problems are not bad.
Thanks for the contest!
The main idea is the same, but the way you go about it is different:
Your solution uses a
vector<list<int>>
to help determinecmx
(using variable names from your code), and has to update the lists as you sweep through.The intended solution also finds all values of
cmx
, but uses the additional idea of prefix maxes on increasing functions to simplify the memory usage to a singleint pf[100000 + 1]
.I had MLE with vectors too, but during contest I forgot about std::list and wrote custom (164757358)
Changing vector to list in upsolving gives AC but sadly it is ~9x times slower than custom (164886835)
I was using a linear memory solution, but it was using
vector<vector<int>>
and the memory still blew up and used > 64 MB.Then I learned that
.clear()
does not necessarily reallocate to make the capacity back to 0. To "force clear" a vector, one can usevector<int>().swap(x)
I also agree about seeing C somewhere. I did try spending a little bit of time looking for it, but ended up not finding anything. I don't know how similar the problem I remember was, but it involved this idea of a[i] > a[i — 1] and a[i] > a[i + 1]
https://mirror.codeforces.com/contest/1698/problem/B from round 803 is based on the same basic idea but asks a different question about it.
wow, memory limits in D1 are divine. I submitted with O(n*3000) time, using 2d arrays, but it got ml. I changed algorithm for 2d arrays to 1d, and it passed. 5 incorrect attemps, rest in peace. But i had to gain only 4 points to reach CM
164778279
Is it Div.3?
No.
Did you know participating with alt account is forbidden in codeforces?!
I think my solution to D2 only uses O(N) memory, but still can't pass TC11.
upd: std::vector is so hard (.shrink_to_fit() is stupid)
In the end, I solved three problems, which made me very happy. But how to solve D1?
I think you fix either the max or minimum value and use brute force, but I didn't solve it, so I'm not too sure.
Yes, but instead of brute force use two pointers.
Video Solution for Problem C.
I did pretty much the same thing.
Here is my submission:164775959
Can anyone give me a fail-case.
long long ans
1
10
5 5 6 6 1 8 1 4 5 1
5
3
I think the input constraints in problem D2 are really confusing. Why those $$$O(n\sqrt n\log n)$$$ solutions can get pretests passed but a $$$O(A\log n\log A)$$$ solution (my idea) can't get PP (only $$$\sum n$$$ is $$$10^5$$$ but $$$\sum A$$$ isn't) so I wasted a lot of time on this problem and I didn't solve problem E (or even carefully read the statement) which I found a solution just 5 minutes after the contest.
Anyway, good contest & problems, hope the next round will be better.
If $$$n=100000$$$,$$$\sqrt{n}\approx320$$$,$$$nlog^2n \approx 256$$$,but the constant of segment tree is so big that it is greater than $$$320$$$ after multipliying $$$256$$$.
I used DSU to get when each point is first added to the connected graph, and then use segment tree to query the maximum values within the range [L+1, R].Why I couldn't get a accepted?my submisson
that's not correct. Added to connected graph does not mean connected to previous node.
Thanks!
I used Overall dichotomous( $$$O(n \log^2 n)$$$ ) ,but TLE on 4. Am I wrong ? mysubmission
I think the most difficult problem in this contest is at most *2200 :(
so it like div.3.
we heard you the first time now shut up jesus christ
Maybe most difficult one idk about that, but A, B and C's are not far from expected div2 difficulty
D seems to be an easy one but when I started I found it a bit complicated :)..
Why problem B Complexity: O(n) can not pass?164782973
I had same issue (but with Golang, not Java). I had to change standard output (fmt.Println) to bufio Writer. [Solution_1 TLE, Solution_2 AC]. It might have something to do with bufferization.
yes, this is ok 164798975
Well, problem E is better to be put in an edu round. And D2 is a totally trash problem I think.
Sorry to hear. What did you dislike about D?
Too difficult to implementation.
just about 10 lines except for careful memory management. Where is difficult?
Hi, the intended solution codes for D2 have now been posted (here and here). IMO, the implementation in both is very clean and easy, no optimizations needed.
As I said in a different comment, the difficulty in this problem seems to lie on whether you want to painfully optimize a simple idea or think a little more to find a nicer solution.
It says "you are not allowed to view the requested page" when I click on 2nd link(/here).
Sorry, the link has been fixed
Thanks for the contest!Awesome problems especially B,D2 and E!
First time to AK a div 2 contest!
Is the below statement true?
for integers a and p, where 1<= p <= sqrt(a) . floor(a/p) is unique.
Proof if any?
How to get unique elements of
a/p
for an integera
andp <= k
, efficiently for problem D2?Iterate over segments:
start with
[1, 1]
then next for
[l, r]
will be[r+1, a / ( a / l )]
in each segment
a // i
is constant(l <= i <= r)
.Thank you very much. And are the number of unique
a/p
s around sqrt(a)?, if we consider k as infinity.I wanted to calculate time complexity.
There will be no more than
2 * sqrt(a)
such segmentsFirst part where
r <= sqrt
havel = r
In second part
a / p
=sqrt ... 1
Ratings updated preliminary. As I said here: https://mirror.codeforces.com/blog/entry/104766?#comment-932270 cheaters will be removed later.
thx for specialist-1... im totally fine after today's contest
div2.5
I'm sorry I missed the fight
How to become stronger quickly
Problems were somewhat hard in this contest.
Life is not easy as you are thinking.
Could anyone have a look at this code?
https://mirror.codeforces.com/contest/1706/submission/164815320
The solution got TLE before I added an early exit trick, then it got AC, I have no idea why. It seems that the early exit trick is wrong. So is the data too weak or the early exit is actually correct?
why are you glorifying this shenanigan by calling it a "trick"
Is the word trick kinda glorifying? I don't think so.
And, if actually it can be proved at most a certain amount of updates lead to the minimized answer, then it's not a shenanigan. This is also why I am asking here. I'm not able to construct a case failing the solution.
Besides, early exit is sometimes useful in OI competitions.
For problem B:
I used std::vector and got TLE — https://mirror.codeforces.com/contest/1706/submission/164907546
I changed to normal arrays for the same solution and got AC — https://mirror.codeforces.com/contest/1706/submission/164916818
I understand vectors are slower than arrays but can someone help me understand why I got TLE. Thanks.
You are making vectors of size 100005 irrespective of n. Instead make vectors of size n, it will get accepted :)
Hi MikeMirzayanov. My solution for problem A was detected as coincide with another solution. However, this is not a violation because I have not leaked or copied the code. This is only because the logic for problem A is quite simple so the 2 solutions may have looked quite the same. I also encountered this last time. I do not have concrete evidence to show that this is a false cheating detection. But I just want to inform you so that you may reduce the detection for easy problems. This may help other coders too and more importantly, I do not want to see my account blocked because of this incorrect detection.
Why are my ratings rolled back without any message like cheating warnings?
They have been temporarily rolled back for everyone. It will be back after removing cheaters
Hi MikeMirzayanov. my solution 164765949 for the problem 1706B significantly coincides with solutions with others. But I have solved it myself you have take a look at submissions of my previous contest solutions, in which I have used same methodology to solve the problems. I haven't indulge in any malpractice in during the contest.
Even in the apology comment, you are copying from others' apology comments LMAO.
As a tester, please give me contribution.
The only goal for joining the test is to get more marks and get more ratings.
We wish ourselves best wishes and that's it