
Hello Codeforces!
The series of Educational Rounds continues thanks to the support of the Neapolis University Pafos.
On May/30/2024 17:35 (Moscow time) Educational Codeforces Round 166 (Rated for Div. 2) will start.
This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest, you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.
You will be given 6 or 7 problems and 2 hours to solve them.
The problems were invented and prepared by Adilbek adedalic Dalabaev, Ivan BledDest Androsov, Maksim Neon Mescheryakov, Roman Roms Glazov and me. Also, huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.
Good luck to all the participants!
UPD: Editorial is out








another BledDest round. Sheesh!!!
I got it.
mewing cat ready 4 the contest
Hope the competition topic is more interesting!
Hope ABC!
Mathforces round are the best
hope ABC
let's hope for delta > 0
Best wishes for everyone's A, B, C and D.
My post contest discussion stream for problems ABCDE
need +1
Hope everything goes well !!
Am I the only one for who the contest page is broken? I can't read problem statements or watch standings or submit.
Probably among a handful at best. Pretty sure the blog would be lambasted otherwise.
yes I am also the handful one
Nice problems, but solved only ABC. Sure D is simple counting with stack, but couldn't quite figure out till the end.
today first 10 min my codeforces didnt run well
Bad network
I've wasted about 30 minutes because of 502 and cloudflare
It was constantly showing an error on Brave browser. The issue was resolved when I switched to chrome for some reason.
I opened a B! :)
had 11 WA2 and took 1.5 hours on problem B until get AC
couldn't solve C
worst nightmare for me, expecting -150 delta
but.. you didn't even give the contest?
Yes, it seem, this tickbird is made for leaving comments only. Here is his alt jinsu
what is the idea for D?
Let $$$b$$$ be array of string balance. Then, if you do operation on $$$(l,r)$$$ you change all $$$b_i$$$ $$$(l \le i \le r)$$$ to $$$2 \cdot b_{l-1} - b_i$$$.
Hint — 0
We can only reverse EVEN length segments. We can only reverse segments, where number of '(' is equal to number of ')'.
Hint — 1.
Lets take one sample string ->
(((( )))). Figure out, how many possible reversals are there.Hint — 2.
We are allowed to reverse till last two '('. We can not reverse last three '(' . Why ?
To get an answer to above question, try this on pen-paper...
Keep one counter. Initial value of the counter = 0;
Travel the string from left to right. When you encounter '(' , counter++, else counter--, Store above values into some array.
For each segment start l we want to count number of correct segments' ends r, such that sequence remains balanced, and that means:
Counting suitable ends can be done with grouping positions by balance and binary search
Here is my solution.
diff_map[(diff_cnt[i]-1)/2] = 0;The different from0todiff_cnt[i]-1)/2is invalid. But other value will be set later.For each position the answer will be all position of current diff_cnt. (
ans += diff_map[diff_cnt[i]];) Because the difference between these position is 0.map<int, int> diff_map; for(int i=1;i<=s.size();i++) { ans += diff_map[diff_cnt[i]]; diff_map[diff_cnt[i]]++; diff_map[(diff_cnt[i]-1)/2] = 0; // cout << "diff cnt: " << diff_cnt[i] << " map: " << diff_map[diff_cnt[i]] << endl; } cout << ans << endl;
263353060
Excellent mental exercise... Loved the problems.
thank you for the contest. :)
I really enjoyed solving C today.
Said no one ever!
I don't really understand C
For the last test case 3 1 4 3 3 4 1 5 5 4 5 2 and for the 3rd candidate (programming skill, and testing skills) would be (4, 5) (3, 5) (4, 5) (1, 2) we need 3 programmers and 1 tester so for the 1 tester we take the 2nd candidate (3, 5) and for the 3 programmers we take (4, 5) (4, 5) (1, 2) Doesn't that mean the result is 5 + 4 + 4 + 1 = 14? why is it 13?
since first candidate is having higher testing skil, he must be consider as the tester.
you have to assign in order, so the first candidate will be assigned as a tester since his bi (5) > ai (4), then the second candidate will be assigned as programmer
ah I just thought since it was most suitable position, I thought I had to get the max possible value. Dam I actually did so much extra stuff when I could have solved it
I could not figure it out a case where the output is zero for Problem B , I guess this is where I got WA, could anyone provide one please? Thanks in advance!
you always need to do the copy operation once so the answer can never be zero
Exactly, however in the problem statement it mentions that the number of operations made can be possibly zero, this is the part I am not getting, how can it be zero if we need to do copy operation?
maybe a mistake
I just check the meaning of "aforementioned" that means change in value by increasing or decreasing so that possible that we wont change
So it's correct statement
It's not correct because copying counts as an aforementioned operation
your code is wrong because if lastIncluded is false at the end of the iteration you just add one but more than that many operations might be needed
Your point was right, just got it accepted, needed to check for more operations instead of adding just one; I thought during the contest that it had to be with possibility of zero, thanks for your help
Aah i missed updating the condition in A!! Cost me wayy to much
simple solution for A, if string is sorted YES else NO
Couldn't think of this in the contest so just brute forced it but damn, how did i miss this observation.
i solved D one minute after contest ended :(
May/31/2024 00:36UTC+8 263359883
If someone could explain why I have a Runtime error on this PyPy submission (problem C) I would really appreciate it.
https://mirror.codeforces.com/contest/1976/submission/263361104
Nevermind, after the contest ends you can see the error messages, it's a stack overflow.
Can Someone spot the mistake in my code or tell the test case ? I know the logic is correct but i am unable to find the error.
https://mirror.codeforces.com/contest/1976/submission/263360996
if someone does it, he will be blessed with high ratings :)
3 wa's for problem 1...i think its time to leave :(
Don't leave. Keep trying you will do better. I saw, you solved both A and B which is great! You shouldn't be demotivated by few WAs.
thanks :))
Solution for D with step-by-step optimizations:
263354202
First preprocess this thing to
arr:For every starting position
pos, the valid number of ranges is "count ofidxsuch thatarr[idx]==arr[pos]", whereidxmust be betweenpos+1andlast, wherelastis "the first position afterpossuch thatarr[last] > 2*arr[pos]" (because positive is subtraction after inverse, we need2*arr[pos]to clear it to zero, and one more to make it invalid)Now we need two lookups:
find_first_gt_fromfinds the position of the first value greater thanxstarting frompos.count_equal_in_rangecounts the number of items equal toxin range[first, last).find_first_gt_fromis optimized withmap<value, vector<pos>>andlower_bound. Whilecount_equal_in_rangeis optimized with binary search plusrange_max, which can be optimized with a sparse table.How to solve C?
Calculate the answer for answer[n+m+1], call it sum. Store the job given to each indices in this arrangement(You can use a set for example). Also, store the first instance where someone's job flipped(i.e. they were more skilled in testing but only programming is left, or vice versa). Notice that after that, there are no more flips of the opposite manner, since after a flip, every job is the same. Finally, just run through from 1 to n+m, and pretend to remove this persons job. It would go to either a) the first person flipped infront of this index(in which case their job goes to the last person) or to the last person. For a more formal look, you can checkout my sol here 263338267
Simplest is bruteforce with memoization, because taking/skipping 1 element will affect very few elements.
But of course there much more clever solutions
is carrot working for anyone?
no
damn seems everyone made the same mistake in E
What mistake?
Great problem D, the solution is quite simple but still not completely trivial. E is also nice, sad I couldn't implement it in time...
I don't want problems like today's C to get normalized
i don't want comments like this get normalized
nowadays not many people have sense of humour :(
Why? I enjoyed it.
good for you!
Why? Because it forces you to think in a different way?
it forces you to "if else if else if else if else if else if else..."
I don't have many if statements
Well there is an implementation which doesnt have such complications. One thing to notice is that there are only two types of distribution of workers. n + 1 programmers and m testers and n programmers m + 1 testers. For each i, if a[i] > b[i] remove it from the net sum of the n + 1 configuration, otherwise remove it from the net sum of the m + 1 configuration.
You are damn right
C — any idea why I get WA for this?
https://mirror.codeforces.com/contest/1976/submission/263362135
For example:
1
2 2
1 2 3 4 2
3 4 5 6 1
Your code outputs 14 13 13 12 14
For the second person, the answer should be: 3+5+4+2=14 (he would've been a tester, so the third guy becomes a tester instead of him, and the last guy becomes a programmer).
Came up with the following solution during contest for F but didn't implement it in time:
https://mirror.codeforces.com/contest/1976/submission/263362159
TLDR, always remove the two deepest branches, and make them into a cycle. How to prove that:
a) this is optimal
b) this runs fast enough
Edit: fixed spacing of comment
Edit 2: solution was hacked
Can anyone provide a testcase where this submission fails. 263337520
Correct answer: 3 Your answer: 4
Thanks
baler contest !!!
Any hint for 'C'?
Remove last one and choose everyone to progers or testers by naive. What will happen if you remove $$$i$$$-th person? $$$(1 \le i \textbf{ \lt } n+m+1)$$$?
D was nice, C was too much case work (for me) but anyways nice problem
can we do better than n * log(n) * log(n) in D.
yes, my submission is n log n
You can do binary search + sparse table or segment tree to solve in $$$O(n \log{n})$$$
i use bs over range maximum using segment tree it's
it's $$$ n\ log^2(n) $$$ can you please tell me how to reduce it to $$$n \ log(n)$$$
You are using segment tree to find maximum in $$$O(\log{n})$$$, but you can use data structure sparse table to find maximum on segment in $$$O(1)$$$.
Thanks!
In general, you don't really need to do binary search separately on the segment tree. CP Algorithm's blog on SegmentTrees is pretty good; I'd suggest going over the blog as a whole, but even the following section should give you an idea: Typical UseCase — $$$O(log^2(n)$$$ -> $$$O(log(n))$$$
Thanks! i learnt a new technique.
We don't really need dedicated RMQ data structures such as SparseTable/SegmentTree. Set/Map worked for me.
Reference Submission (C++ : Jiangly)
Reference Submission (Java : Me)
Complexity remains the same though, i.e., $$$O(n*log(n))$$$
*Edit: Added C++ reference submission (Jiangly's)
D can be solved in O(n): 263368704
Thanks! interesting soln.
Dang that's actually so clean
max(a[i..j]) ≤ 2×a[i]can u please explain thisAfter inversion all +1 will become -1 and after subtraction will become < 0, invalid brackets
Cool simplification!
Got accepted C and D after upsolving. Feeling pretty bad today for corner case (or maybe some stupid handling in my implementation) :(( .
I too was not able to find why I got WA for 30 minutes. I am Too slow at implementation and debugging.
Hello Master DuongNeverAlone! hru? do u remember me?
Yes Master DuongNeverAlone! You had a bad day, but you made a comeback just another day, and also today you did really well. Congrats! and yes i'll be focussing on >=1600 it just took a lot of work to figure out 1600 level problems (as of now) so i can't do more than 2, i have university exams for the whole month as well. Can you give me a tip on something? that how much time should i spend on problems >=1600 on my own without seeing the editorials? Thanx in advance
Try to direct message me instead of comment, as this is a personal problem.
The A was really bad
I too thought the same. But the shortest way to solve the problem A is to just check whether given is sorted or not. it is so elegant.
Oh wow, didn't notice that. But still, i'm pretty sure that most participants brute forced the solution which was really annoying to code.
how to solver B
consider each element as potential candidate which can be use to perform 3'rd operation
if you choose a_i for 3'rd operation
think about how you can minimize cost for i'th element because for all other j (j != i) cost is fixed that is abs(a_i — b_i)
Hi! Do you have any idea whey (possibly zero)?
_ the minimum number of operations (possibly zero)_
no. of ops will always be > 0
Dp, If don't understand then ask.
problem D the time limit is very strict. O (n * logn * logn) solution using Recursive segment tree gives TL, although I know nlogn solution exists.
I use sparse table + binary search to find "the index of the first item after pos that is greater than x"
263354202
I used map<int,vector>
My solution is the same and runs in O(n * logn * logn). But I just copied segtree's code from GFG and it runs in less than 1000ms.
It seems that my purple name want to stay with me for a longer time :)
Somehow I come up with an solution to D using segtree, and it worked! :)
compare my first submission in the contest and after contest in the D and cry with me T^T
How to solve Problem C using Binary Search? I solved without using it.
263329045
https://mirror.codeforces.com/contest/1976/hacks/1028125
Is this hack not weird? Why would they randomly hardcode wrong answers. Seems like a trick by the hacker to gain points by hacking solutions like this.
I couldn't submit B for a long time cause cf wanted to verify if I am a human.
God, I read B incorrectly and was thinking that the third option was to copy the number to the initially empty array
b...Spent 30 extra minutes do to that =(
Another amazing performance for JinnyW For what i know he is only 8 years old Could he be the next big chinese competetitor?
Where did you get such information? I still find it hard to comprehend an 8yr old CM :(.
Could someone please help me by finding a test case where I am wrong for today's C https://mirror.codeforces.com/contest/1976/submission/263348497
input:
correct output:
Thanks. Could you also tell what strategy did you use to find this test? I tried to debug it for an hour but was unable to find a counter case.
i failed test 2 in the contest, so i wrote a test generator and brute force code to check my solution for task C, and it got accepted. here is my code
i used the same strategy to find a counter case for your code
Thanks
Try to write cleaner code! it helps while debugging your solution.
C is really a bad problem. Just lengthy implementation. I just got scared and could not implemenet it properly
How is a problem bad just because it is lengthy? Most real-life problems are way longer than this tbh I enjoyed C it had so many factors to consider before arriving at the solution instead of one single crazy trick ¯_(ツ)_/¯
A lengthy problem in 2-hour contest is a bad problem.If it's in a 5-hour or 14-day contest, it's not really bad.
I didn't find the implementation that lengthy, 263365416
The solution to problem D involves identifying a pair
(i, j)that satisfies the following conditions:A[i-1] == A[j], A[j] != 0, and for every k in the rangei <= k <= j, A[k] <= 2A[j]. Here, the array A is a prefix sum array derived by considering '(' as +1 and ')' as -1. To illustrate, consider the sequence "((((()))))".Interestingly, while many have approached this problem with a time complexity of
O(n * log(n) * log(n)), there exists a more efficient solution. This problem can actually be solved inO(n)time 263375129Any idea how could I improve my code for C, giving TLE in test 4
https://mirror.codeforces.com/contest/1976/submission/263348500
Assume all the candidates come to interview. Solve the problem twice, once for N+1 coders and M testers, and once for N coders and M+1 testers. In both solutions track whether each candidate is appointed as a coder or as a tester. This takes O(N+M+1) steps.
If the candidate i does not come to interview, then check whether i is appointed a coder or tester in the two solutions. If a coder in the first solution, then answer is (first solution score — candidate i score as a coder). If a tester in the second solution, then answer is (second solution score — candidate i score as a tester).
You will never have candidate i appointed as tester in first solution and as coder in second solution.
Can anyone tell why this submission fails for C? https://mirror.codeforces.com/contest/1976/submission/263357375
line 124: cout<<ans1-t[i]; There is no space before the next output.
Dammit!That was the only mistake.Thanks for pointing out.
whats wrong in my first solution to B ?
You need to check if $$$b[n]$$$ is between $$$min(a[i], b[i])$$$ and $$$max(a[i], b[i])$$$ for any $$$i$$$ in loop instead of just at the end using bottom and top variables. If this condition holds, just add 1, otherwise handle the case as you're doing it right now.
E is no easy, I can't AC T_T
codeforces.com is down in some time interval during the contest, and around 15 minutes later the mirror.codeforces.com recovered but the root domain didn't and wasn't accessible even at the end of contest. I don't see why this round should be rated even the terrible server issue occurs. By the way, C is really a bad problem.
The mirror was fine the whole time for me.
I wasted about 30min because of 502 and cloudflare.
m1,m2 and m3 didn't work well, too.
It seems that m1, m2, m3 haven't been working well for a few months. I don't know why Mike didn't fix it.
I solve problem C Using Recursive DP
DP[n][2]
this person take place as prog 0 else 1
and send remaining places of prog and test
this is recursive function
two states only person prog or tester
i think it's most easy solution to this problem
can you please explain it a little bit? like in my mind I need at lease 3 states index,n,m
which is 1e15 I looked at your code but I couldn't get it because I'm not used to java can you explain the logic ?
if we solve it for first n people for example if we stand at index 7 and remaining programmers 4 and testers 3 if we remove index 3 this is programmer we go to index 7 with 3 prog and 3 testers yes? if we remove index 4 this is tester we go to index 7 with 4 prog and 2 testers yes?
if we remove index 5 this is programmer we go to index 7 with 3 prog and 3 testers yes?
which meaning we always go to any index with prog-1 or testers -1
so I don't care about n and m in first case I don't remove any one
i also kinda solved it with DP(Non Recursive)
263356128
Please take care of chinese,We can't even get into codeforce.com
can try m1.codeforces.com?
didn't work well.
what is the idea for C?
Hint : only 2 will change, first forced employee and last index one and calculate in reverse order
calculate in reverse order means?
mean first we will calculate n+m th doest come on interview then n+m-1,n+m-2....so on till 1,0th index dont come at work. or maybe forward can work but i have written in backwards manner
I have this test case for problem B 1 3 2 4 6 1 5 2 13
shouldn't the ans be 21 for this. ans=(2-1)+(5-4)+(13-6)+1+(13-2)=21. for making the copy of 13 we first have to go from 6 to 13 which is 13-6=7 operation and then after appending the copy(+1 operation) we have to come back to 2 (13-2=11 operations. And for the remaining numbers in a ans+=(2-1)+(5-4). what is the flaw in this logic ?
First operation is to copy the 6 to the end, giving 2 4 6 6. Then using +-1 operations convert to 1 5 2 13, taking (2-1) + (5-4) + (6-2) + (13-6) steps. Total 14.
I am puzzled at the statement of problem F for an hour and couldn't explain the sample output, until I realized that lower vertex in condition below is by depth instead of vertex id! Somehow I couldn't realize it earlier despite noticed the input is a rooted tree.
My friend had also misunderstood at this place before,though he solved the problem at last.When he was reading this part,he was confused why the problem repeats "root has only one son" again and again.So he asked questions and specifically said this to the organizers at question part.However,the response isn't satisfying and there are still a lot of people who neither realized the contradiction nor got the correct meaning.
Results,when.. ??
When will the ratings change?? I am checking my ratings from yesterday Night!!!
It will take some time but soon will get updated.
The problems are quite suitable for Educational Round,I like this style.
can someone tell where is my code failing for problem c,i calculated skill if candidate n=m+1 th didnt come and then using it found if candidate i th didnt come(i>=1 and i<=n+m) 263427040
want a tutorial for C PLZ!!!
Forget that you have to pick n and m guys. Imagine that you want to pick n + 1 programmers and m testers.You can do it simply by checking a[i] > b[i]. Let us say the sum of a[i] (for prorgrammers and respectively b[i] for testers) is S. Now for all guys selected as programmer , the answer , when they are excluded is simply S — a[i] , as you can discard i_th guy from the chosen set. Similarly do it other way i.e. solve the problem for n programmers and m + 1 testers.
thanks!!!
how will i get to know if the i_th person which is absent now was contributing as a programmer or tester?
You can maintain that using some array. What I did was whenever a particular i was a programmer , I did was ans[i] = -a[i]. After getting the final sum S , I had to check if ans[i] < 0 and then do ans[i] += S.
but there will be 1 person that will contribute as both programmer and tester when we will take (n+1 programmer and m tester) and (n programmer and m+1 tester) right?
Yes , you are correct , and both gives same answer , so there is no issue.
Div-1 participants(rating > 2100) are rated for this round?
no. This round will be rated for the participants with rating lower than 2100.
Why are people above 2,100 given a rank in the common standings?
but rating more than 2100 are showing in official standing :)
Educational rounds has always been 'official' for all participants. However, 'official' != 'rated'. It is 'rated' only for participants with rating lower than 2100.
oh, thanks
I am new here. My rating is 1210 will this contest be considered rated for me or unrated.
You will be rated, if you made at least one submission during the contest.
Everytime there is a contest, the codeforces.com always asks me to prove I'm a real person. why?
This actually happen when there is lots of traffic at the codeforces. Just to avoid the denial of service attack during the contest this is done by the cloud-flare.
Will we get the rating updation before 949 Div-2 starts?
This is a nice question, if you became master in the EDU, I believe both contest will be rated for you.
Can anyone look at my C and help me in figure out what I'm missing? 263424813
when will the ratings be updated?
what is system testing? and why a 2 hour-long contest is taking more than 12 hours to conclude. I am new to cf.
“System testing” is a procedure that retests all the submitted code with successful hacks during the open-hacking phase, as well as extra tests (if available) provided by the contest managers. Edu rounds and Div.3 rounds may include a 12-hour open-hacking phase, during which everyone can try to hack every submitted code in the contest.
when will the rating be updated ?
Can someone explain why this code is getting accepted on C++17 but not on C++20..... 263515419
I have helped debugged your code.
In this section:
it1--crashes. Looks like you are missing some boundary checks.input:
Debugging environment: MacOS ARM64 clang++
-Wall -std=c++20 -Wextra -Og -g3with slightly modifiedincludesection of your code.but how did it get accepted while submitting in c++17 it got WA on test 7 in c++20;
If it==s.begin(), then when you do auto it1(it); it1--; you are stepping off the start of the set s, and anything can happen.
If *it1 happens to give the same value as *s.begin(), or some unpredictable number greater than *s.begin(), then you get the right answer.
Thanks for the explanation!
system testing got tle
why the rating updation is getting this much delayed unusually??
awoo , BledDest , MikeMirzayanov
Even hours after final standings, neither of today,yesterday's contest rating changes are published yet ?
is there any reason or just ratings TLE....
How much time will it take to display rating??? i cant see myself in 700s anymore. This is torture to a newbie.
Will be updated soon
Great contest! Does the rating update usually take this long, lol?
They say sometimes it does. I've only been on a handful of rounds so far, but one took 12+ hours to update. There was no open hacking that round, so add that time to this round. And dunno about R949. Hope to see the updates by tomorrow morning.
Cheers, both of them got updated finally.
When rating will be updated?
Why I'm still unrated?
Why i am still blue even my max rating has been changed to candidate master?
It seems that all the people participating in this round but not the next round and getting level upgrade have encountered this problem.
can't even understand how this could happen...
It's quite fun seeing I am blue with the rating of 2007 :)
but I believe it will update soon.
I think they don't know about this bug As this bus is in that div only The least round has no bug
Something went wrong with the new rank
Why am I still Newbie with a rating of 1200+ :(
same with me