
Привет, Codeforces!
Благодаря поддержке Neapolis University Pafos, продолжается серия образовательных раундов. Университет предлагает получение степени бакалавра в области компьютерных наук и искусственного интеллекта со стипендиями JetBrains. Получите передовые навыки в области искусственного интеллекта и машинного обучения, которые подготовят вас к востребованным техническим карьерам. Любопытно? Ознакомьтесь с учебной программой прямо сейчас. Доступно ограниченное количество стипендий. Не упустите свой шанс учиться в Европе бесплатно!
В 02.12.2024 17:35 (Московское время) состоится Educational Codeforces Round 172 (Rated for Div. 2).
Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.
Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.
Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.
Удачи в раунде! Успешных решений!
UPD: Разбор опубликован









First Comment
YEah thanks.
This is not linkedin.
Why isn't unrated participation allowed this time?
Was unrated participation allowed last time?
yes
No score distribution?
I mean generally, all div2's have score distribution, right?
Educational rounds don’t have scoring distributions since they are held on ICPC rules(ranked by # of problems solved then penalty) unlike regular div 2 rounds.
upvote?
God, please don't make me fumble this one and let me become specialist for the first time.
Nah, i can never reach specialist -_-
Why so serious?
Good luck!
I am curious why the exact number of problems is not given in the announcement? it's always sth like x or (x+1) problems.
How does that affect you lmao.
Seriously now, I think that it is because educational round are only prepared by 4 people and are held quite often so it is quite hard to make 6 or 7 problems before the round.
Damnnnnn I was so close to solving D in time. I can't figure out what exactly is wrong with my implementation.. failed on test 2.
UPD: figured out what was wrong. needed to separate the left-hand answers and right-hand answers and add them up to avoid extraneous previously seen segments' left bounds.
I don't usually like problems in educational rounds, but this time problems were very good and the problemset was balanced, except for the difficulty jump in D->E.
What do you mean by "balanced"? :)
Problems A and B are so easy that there are ~10k submissions each.
Problems C with < 2500 seems to be unusually hard.
Idk why C doesn't have more solves, its difficulty felt natural to me even though it took me a lot of time to solve.
As a participant, I can only solve A and B. Anyway how to solve C?
Iterate from 0 to n — 1. Let's say you are at some index $$$i$$$, assume that you have already divided the suffix of numbers after $$$i$$$, if you decide to merge $$$i$$$ with the segment right of it, you will add $$$a - b$$$ to the difference between Alice and Bob(I will call this number sum), where $$$a$$$ is the number of 0 in the suffix, and $$$b$$$ is number of 1. Sort all $$$a - b$$$ and add them and decrease the number of segments while it is optimal. In the beginning divide the array into $$$n$$$ segments and then you reduce them.
Implementation: 294433631
did anyone do C using segment tree and binary search ?
How to Solve C ?
Can be much better if you explain why sort the suffix sum descend and sum them 1 by 1 will work.
Anyway thanks for the clear hint, because the proof/observation why it works is very value-able.
Can anyone pls tell me what's wrong with my approach for prob B
Explain the main idea?
What is the logic of the main if-else in the solve function?
My logic is that I will take each color of the marble once. Then if number of the color >= number of Alice's turn, the ans will be number of the color + number of marble that appears only once. Else I will sort the number of each kind of marble ascending and just simulate the game, and see how many color can Alice conquer. (Alice will take each number of each kind of marble -1 until she cant for example 1 1 1 1 1 1 3 3 4 alice will take 1,3,4 then alice have 5 turn left and she will take 3,1). I know i explain kind of stupid ToT but hope you understand what I'm saying.
First, it is too complicated for Div2B, and it is hard to see the logic. Second, for test below, your code gives 8, though 7 is the answer.
oh tks so much bro
Mfw when i realize "Alice wants to maximize her score at the end of the game. Bob wants to minimize it." actually means Bob wants to minimize Alice score not Bob wants to minimize his score after losing 100 rating ToT.
I also read B wrongly at first. I, for no reason (maybe because of urge of solving B fast), interpreted as one point for taking some character (same as in the problem), and second point for the one who takes last character. Then basically trying to understand what's wrong with output. Hopefully, it did not require much changes to correct from my approach.
AAAAAAAAHHHHHHH Why o why is problem F so much easier than E? I didnt look at the scoreboard, and hence spent 3/4 of the contest implementing E instead of F :(. Anyway, nice problems (especially A,B,C)
Why is $$$n \leq 1000$$$ in B?
Has the same question, felt like the number of solves would be a bit more "balanced" if n is bigger.
Looking back, it might be to allow people to simulate the removal of every marble, however I don't think that is appropriate for a D2B, I mean it is not hard to get to the $$$O(n)$$$ solution.
i don't even know how one would simulate this, lol
edu 2b frequently allows $$$O(n^2)$$$ while $$$O(n)$$$ solution exists. In the last edu 2b it also allows $$$O(n^2)$$$.
What is the logic behind unrated participants still being official for educational rounds?
I really like E (although I haven't solved it). It's the kind of problem you can solve step by step.
C — super good.
D — boring in general (good for edu)
C look like dp why?
i did dp got tle one test4 :/
But DP is n^2 right? How would it work when n is 10^5?
yeah thats why i got TLE on test4
What is the logic behind unrated participants being counted as official in educational rounds?
1903C - Theofanis' Nightmare
1175D - Array Splitting
I literally solved 1903C problem yesterday. but still wasn't able to solve today c problem.
happened to me too. i have solved both of these problems in the past!
omg i couldn't solve C! for 1:45 hours!
If a CM couldn't solve it, I had no chance... I could only solve A and B. Is there a very specific technique that you have to know to solve C?
well i tried everything! just couldn't crack it.
C is peace of s***. Worst edu ever
Who put problem E at this position?
I have an approach to C, but its failing (Wrong answer) in the test case 2 and I don't really know why. Can someone help with this one point out some flaw in this one.
Approach:
It would be best if we look at the difference of scores of alice and bob as that's what only matters. Let's call it
score.Initialize an array,
arr. Then, we start from end of the string and 1. if we find a0, then keep traversing towards the left as long as the count of1s and0s is not equal in this group. When a block of equal0s and1s found, then insert a0inarr(signifying that the contribution of this group is0). 2. if we find a1, then make it a separate group and then insert a1inarr(signifying that the contribution of this group is> 0).So, we try to make groups such that each group has an equal number of
0s and1s (so this block doesn't contribute to the score difference), and only the group of single1s contribute to the score.Since we inserted in
arrin reverse order, we reverse thearrand then assign the indices from the start and find the score. I think this would be the maximum possible score.For example: (taking something other than sample testcases)
s = "100110101101"then final array(after reversing) looks like (
0 1 0 0 1 0 1).Now, I can loop over it and find the score as (
group number * contribution).So,
score = 0 * 0 + 1 * 1 + 2 * 0 + 3 * 0 + 4 * 1 + 5 * 0 + 6 * 1 = 11If this
score < k, then-1is ans. Otherwise, we can try to merge groups from the right. I used binary search here, to find a suffix till after which we merge all the groups into single one and then calculate the score of array and compare it withkto minimize group count.Is this line of thinking correct or is there a mistake in here?
Your WA case is:
In this case you divide
0011into00|1|1, which gives a score of $$$3$$$ and your code thinks it's impossible to reach $$$4$$$. However, we can divide0|0|1|1to get a score of $$$4$$$.Problem C was too tough. Edu div 2 is more harder than div 2. Edu Div 2>>>>>>>>>>>>>>>>>> Div 2
Exactly!! I always avoided EDU div 2, but this time I thought of participating and got a really bad rank.
Why it is TLE?
https://codeforces.me/contest/2042/submission/294472150
unordered map collisions, use map forever and always
Can anyone please explain logic for the problem C
Replace $$$0$$$ as $$$-1$$$, and the result of some grouping, eg $$$[-1,1],[-1,1,1],[1,-1,1]$$$, is $$$\text{sum}[1,-1,1]+\text{sum}[-1,1,1,1,-1,1]$$$. So you can solve all suffix sums and add them greedily.
i thought of this but couldnt code would be helpful if i get code of this in c++
A: sort {a[i]} and find the maximum suffix sum with value at most k. The answer is k minus this sum.
B: Let k1 be the count of colors with only 1 occurence, and k2 be the count of colors with at least 2 occurence. For each time Alice pick ball from k1 she will gain 2 points, and when she pick from k2 she will gain 1 point. Also Alice cannot get 2 potins from k2, because Bob can take the ball with same color after Alice pick the first ball from that color. So the optimal move for Alice and Bob is take balls from k1 first, then Alice will take a ball for all colors in k2. Therefore the answer is k2+2*ceil(k1/2).
C: For each 1<=i<n, if we separate the array at the "gap" between i and i+1, the score of fishes on [i+1, n] will increase by 1, so the value of (Bob's score — Alice's score) will increase by (number of '1' in [i+1, n] — number of '0' in [i+1, n]), so we can calculate the change of balance for 1<=i<n by suffix sums, sort them and pick from the greatest to smallest.
D: Let's find the number of strongly recommended tracks with number > r[i] for each 1<=i<=n first. So we can sort users by l[i], and for each i we need to find the minimum value of r[j], for all j such that l[j]<=l[i] and r[j]>=r[i]. Here the first condition is satisfied from the non-decreasing order of l[i], then we need to find the minimum r[j] by lower_bound on std::multiset. Then we need to find the number of strongly recommended tracks with number < r[i], we can do this by {l[i], r[i]} := {-r[i], -l[i]} and do the same steps as previous case.
F: We can solve the problem by segment tree. The merge function of segment tree is something like this:
Where: (Assuming the range represented by
Iis [x, y], Denoting sum(x, y) = a[x]+a[x+1]+...+a[y-1]+a[y])I.summeans sum(x, y)I.Lameans maximum value of (sum(x, j)+b[j]) for x<=j<=yI.Rameans maximum value of (b[j]+sum(j, y)) for x<=j<=yI.ansmeans maximum value of (sum(j, k)+b[j]+b[k]) for x<=j<=k<=yI.Dmeans the needed answer for the range (which is maximum value of (sum(j, k) + b[j]+b[k] + sum(p, q) + b[p]+b[q]) for x<=j<=k<p<=q<=y)I.LDmeans maximum value of (sum(x, j)+b[j] + sum(k, p)+b[k]+b[p]) for x<=j<k<=p<=yI.RDmeans maximum value of (sum(j, k)+b[j]+b[k] + b[p]+sum(p, y)) for x<=j<=k<p<=yI.LRDmeans maximum value of (sum(x, j)+b[j] + b[k]+sum(k, y)) for x<=j<k<=yThe merge function is similar as what we do when finding maximum subarray sum by divide & conquer.
Let
.denotes position we add neither a[i] or b[i],-denotes position we add only a[i], and[or]denotes position we add a[i] and b[i]. Suppose we've decided the 2 intervals we pick for answer, then for any subarray of [L, R], the situation can de represented by one of 9 strings:----------------------]..........[--------...[------]...---]..[---]......[---]..[---..[--]..[--]..----]....[----..............Except for the empty case (9), we need a variable for every other cases.
Why is problem C tagged geometry?
Why is problem C tagged geometry?
high rating people trolling with tags once again; they're free to edit them regardless of what the problem actually is which can cause chaos if some person intentionally chooses the wrong tags
why sorting all the values of the suffix in descending order works?
Why the suffix works in C?
Does it matter if the starting score for the first group is 0 or 100?
The main key observation is to understand that the difference of Bob's score and Alice's score is just the summation of the suffix sums at each split;
Why this works is really interesting:
Basically, taking an example, if you have three groups:
[ Group 1 elements ] [Group 2 Elements ] [ Group 3 elements]
You could normally calculate the total difference between Bob and Alice's score as:
(Difference in scores for group 1) * 0 + (difference in scores for group 2) * 1 + (difference in scores for group 3) * 2
(Lets call the above equation (1))
Now the key thing to understand here is that there is a pattern here; Group 3 is being summed 2 times, Group 2 is being summed 1 times, and Group 1 is being summed 0 times....
So instead, if you just calculated the suffix sum for difference of scores at each position starting from the last element, and then calculated:
(Sum of suffix scores at Group 1/2 split) + (Sum of suffix scores at Group2/3 split)
You would automatically calculated the same thing as equation (1) above! This is because in this expression, the suffix sums for Group2/3 split would get counted twice (once because of the Group 2/3 split term, and once because of the Group 1/2 split term).
Thanks, that's seems too easy, just convert the multiplaction to summation.
unfortunately i didn't get it :(
B. Game with Colored Marbles
for above question i have write code in c++ now i am using same approach to solve question in both the code with difference of taking input and counting at incrementing at the same loop in code with addition checking the size of map. WHICH I SUBMITTED DURING CONTEST WHICH PASSED GIVEN TEST CASES AND DOES NOT PASSED HIDDEN TEST CASES
after contest i use same code but counting frequency using another loop which passed all test cases so can someone explain me why this happend i asked chapgpt and got reply both code will generate same output. but why my very first submission of code did not worked
code 1: -
~~~~~~~~~~~~~~~~
include
include <bits/stdc++.h>
using namespace std;
int main() { int t; cin >> t;
while(t--){ int n; cin >> n; vector<int> marb(n); map<int,int> mp; for(int i = 0; i < n; i++){ cin >> marb[i]; mp[marb[i]]++; } if(mp.size() == 1){ cout << 1 << endl; continue; }else{ int uni = 0, nonuni = 0; for(auto it : mp){ if(it.second == 1){ uni++; }else{ nonuni++; } } int mxsc = 0; mxsc += (uni & 1 == 1 ? (uni/2 + 1)*2 : (uni/2)*2 ); // cout << (uni/2 + 1)*2 << endl; mxsc += nonuni; cout << mxsc << endl; } // vector<pair<int,int>> vec(mp.begin(), mp.end()); // sort(vec.begin(), vec.end(), [](const pair<int, int> &a, const pair<int, int> &b) { // return a.second < b.second; // }); // mp.clear(); // for (const auto &pair : vec) { // mp.insert(pair); // } } return 0;} ~~~~~~~~~~~
CODE 2 :-
~~~~~~~~~~~~~~~
include
include <bits/stdc++.h>
using namespace std;
int main() { int t; cin >> t;
while(t--){ int n; cin >> n; vector<int> marb(n); for(int i = 0; i < n; i++){ cin >> marb[i]; } map<int,int> mp; for(int i = 0; i < n; i++){ mp[marb[i]]++; } int uni = 0, nonuni = 0; for(auto it : mp){ if(it.second == 1){ uni++; }else{ nonuni++; } } int mxsc = 0; mxsc += (uni & 1 == 1 ? (uni/2 + 1)*2 : (uni/2)*2); mxsc += nonuni; cout << mxsc << endl; } return 0;} ~~~~~~~~~~~~~~
For your first code, if there is only 1 marble in the game, do you print 1 or 2?
Your code 1 can handle
mp.size() == 1in the else part but when you handle it in paritcular, you handle it wrong.ps.
uni & 1 == 1is actuallyuni & (1 == 1), but it doesn't matter in this case.Did anyone solve C using binary search?
Yes, you can to find ans on binary search. Checker: if you try to push level on number you can to recalc difference on Alice and Bob. Check my code.
What's the hack for C?
Int overflow probably
Yes, when you have 2⋅10⁵ zeros, the sum gives negative overflow for int
As a victim I can confirm. And I thought it was my best round ever. Now I have to wake up early tommorow to release the frustration
Normal round. But C is very easy and D has bad hard realization for me. I think, in Edu Rounds C and D normal but for div2 it is not good.
Bro, really?
Please can I have the name of the app that predicts delta change? I tried to look for it but I couldn't.
It's a chrome extension called Carrot
https://chromewebstore.google.com/detail/carrot/gakohpplicjdhhfllilcjpfildodfnnn
Thank you so much! Have a nice day :)
Actually, I think these whole bunch of submissions are all suspicious (esp with similar code structure + random bizzare function names)
Yeah, and the most suspicious part about them is the time. All of them were submitted instantaneously.
why unrated
Same issue
Rating will be updated after Codeforces Round 990.
Thanks for the round, I finally reached CM after a year. Hope you get there as well :) P/s: I just saw a post of an expert frustrated with FST on problem C in the round. Honestly, if you didn't see that the calculations could get a value of > 2^32 then yeah stay at expert and train more.
yapping while account sharing is wild work
MikeMirzayanov awoo please look into this, this user had 2 different code styles in the same contest
Thanks for your statement and I respect every comment, even if I have to explain. There is a total of 3 styles of codes that I use throughout every competitive programming contest that I use, even including ICPC. Yes, sometimes with training sessions even my teacher asked me whether I cooperated with someone else's and I had to capture the screen for him of all my work. It seems that due to the fact that three of my teachers now have opposing coding styles, I am also affected. I felt that I could fix this in the future.
I felt that the only advantage that I had was fast coding, as in every ICPC contest our team is always "first ranked of all teams with equal points". My knowledge is not world-class, but I surely wanted to reach there. So of course, every suggestions that make me change myself, I will be deeply appreciated. Thank you sir, and have a nice day.
if you judge correctly you won't get overflow on both sides.
To prevent overflow:
In fact I don't know how C can overflow until I see the comment. Maybe the authors also don't realize the case and thus fail to set a $$$00000000\dots$$$ in pretest.
Thank you for sharing the idea. I just saw the 20 test cases that were added by hacks. The only idea that I used "long long" is that I felt that the suffix sums with their maximum value could be around 10^9 so I changed to long long before submitting only a few seconds.
(written) editorial waiting room, hopefully it gets updated soon
xD