Привет, 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
Ok.
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?
These divs are my favorite keep going
Goodluck to everyone!
God, please don't make me fumble this one and let me become specialist for the first time.
Good Luck!
Same lol
Nah, i can never reach specialist -_-
How many were you able to solve?
Why so serious?
i think u did it buddy
No. My performance was not even 1400.
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.
C was i think 1700+
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
Thank you!
Thank you very much guys for the round.
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.
As you can see in this image, the portion between blue segment and black segment is the first partition, between black and red is the second partition, between red and green is the third partition and the last green is the fourth partition. According the problem's solution,
1 * d1 + 2 * d2 + 3 * d3 + 4 * d4 >= k
. where d1 is the difference between number of ones and zeroes in the first partition. Now, if you sum all of the portions highlighted in four colors, this will give us that left hand side of the equation, no matter in what order we take it. Hence, it's greedy to sort the differences in descending order and greedily pick from large to small.Can somebody please share their approach for solving problem C, I tried a lot but couldn't solve it...
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.
consider marbles 1 2 3 3, if Alice pick 1 then Bob can pick 2 to prevent Alice to take each color once.
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)$$$.
can anyone share their approach to C in a detailed way?
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
Oh thats why its hard problem
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!
so hard for me. Just A and B are solved. Hope next time better.
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.
I m newbie but i solved C <...>
C is peace of s***. Worst edu ever
good problem, bad placement
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 of1
s and0
s is not equal in this group. When a block of equal0
s and1
s found, then insert a0
inarr
(signifying that the contribution of this group is0
). 2. if we find a1
, then make it a separate group and then insert a1
inarr
(signifying that the contribution of this group is> 0
).So, we try to make groups such that each group has an equal number of
0
s and1
s (so this block doesn't contribute to the score difference), and only the group of single1
s contribute to the score.Since we inserted in
arr
in reverse order, we reverse thearr
and 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 = 11
If this
score < k
, then-1
is 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 withk
to 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
0011
into00|1|1
, which gives a score of $$$3$$$ and your code thinks it's impossible to reach $$$4$$$. However, we can divide0|0|1|1
to get a score of $$$4$$$.Yeah I got it now. I am nowhere near the solution and need to re-think this.
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.net/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
I
is [x, y], Denoting sum(x, y) = a[x]+a[x+1]+...+a[y-1]+a[y])I.sum
means sum(x, y)I.La
means maximum value of (sum(x, j)+b[j]) for x<=j<=yI.Ra
means maximum value of (b[j]+sum(j, y)) for x<=j<=yI.ans
means maximum value of (sum(j, k)+b[j]+b[k]) for x<=j<=k<=yI.D
means 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.LD
means maximum value of (sum(x, j)+b[j] + sum(k, p)+b[k]+b[p]) for x<=j<k<=p<=yI.RD
means maximum value of (sum(j, k)+b[j]+b[k] + b[p]+sum(p, y)) for x<=j<=k<p<=yI.LRD
means 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 :(
Thank you so much . Now i am able to understand the approach.
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;
} ~~~~~~~~~~~
CODE 2 :-
~~~~~~~~~~~~~~~
include
include <bits/stdc++.h>
using namespace std;
int main() { int t; cin >> t;
} ~~~~~~~~~~~~~~
For your first code, if there is only 1 marble in the game, do you print 1 or 2?
so if there is only one type of marble with frequency more 1 we should print 1. else 2
Thank you for answering.
Your code 1 can handle
mp.size() == 1
in the else part but when you handle it in paritcular, you handle it wrong.ps.
uni & 1 == 1
is 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.
Can you please explain a little bit your logic? I am not able to understand it on the face of it. I know we binary search on number of groups and see if we can get a score atleast k with that many groups. But how to decide the group size in the check function?
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 I wrong awnser in C in test 2? see the checker, it may be because I cout<<-1, but it is feasible. https://codeforces.net/contest/2042/submission/294520912
sorry,I know where I wrong. whether to choose to add a split is only relative to suffix 1's occurence > 0's occurence, which is not relative to
Cnt1[i]-Cnt1[upS]>Cnt0[i]-Cnt0[upS]
, so it should be fixed asCnt1[i]>Cnt0[i]
you can test your code with this datain to check this problem.It should out
5
ou, it's not 5, it actually 2
010|11
Can someone share idea of question C ?
try do sth. from back?
Try to approach the problem in the follow way:
solve easy special cases of the problem such as
all 0s
all 1s
0001111 and vice versa
if you found the solution this way, please share how you did that, what did you discover
I know the mathematical relation for the problem which is
d[0] * 0 + d[1] * 1 + d[2] * 2 + ... + d[m - 1] * (m - 1) >= k
, where d[i] represents the difference between number of ones and zeroes in i-th partition. I saw people's solution, which involves taking all the partitions where cnt1 > cnt0, sorting them in descending order, and greedily summing them until the sum becomes greater than or equal to k. I don't know why it's working.why unrated
Same issue
Rating will be updated after Codeforces Round 990.
.
Why I didn't recive any elo yet?
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
(Div-2(D)) What is the reason for the tle ?
I am a new user of Codeforces and was not aware of all the rules and potential issues. I believe this situation might have occurred because I used ideone in public mode, not realizing that someone could copy my code from there. I apologize for my mistake and assure you that I will be more careful in the future to prevent such incidents.
Please give me a chance and do not take any strict action. I am committed to following the rules and maintaining the integrity of the competition.
xD