Hello Codeforces!
The series of Educational Rounds continues thanks to the support of the Neapolis University Pafos. They offer a BSc in Computer Science and AI with JetBrains Scholarships. Gain cutting-edge skills in AI and machine learning, preparing you for high-demand tech careers. Curious? Check out the CSAI curriculum now. Limited scholarships available — don't miss your chance to study in Europe for free!
On Aug/15/2024 17:35 (Moscow time) Educational Codeforces Round 169 (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 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
Hope to reach candidate Pupil after this one
Best of luck
best of luck
Best of luck.
BledDest orz
Please share the problem ratings.
hopefully expert after this one
good luck mate
good luck
why is this comment at -12???
idk either lmao, it is what it is
because this is cf
coz he's probably a cheater,see his submissions
if you accuse me of cheating, I suppose you have evidence?
.
Look through every single one of my submissions, and you can see I ALWAYS write long long int. Any single time I use 64-bit integer, I always type long long int. You just picked a random submission and the most random reason and decided to go with it? cope and seethe newbie, maybe focus on actually solving some problems instead of throwing baseless accusations.
So maybe you debug every question using ai,who knows!Also I am actually pupil,I didn't know multiple accounts are not allowed on cf,Hence kept this one only for practicing.
yea sure, I also use ai to type my code when I practice as well right? you're a complete clown, stop embarrassing yourself. oh and since when is AI considered cheating?
I used to write long long int every time myself before I started using a template that had long long. "clearly ai generated" bro is confident too. maybe try to come up with better proofs next time, at the very least you could avoid so many wrong submissions Starting to blame everyone you see for cheating using such petty claims is making things worse
Independence day Contest !
All the best to all. Hope you all get +100.
I need 130 :) but 100 still good and will make me happy
thanks
How to gain rating in EDU Round? I've droped the rating at almost every the EDU round.
Same here
during the contest, if you see that your position is too low to gain rating, it is best to solve another problem
based
What do you mean?
I'm glad that there are no tester comments.
i love edu rounds <3
Pupil rank happens TOMORROW
Looking forward to weeks of therapy for failing to do C over my misinterpretation of what the k variable meant...
How to Hack someone's solution?? Shayan bro i think you should make a video on this topic!! I tried many times to hack someone.. but always ( Unsuccessful Attempt )
You should give test with high strength. Here is an example: 274841071
https://mirror.codeforces.com/contest/1999/hacks/1066931
If you can't understand this code, it doesn't matter. You just need to know what he is doing. In this code, he's using Substring all the times which is $$$O(|s|)$$$ in time. It will get a TLE by a test with high strength. Thus, I give a test like this:
1
, and then 200000?
s, and then ana
.Unaccidentally, he is hacked by me.
You just used generator to generate worst case for s right?? But how did you figure out it'll give TLE..
How to practice for this?? I am very bad to figure out the time and space complexities
You can search the submissions in “Status”. And sort it by execution time at the end of the page. And get to the last page. The submissions there are almost TLE so that maybe TLE after you hack them.
What generator do you use?
Usually I use C++’s output. You can use what you familiar with.
if the test isn’t that long, just input the test by text is enough.
There you've wrote string s of length 2*10^5, how did you do that, and how to generate those big test cases?
There is a “Generate Input” Botton when you hack. Press it and paste your code there.
Example:
Okay, this way! Thanks.
I tried this multiple times but never got successful Attempt
Try more, you’ll gain from it.
What’s more , see which problem is hacked most. It may mean that it is easier to hack than other problem.
Sorry I’m a beginner here, how are edu rounds different from normal contests ?
PS: Got it, thank you!
The difficulty level is usually the middle ground of div2 and div3 constests.
You can't hack during the contest, but you can EVERYONE hack after contest.
I am a total beginner and have no idea what hacking means in this context. Like changing the answer or sth? Where should I start from
https://mirror.codeforces.com/help
Read about hacks.
In some contests like Div. 2 Round, there is a Codeforces Format .
Maybe in most websites, it will give you the result at once when you submit. But if Codeforces, there is only a set of tests called Pretests.
It just means that this is just the preliminary test which shows you if the code can run normally. If you passed pretests, you can lock this problem and hack participants who pasts pretests in your room, by giving tests with high strength to make them failed passing this problem.
P.S. If you lock the problem, you can't resubmit any more until the contest ends.
To get more information, you can read this blog
https://mirror.codeforces.com/blog/entry/456
In Div. 3 , Div. 4, and EDU Round, it is EX-ICPC Format. There will be a 12-hour-long phase at which you can hack everyone after the contest.
Different from Div.1 , Div.2 , Div.1+2 contests, it is an EX-ICPC Format.
Similar to Div.3 and Div.4 contests. You can see participants rated and unrated separately in the standings after system testing. You can view last Div.3 contest as an example: Codeforces Round 966 (Div. 3)
And view this round to see the probable difficulty of each problem. Educational Codeforces Round 168 (Rated for Div. 2)
standings: View rated participants rated separately by pressing the
Both divisions v
botton at the rightmost of your screen. Then cancel the tick ofShow unofficial
one.Thanks to all who contributes to this contest. Hope I can go back to specialist after this one!
hoping for the same!
Hope for 1300+ rating
good luck (you did well in the last contest congrats)
thanks, you too
Let's go specialist in this one
My first contest as specialist. Good luck everyone.
Best of luck to all. Hopefully, we will increase our rating in this contest =)
Bet it or not, I'm going to reach Master this round.
Good luck to you. Good luck to everyone.
Not happening, ahahaha
I didn't say I bet it. haha.... ha... Failure is common.
Nevermind. I'll be still there next round.
How can you reply me just minutes before the contest, are you watching me? Thank you for your watching stuttering
Maybe I'm going to change my handle into
Lmao_Fox
if this happens too many times.best of luck guys
I want to regain my pupil status.
If I don’t get CM I’m gay.
Congratulations! At least it's legal in Singapore since recently.
nice way of coming out of the closet
hope i become pupil , pls be easy for me
and it happened nice
Hoping for a positive delta!
In Educational Round dose speed of solving question matters or only number of questions solved during the contest matters and does not depend even on the rating of the question solved??
Speed matters. Rank is sorted first by number of solved problems, then time (10 minutes penalty for 1 wrong submission)
That means solving A and solving G are the same. It just calculates the total number of your solved problems and then the time.
InShaAllah, I will get +100 today
I also prayed to Allah to make me capable of solving at least 4 problems but i guess it wasn't better for me
Hope to solve four problems!
c < b
https://mirror.codeforces.com/contest/2004/submission/276681600 why its wrong
se is changed after se+=min(k,fi-se) so you need to use temp like t = in(k,fi-se) , se+=t
i was dumb thanks for solution
worst contest((
Great D but C < B.
was C really that easy?
it was easy I still got 6 WA's cause i didnt read "total" increase <=K
ahh, that changes a thing or two
or three
OOOHHHHH MMYYYYYYY GOODDDDDDDD!!!!!! YES!! YESS !! YESS!! YESS!! NO !! NO!! NO!! NO!!
gotta be honest the difficulties of problems from A->D is too low, compared to normal div2 rounds or just edu rounds. I choked this one but generally speaking, i think this contest was not so good
D offered a little bit of implementation fuss despite being not that hard conceptually.
Mind pointing out where my mistake was ??
https://mirror.codeforces.com/contest/2004/submission/276691814
so what the hell are you supposed to do for E (nims and games are kinda like the opposite of my skillset lol)
Find grundy numbers using SPF.
I don't know why it was named "not a nim problem". I solved it as a nim problem. Case analysis on small numbers showed that the nimber of a pile is basically the "rank" of its smallest prime factor (where a prime having rank k means it's the kth prime number, except that the rank of 2 is 0.)
Video editorial for D: Colored Portals
Here's a very fancy implementation of D: Colored Portals using Bitmask tricks that was introduced in D: Cases from a recent CF round. I also have a video editorial for the old problem.
Let's represent all portals as bitmasks of length 4. Then, a path between 2 nodes is possible if and only if the bitwise AND of both the numbers is not zero.
Assume $$$x < y$$$. On a number line, we know that the shortest path between 2 points is the straight line connecting them. So, if $$$a[x] \& a[y] \neq 0$$$, then, the answer is $$$|x - y|$$$. Otherwise, we need to jump to a portal that differs in exactly one color (i,e, the bitwise AND should contain exactly 1 set bit). From there, we can jump to $$$y$$$ directly.
Define $$$ldp[i]$$$ to be the nearest portal to the left that differs in exactly one color. You can populate it from left to right by maintaining a map of the latest bitmasks seen so far. Similarly, you can populate $$$rdp$$$.
There are only 3 possible paths. We take the best one amongst them.
i got the solution down immediately, but i could not implement it at all, fk me
I also got the solution, but my implement is not as good as the method above so... I don't know where I went wrong (I use binary search btw)
i tried using a map and then i also tried bs and some other stuff and i just couldnt get it. unlucky :(
276681877
You can look at my case work. I am laughing at my own code.
i shouldve just quit trying to do it nicely and just do that. good job ngl
Nice work
oh well I notice where I went wrong, need to reverse the array and position to binary search to get the correct answer. Not searching the y+1 or x+1 or (x+y)//2 will do
UPD: after fix the bs bug, my solution got TLE in test 6
In the hindsight, just maintain ldp and rdp will do me a favor more than bs
UPD: Resolved TLE, it's list.insert(0, list) which I think O(1) but it's O(n)
And the trend of 4k+ solves on D in Edu Rounds continues...
This D is only of Div2C level at most.
whoops
Why would you ever call a nim problem — $$$\texttt{Not a Nim Problem}$$$
Like I really don't understand, because it is funny?
When I read the name, I though that it is a bad idea to include "Nim" in the name of the problem, because when you search for nim tasks, this one would show up.
When though of the solution, I became even more confused. It was a nim problem. So why the author is telling me it is not true?
I thought that the name was part of the statement. I started to doubt myself that I got something wrong. Turns out everything is fine, nim works. Downvoted the contest when I saw "Accepted" verdict.
And also this statement:
Why you say "not not A" instead of just " A "
We can rewrite it like this:
This sentence is so confusing that even an announcement was made, where it was stated that
If it is so confusing, maybe the statement should be fixed? I don't understand why the announcement was made, and this sentence was not changed.
Lol, bro, relax
Agree with the title, just why?
Oh bro, is it a nim problem?
I immediately got idea for single pile, thought of using nim for n independent piles, but then I saw the problem name and thought its going to be some special case where nim doesn't work. And spent whole contest trying to solve without nim lol. I should understand nim better.
this nim thing is unfamiliar to me. any suggested resources ?
I really think you do not need to know that at specialist rank.
Hey, I was confused too. This article seems good :) https://mirror.codeforces.com/blog/entry/66040
thanks
You can read the wikipedia article on sprague-grundy theorem and Nim Sum. I think they are pretty well written.
Agreed, read it wrong due to the not not thing and thus couldn't do it in time.
Every page from problem to submit takes so much time to load. It's infuriating.
for the i 1 its grundy number is 1
for the i 2 its grundy number is 0
for the i 3 its grundy number is 2
for the i 4 its grundy number is 0
for the i 5 its grundy number is 3
for the i 6 its grundy number is 0
for the i 7 its grundy number is 4
for the i 8 its grundy number is 0
for the i 9 its grundy number is 2
for the i 10 its grundy number is 0
for the i 11 its grundy number is 5
for the i 12 its grundy number is 0
for the i 13 its grundy number is 6
for the i 14 its grundy number is 0
for the i 15 its grundy number is 2
for the i 16 its grundy number is 0
for the i 17 its grundy number is 7
for the i 18 its grundy number is 0
for the i 19 its grundy number is 8
for the i 20 its grundy number is 0
for the i 21 its grundy number is 2
for the i 22 its grundy number is 0
for the i 23 its grundy number is 9
for the i 24 its grundy number is 0
for the i 25 its grundy number is 3
for the i 26 its grundy number is 0
for the i 27 its grundy number is 2
for the i 28 its grundy number is 0
for the i 29 its grundy number is 10
for the i 30 its grundy number is 0
for the i 31 its grundy number is 11
for the i 32 its grundy number is 0
for the i 33 its grundy number is 2
for the i 34 its grundy number is 0
for the i 35 its grundy number is 3
for the i 36 its grundy number is 0
for the i 37 its grundy number is 12
for the i 38 its grundy number is 0
for the i 39 its grundy number is 2
for the i 40 its grundy number is 0
for the i 41 its grundy number is 13
for the i 42 its grundy number is 0
for the i 43 its grundy number is 14
for the i 44 its grundy number is 0
for the i 45 its grundy number is 2
for the i 46 its grundy number is 0
for the i 47 its grundy number is 15
for the i 48 its grundy number is 0
for the i 49 its grundy number is 4
for the i 50 its grundy number is 0
for the i 51 its grundy number is 2
for the i 52 its grundy number is 0
for the i 53 its grundy number is 16
for the i 54 its grundy number is 0
for the i 55 its grundy number is 3
for the i 56 its grundy number is 0
for the i 57 its grundy number is 2
for the i 58 its grundy number is 0
for the i 59 its grundy number is 17
for the i 60 its grundy number is 0
for the i 61 its grundy number is 18
for the i 62 its grundy number is 0
for the i 63 its grundy number is 2
for the i 64 its grundy number is 0
for the i 65 its grundy number is 3
for the i 66 its grundy number is 0
for the i 67 its grundy number is 19
for the i 68 its grundy number is 0
for the i 69 its grundy number is 2
for the i 70 its grundy number is 0
for the i 71 its grundy number is 20
for the i 72 its grundy number is 0
for the i 73 its grundy number is 21
for the i 74 its grundy number is 0
for the i 75 its grundy number is 2
for the i 76 its grundy number is 0
for the i 77 its grundy number is 4
for the i 78 its grundy number is 0
for the i 79 its grundy number is 22
for the i 80 its grundy number is 0
for the i 81 its grundy number is 2
for the i 82 its grundy number is 0
for the i 83 its grundy number is 23
for the i 84 its grundy number is 0
for the i 85 its grundy number is 3
for the i 86 its grundy number is 0
for the i 87 its grundy number is 2
for the i 88 its grundy number is 0
for the i 89 its grundy number is 24
for the i 90 its grundy number is 0
for the i 91 its grundy number is 4
for the i 92 its grundy number is 0
for the i 93 its grundy number is 2
for the i 94 its grundy number is 0
for the i 95 its grundy number is 3
for the i 96 its grundy number is 0
for the i 97 its grundy number is 25
for the i 98 its grundy number is 0
for the i 99 its grundy number is 2
for the i 100 its grundy number is 0
Yes
I could generate grundy numbers, but didn't know how to extend them to 10^7. Small hint please ?
For even numbers, grundy is always 0. For 2, it is obvious because you can only take 1 and the grundy of 1 is 1. For the rest, because player is not allowed to take 2, then $$$g(2)=0$$$ would always be the mex of all options
For prime numbers, the grundy is $$$k$$$ where $$$k$$$ is the order of prime numbers (e.g. $$$g(3) = 2$$$, $$$g(5) = 3$$$ etc). This is because all prime numbers $$$p$$$ can have options of $$$1,2,3,\ldots,p-1$$$. Therefore the mex is always $$$k$$$ because it hasn't existed yet
For the rest, the grundy would be smallest prime factor of that number. Because it would be the smallest number that doesn't exist for all its transition (hence, it similar to the nature of mex). The other number would exist because if the smallest prime factor is $$$p$$$, then all numbers between $$$1, 2, \ldots, p-1$$$ can be taken of that pile. Hence, all numbers between $$$0, 1, 2, \ldots, g(p-1)$$$ can be exist as transition moves and won't appear as mex.
Thank you very much for explanation.
I could see the first and second observations from the brute-force that I had written.
But I couldn't deduce the third observation :( . otherwise I would have solved this.
Anyone who is interested in how to generate grundy numbers here, please refer to this.
~~~~~~
grundy[0] = 0; grundy[1] = 1;
~~~~~~~
Don't worry it took me 90 minutes to get it haha. F was much more straightforward today, so it's a good thing I wasn't afraid to skip.
small doubt, can we generate all the primes till 10^7 within the given time-limit ? ( never generated primes till 10^7, so asking ).
We need to find the what is the order of the given prime number, and we can't do that unless we have all the prime numbers within 10^7.
Do we need to implement SegmentedSieve ? or normal sieve is sufficient ?
fonmagnus
I think if we skip the even numbers, then we can do it for $$$5 \times 10^6$$$ numbers and should be fine (it's kinda close to TL but I guess that's one way to prune it)
Sure, will try later.
I wish, the pile sizes were within 10^5 range.
then I would have solved this question in 25-30 minutes :P .
yes we can. my submission ran in 406ms and i am running sieve till 1e7
yes, use linear sieve
Here, you forgot to include a link.
Normal sieve, if implemented correctly, runs in O(n*log(log(n))), which is sufficient (my sol passed with it).
Don't use " NOT NOT " in your statements ever again please
And yes, I googled E, sue me (I suspect many others did or have seen this problem before anyway)
This makes me wonder how many people thought of E during the contest by themselves instead of just googling. Because I couldn't think of anything after more than an hour (sad noises**)
I have spent most of the time going back and forth: "This is coprime nim. No, this isn't coprime nim. What if I take only divisors? But I can take any non coprime number. Wait, this is coprime nim, gcd should be equal to 1"
In regards to coprime nim (and not divisor nim, non-coprime nim and other variations) I've come up only with the most obvious stuff on my own:
D is maybe just next and previous tables but in order for me to implement it I would need maybe 400 line looking forward to see how people did it nicely
I'm curious if E is a classic problem of SG function. I don't know how to do it, but I have a vague feeling that it can do it.
what is SG function?
Sprague-Grundy function, super useful for nim-like problems.
Consider treating the game process as a DAG, taking the SG function value of a node as the mex of the SG function values of its child nodes.
I just generated all values of SG and guessed, then I realized that $$$g(x)$$$ is equal to the smallest prime factor of $$$x$$$ ($$$g(x) = 0$$$ if $$$x$$$ is even))
C < A < D < B
Maybe I'm salty for not solving E, but is it ok to put a somewhat well known problem that apparently has a solution on the internet to a contest?
I am not a big fan of E myself but its edu round so the authors are somehow justified
Should such a contest be rated for anyone at all? C,D,E all were kind off not div2 level. If someone had a day where they did B and D fast enough (I couldn't, maybe thats why i am putting this out), E was a walkover.
Lovely problems thanks, problem B and D were a bit implementation heavy unless I just missed the obvious solution and did something unnecessarily long.
I think that D need a trick like bitmasks or else it would be so much pain
My solution was a few hundred lines long without bitmasks haha
I got WA test 2 in D until the contest is over... unable to fix the code in time
binary search the indices would be enough no need for bitmasks
OMG! same avt. best of luck
yeppiee, u too
look at mine 276671836
Why this code (https://mirror.codeforces.com/contest/2004/submission/276666440) shows strange behavior when all the array elements are equal, for example:
5 4
3 3 3 3 3
Shouldn't the answer be 3 here?
Also i tried printing the final array after all the operations done, and in this case it is 3 3 3 1 0, but according to code none of the elements should change. Where i am going wrong?
Update: There was problem with my keyboard language setting due to which a special character was in the input instead of 3. But the solution is still wrong i think.
The variable ind will still bea -1 after your operations on nums, adding an another verification may help.(Though the solution is still wrong as you don't need to adjust all the numbers)
Okay, let me try once again, thanks.
Wasted so much time on B lol, though D was very enjoyable!
I enjoyed these problems
If you ever feel stupid, I got +7 penalties on D despite solving it in 20 minutes due to writing this function:
small piece of advice.next time create character set. and put characters of both the strings inside the set.
If the set size is less than (a.size() + b.size()) , means there is an overlap <3 .
I had the same issue and couldn't figure it out in contest lol. 276656805
IMAGE
i got also got penalty on D, because of this: wrong submission: 276659462 correct submission: 276671836
can any one tell me what is the wrong in my code in (d) or if i missed some cases may be 276679658
My sol for D looks like abomination 276680579
at least you solve it
R u blind? He didn't.
oh my god i was think he solve it
He did later.
Lol, u r also blind xD since he didn't
Not during contest, but he did :)
Doesn't count :D
thank you
It clearly says Runtime error on test 2 so they didn't.
sorry, wrong submission
Holy mother of God what is that code
Bro what, 800 python lines...
276679322 Mine is not too far off xD , just that mine TLE'd
Lmao i just brute forced the first 100 grundy numbers and stared at the screen for 45 mins until i observed pattern
what is the pattern in this problem?
for even its 0 and for odd it is same as the grundy number of its smallest prime factor
Oh god, I've just realized that I misread the statement completely LOL. There was two "not" in the statement @@.
How do you solve D??
if x1 and x2 dont share a colour, then you want to find the closest city to the right of x1 and the closest city to the left of x1 that share only 1 colour, then you calculate which of the 2 paths is better. im so salty i couldnt implement this, but this is the solution i think
i was think if you find the closest city to minimum one between of them you can find the answer and i think this do same idea you mention but i got wrong 2
I added a 13 minute video editorial. Hope this helps.
For each pair query, there are three cases you have to consider:
Case 1: The two portals are not opposites (i.e. they share a color)
In this case, you can just directly teleport with a cost of their distance in the array
Case 2: The two portals are opposite (they do not share a color), but between them there is a portal color combo which is different from both
In this case, our cost is also just their distance in the array b/c you can just teleport to the element between them to get from one to the other
Case 3: The two portals are opposite (they do not share a color) and there is no element between them which has a different color combo than either one
In this case, we have to calculate the shortest distance from the left of the leftmost query point to an element different from it which is not its opposite and likewise for the rightmost query point to the right instead. We then take the minimum of these distances we call mindist which naturally gives the total cost for the query to be 2*mindist + the distance between the query points. If there is no such minimum distance (i.e. there is no way to get between the query points at all) then we instead output -1.
One can implement the third case by iterating forward and backward through the array for each color combo to fill an array of pairs calculating the index of the nearest element that is not equal and not opposite to its color combo both to the left and right.
can you tell me what's wrong in this solution for C? https://mirror.codeforces.com/contest/2004/submission/276677983
my code for C could pass the sample test cases but i kept getting WA after submission :(
i wasted 1 hr on it lmao, was C really so easy?
try using long
just tried using long long, still WA
Look at my code if it help
The problem is that if the array is initially of odd length, then you create a phantom element equal to 0 and further consider it as the original one and, accordingly, you can add values to it, which cannot be done, in fact, it does not exist.
Test when the code is not working correctly:
1
3 1
1 5 5
Program output: 0
Correct answer: 1
According to the logic of your program, element 0 is created and the array turns from [1, 5, 5] into [0, 1, 5, 5]. After that, in order to get the optimal answer, your code adds 1 to 0 and you get an array [1, 1, 5, 5]. Thus, the result will be equal to 0.
It turned out that we optimized the response using a non-existent element.
In a situation where the array is of odd length, you need to use another method — immediately add the minimum value in the array to the answer and then remove it from the array, thereby making it an even length
wow i wasn't expecting an answer so well explained lol. thanks a ton, i understand it now.
honestly i feel i could easily be cyan but i always mess up small things like this, for example related to the range of inputs, such as writing >x instead of >=x for some loop, etc. and realizing that after wasting 25 minutes on that. since you're blue do you have any suggestions for me?
The best practice will be to solve implementation tasks outside the contest and set a goal to pass the task the first attempt. That is, spend a lot of time checking all the key points of the code and be 99% sure that all the places are implemented correctly.
In the contest itself, you can:
1) Write a naive solution for small values and compare the answers received with the code that you are going to send
2) Manually check the boundary values, experiment with the boundaries (try to change > to >= or even to <, try to change the data type (if an overflow occurs))
3) Check each part of the code and intermediate values separately (whether the array was built correctly, whether the answer is updated correctly at each step, whether the necessary variables are used everywhere, etc.)
Usually these steps are enough, if not immediately to send a solution without bugs, then after an incorrect attempt to quickly find where it can be the error and fix it
makes sense, thanks. i'll try solving a bunch of div. 2 Bs and Cs and try to get them right on the first try
Is there a $$$ O(n^2) $$$ solution for F?
just use hashmap
https://mirror.codeforces.com/contest/2004/submission/276639528
too tight constraints for D. This is a QlogN and not passing? [EDIT SOLVED . I was declaring the vector again]
O(N+Q) is possible (via previous/next tables for all six pairs, for example), so this may be a TLE intentionally
But there will be only 4 pairs possible
https://mirror.codeforces.com/contest/2004/submission/276683926
with vectors+lower bound tle.
Do you mean to say the complexity is not O(qlogn) but O( (n+q)logn) ?
I meant to say that an O(n+q) solutions exist, so I'm not sure if O(qlogn) is intended to pass. As @rahulmysuru7 pointed out, your code runs even slower, so it's not relevant to you, I was just guessing what might be the reason
Ohh I see. I will think of N+Q solution too.
Thanks for the response <3
@mahendraakshansh ~~~~~ for(int i=0; i<4 ;i++){ set ss = mp2[vv[i]]; .... ~~~~~
yeah ,you fked up here. you are declaring and extracting the entire set inside here. making your code O(qlog(n) * n)
fck me thank you so much.. I am a noob
E is too educational even for educational round
not sure why this is TLE?
https://mirror.codeforces.com/contest/2004/submission/276681345
I dont get my solution is of O(qlogn) but I am still getting TLE on sixth test case, tried so many things but still got tle on sixth, please tell where I am wrong my submission, My submission Link
you are copying the whole vector everytime in binsearch, this could be the issue vector vec=mpp[s];
And, when I thought its better to be good at code writing , I fcked up. Thnx man got accepted
B is the hardest out of the first 5 tasks for me 😭 Also, how tf does E have like 1400 ACs? Do so many people know sprague grundy now?
apparently its a well known problem with solution on the internet, im just surprised so many ppl managed to actually implement D.
B was also hardest for me. I wasted 20 minutes on casework before just (correctly) guessing the pattern. E was googlable.
I remember seeing a cf blog about game theory a few weeks ago that explained how to solve Nim problems, so that might be why
so, How B? Help me please !
I just bruted for all bridges [i, i+1] upto 100 in the end
Break the problem in several cases.
ref : (https://mirror.codeforces.com/contest/2004/submission/276649235)
Case 1: When there is no overlap ----> only blocking one gate will work.
Case 2: When there is an overlap at exactly one point ----> Block two gates.
Case 3: When both the intervals are same ---> Answer will be difference between them.
Case 4: When all the 4 points given are distinct ---> answer will be diff b/w overlap region + 2
Case 5: When only 3 of them(l, r, L, R) are distinct ----> answer will be diff b/w overlap region + 1
Analyse all the cases in order on pen & paper you will get the idea.
Oh I missed case 2, completely skipped my mind
Same here, took time to figure it out.
You can just consider the intersection of the two intervals(you need to place a door between every two cells). Then if there is anything to the left or right of the intersection you need to add 1 door for each case. In case the intersection is empty the answer is 1 as you pointed.
thanks everyone
should I feel proud that the problem I found easiest was hardest for Candidate Master (even thought I could only solve till C) :///
no, as they have a room temperature iq
looks inside
a Nim problem
Why? Just, why?
Fr I was not even thinking around the lines of NIM after looking at the title. 1400+ accepted submissions for that is crazy
One small step for man, a giant fall for my rating.
Don't know why I hate L and R problems which have O(1) solution. Just hate the casework! P.S Talking about problem B
Damn, my programming skill is so bad that I couldn't implement C. The first test cases in problems are weak and doesn't help to find even some edge cases. E has no explanation for how Bob wins in the third case. Next year will be our year.
if u ever feel stupid then just know that I exist : wasted my whole contest on C only to realize it was total increase<=k, not k for every element
The question of double negative sentences is very unfriendly to foreign contestants, which seriously affects the questioning, and I feel very angry about this
Can someone pl look what is wrong in my implementation of D.
Link
if it_low==pos.end() you should try finding the last position <= x
D was actually easier to implement than I thought after I realized you could iterate over the colors and only check when you found an overlap for both endpoints. Then just binary search on the nearest index.
A, B, C, D, F is fucking easy, especially E is just grundy number which is not suitable for an edu round!
fucking rooms
For problem E, I found out quite early that I had to build grundy numbers for all possible number.
But I completely forgot all the theories. Almost all the time that I took for solving E was trying to figure out grundy again and for reading the question wrong and solving a wrong problem first. :3
can anybody point out whats wrong with the below idea for D ? (since failing testcase 2 is not visible till end of hacking) Submission: 276681155
Now for queries that have cities from one of the disconnected type we try three options. (WLOG assume y > x).
Find some city in range [x,y] that does not exist in the same disconnected group of cities as the queried (x, y). If found successfully then answer is again simply abs(x-y).
Find the closest city to the left of x and the *closest city to the right of y that are not a part of the disconnected group. Then answer is abs(x — x') + abs(x' — y) OR abs(y — y') + abs(x — y'). Take the minimum of the two.
If nothing is found in 1 or 2 then all cities lie in the same disconnected group and so the answer is -1. (remembering that we already checked for direct edge between the queried cities as the very first step).
Sounds right to me.(You mean "closest city to the right of y", not "largest city to the right of y", right?)
yeah i wrote that by mistake. I mean closest missing in the prefix of x and closes missing in the suffix of y. Looks like I effed up the code then. If you can take a look at it please ? (I assure you its written cleanly as much as possible.)
Sorry, can't spot a bug immediately. Maybe there's some bug in the implementation detail in finding the closest city to the left or right? Some off-by-one error, maybe?
Yep, no problem, I'll find it somehow. Thanks a lot!
found it: did subsum[l,r] = (psum[r] — psum[l]) instead of (psum[r] — psum[l-1]) :'(
if i understood it properly, that is the solution. the hard part of this shitty problem was the implementation
idea looks right, you might have made mistake in implementation.
thanks i'll debug against some AC solution I guess then.
I don't like problem B and E (because I had a hard time with them, obviously). B is a boring classification, and for E you only need to print out the table of SG function values and find the pattern. TBH I didn't feel the joy of solving Cf problems in these two problems.
just now I was searching for D solution on youtube and saw problem A,B,C ,E and F were uploaded there during contest
my submission for problem b gave some negative number for first submission- https://mirror.codeforces.com/contest/2004/submission/276574322
and same solution got accepted after a few minutes-
https://mirror.codeforces.com/contest/2004/submission/276595377
if it is some kind of error from system then please recalculate penalty for this problem for me
I don't think they can be called "same solution".
The calc function in the first submission calls R itself in calculating R, which is undefined behavior
My code is producing the[submission:276685070] wrong answer, but I can't figure out why. Could someone help me identify the issue?
hmmmm whats wrong with my O(qlogn) solution for Problem D that got TLE on sixth test case? I realized that set::end is O(n) so i precomputed it in the
what
vector, but still didn't work. all other ops are O(1) or O(logn)submission
Use s.lower_bound instead of lower_bound(s)
Former has O(logn) and latter O(n)
yo what the heck! i had no idea. thank you so much. do you know why? same function yet big difference in time complexity.
You can see here set time complexity
didnt got D in time cause wasted 1 hour on fckn annoying B, for what do shit like that? B in hour, C in 10 mins)
Can someone help me?Your text to link here...
Your code looks correct, but you're getting a Wrong Answer (WA) on test case 5992. Unfortunately, I can't see the specific details of that test case
bro whattt
I am getting tle on test 5 can anyone help 276686377 even if the soln is qlog(n)
comlexity of your sol is n * q * log(n) see this accepted code using your code 276705976
thank you so much I got it .
i have no idea why my D is failing, i found the indices of all 6 types of values closest to the left and right and did accordingly am i missing something. solution
You have made exactly the same mistake that I made.
You need to take,
UPDATE :
That is exactly the issue. I copy-pasted your code, and changed one line. Proof :
https://mirror.codeforces.com/contest/2004/submission/276688327
dude i am crying......, i was burning my blood for this :(
Happens, don't worry. Happened with me also, I got 2 wrong penalty submissions for this.
E wasn't new...
projecteuler560
This is allowed during Educational rounds. It's one reason why they aren't rated for Div 1.
Source for this please
https://mirror.codeforces.com/blog/entry/21496
I don't think anything in the blog implies you can take exactly the same problem from somewhere else.
It's not exactly the same problem.
Project Euler asks you to calculate the number of losing positions with up $$$n$$$ stones in $$$k$$$ piles, while this round asked you to evaluate the winner for just 1 given position.
Looks to me like the CodeForces problem is strictly easier, except of course Project Euler has no fixed time limit.
It's true that the crucial insight behind the two problems is the same, so it's not completely new, but again, that's not unusual for Educational rounds and as far as I'm aware that's intentional.
Fair enough
Can someone explain to me why the code I submitted during the contest was rejected but if I submit the exact code with 0 changes after the contest it gets accepted? In fact I modified the code to get the test cases where it was failing at and that code got accepted when I thought it is obviously wrong.Can someone go to my submissions and check?
awoo Why for Div2+ rounds you keep giving problems where cheating is extremely simple? No implementation, but only one critical observation which is extremely easy to pass from a cheater to another cheater.
Since you are giving feedback to Awoo, regarding the contest. I would like to chime in.
I didn't google a shit during the contest. usually I don't. For me, E was really good problem. except for one part, extra BOILER PLATE IMPLEMENTATION for sieve.
I would like to understand what was the motivation to keep pile sizes 10^7 instead of 10^5.
The problem would have been same, if the pile sizes were within 10^5. The core-crux of the solution logic would be same. generating prime till 10^7 and then doing extra implementation things, were more of boilerplate code.
Maybe so you can't completely bruteforce the Grundy numbers and actually have to come up with the "Grundy number of x is the Grundy number of its least prime divisor"? That would make sense in my opinion.
yeah, makes sense.
What problems are you talking about? C? For B and D, implementing a solution correctly is IMO much harder than coming up with it. For E, you still need to know about Grundy numbers and not screw up calculating for the small piles. And pretty much every single A is easy to implement, because it's supposed to be really easy, so there's not much organizers can do with that.
I spoke about problems D and E in particular. Ok, please tell me if these solutions for B and D look hard to implement. Do they?
I didn't realize B is just bruteforce-able like that and was thinking of an O(1) per query solution. I agree doing this is easy. As for D, I don't think your implementation is particularly easy, and looking at the comments, there's a bunch of people with the correct idea that failed to implement it, so I stand by it being difficult to implement.
B in O(1) per query. Need to block full intersection, additionally extending it by one on each side if needed.
Not that great of a contest IMO. A and C are fine, but B is just annoying casework, D is basically just implementation, and while I enjoyed E, it's googleable.
In B u can only check if 'i' is in one segment and i+1 in the other segment for every i in [1,99] then add 1 to the answer, there's no need for casework.
True, didn't realize that doing contest. Doesn't really change my opinion about quality of the problem though, as the fastest solution still suffers from this, and I personally dislike when there's a fast solution that's more complicated than a (significantly) slower one, yet the slower one still passes everything.
I liked problem B. There are different ways to solve it, some of which don't require a lot of case work.
You complain that problem D is mostly implementation, but what's wrong with that? It's a programming contest, not a math contest.
Going by your username, you probably love math problems, but if all problems are math-based other users will complain about “MathForces”.
And problem E was much more math-heavy, so there was something for everyone. In my view the authors struck a good balance between math and code.
So, many $$$n^3$$$ solutions passed in F.
An easy way to fix it would have been to have $$$1 \le a_i \le 2 \cdot 10^4$$$, and decrease the TL to $$$3$$$s maybe. I had to use map because it was not possible to have a global vector of size $$$4 \cdot 10^8$$$. For the suggested constraints, one can simply use a global vector of size $$$8 \cdot 10^7$$$, and find $$$f(a[l,r])$$$ in $$$O(1)$$$ by traversing over $$$(l,r)$$$ in the increasing order of $$$r-l$$$.
$$$O(n^2)$$$ using your idea 276838722
some leaked codes that yall best be on lookout for
All of them has the useless check in their code for problem E lol.
In Problem D, I got wronganswer on test 2. I can't find my mistake.can any one help me? 276676154, and why everyone use lower bound to find the closest point from x and y, cz the vector are sorted and we can find it O(1).
update : problem solved
Can someone help me understand what I missed in
Problem D
?Submission: 276664135
Idea:
If there is a Portal with same color available on source and target, then, it is
target - source
.If not, then :
Let's say for example, source is BG and target is RY, then, I check for the minimum value of below logic with these 4 portal pairs — BR, BY, GR, GY. (i.e., trying to see if at-least 1 color matches). If no suitable answer, then return
-1
.If any of these is present inbetween source and target, then, it is
target - source
.Else if, it is present after target index, then,
(foundRight - source) + (foundRight - target)
.Else if, it is present before source index, then,
(target - foundLeft) + (source - foundLeft)
.Else, INT_MAX
But four more cases are possible- RB, RG, YB, YG.
.
The problem statement clearly stated only 6 types. Unlucky.