안녕하세요, 코드포스! (Hello, Codeforces!)
I'm glad to invite you to Codeforces Round 620 (Div. 2). The contest will start at Feb/15/2020 16:05 (Moscow time), and it is rated for all participants with ratings under 2100.
You will be given 6 problems and one of the problems has 2 subtasks. The contest duration is 2 hours. The score distribution will be announced later.
All problems are prepared by me, with huge help from the testers with developing great solutions.
I'll be on the community Discord server after the contest to share my thoughts and get feedback about the problems.
Thanks to 79brue, molamola., Savior-of-Cross, evenharder, cs71107, Justice_Hui, rkm0959, chpark1111, imeimi, InfiniteChallenge, gaelim, jh05013 (Good tester), yuto0518, N_jara, aryanc403, SnowGoose, solvemproblr, surung9898, and ko_osaga for testing the round. I would also like to thank 300iq for round coordination, and MikeMirzayanov for the great Codeforces and Polygon system.
Hope you enjoy the problems!
UPD: The scoring distribution is 500 — 1000 — 1500 — 1750 — 2000 — (2000 + 1000)
UPD2: The contest is finished! Thanks so much for your participation! The editorial is here.
UPD3: Congratulations to the winners!
Div. 2
2: COVID-19
3: naive_xay
4: anta.baka
5: ChitandaEru
Unofficial Div. 1
1: wucstdio
2: ksun48
3: jiangly
4: uwi
5: teapotd
Wow! Another Korean Round! I hope you enjoy this round. I am a tester of this round, and I think you would enjoy! Good luck and have fun.
Last round made me a pupil because I believed in a similar statement.
I don't think jh05013 is a real newbie.If you see in his first two contests he solved 4 problems and then i think he just didn't care about his profile maybe because he likes being a tester more , so he just intentionally solved 0 problems.And no offence jh05013 but you are just 3 points of rating away,breaking the world record of the most newbie.
he said in the linked thing that contests were too stressful for him (he was 1700+). Now he just don't care to mess up :)
Moreover, in this link, he said he is willing to inspect contests(though these are other site contest), and said to call him a tester if someone wants to. Based on the positive response people have to this article I can conclude he is a good tester.
Finally a newbie Tester this time... So all colors tested this round...sweet
newbie with peak rank 1708
우왕!
.
colorful testers
Fan E AE YO
:v Testers in every ranks !
G
Alright the time will be changed accordingly as cf revolves around your schedule :p (not rlly)
Editorials ?????
Here you go.
Ohh!!! I am sorry man, I was looking for Round 619 Div2 editorials and ended up posting my comment here. I just realized this.
Hope B will be clear this time. Past 2 contests Test Cases for B were very hard.
Allways read B before submitting A ;)
OwO,well...Korea round is my nightmare,hope pass C
As one of the lower ranked testers, I would highly recommend participation in this round. These are good problems, there is something for every skill level here!
I wish positive rating for every participant :)
We all wish that but this is not possible.
The total rating decreases after every contest, otherwise, ratings will become higher and higher because new users will join Codeforces with the initial 1500 rating points.
Round with subtask
팬이에요! :fan:
Is Codeforces started to support the Korean language? Cool.
Can someone tell me what does one of the problems has 2 subtasks means? thanks in advance.
I'm not quite sure, but it may be an easy version and a hard version of the same problem. Like C1 & C2 for example.
One of the problems has an easy version and a hard version. You'll know which problem has subtasks after the contest starts.
I hope the problem statements are short and clear.
Want to be Pupil today.Wish me good luck
I wonder what is jh05013's real rating.
Because when he became blue.I can only solve div.2B problems
Maybe he have a real rating of Grandmaster or higher :>
I found a really interesting thing that jh05013 and I have both the lowest rating -43 and after that, our ratings both increase 3.
How to solve E?
Edited : Thank you to all who replied. Because I got TLE on pretest 14 during the contest, I'll try again using the faster LCA algorithm.
Hint: The added edge is there for parity reasons.
I know that, but I failed to optimize the running time.
Do I need to know "LCA"?
Yes.
In fact,I have never solved any problem about "LCA".I need to learn more!
That was the reason I got when I said E is a standard problem.
wai- how are you even cm?
I know parity reasons. but I don't know distance between two node is long than k or not without time limit exceeded.
With LCA you can find the distance between two nodes in a tree in $$$O(1)$$$ or $$$O(\log n)$$$ time (depending on which LCA algorithm you use).
I think you need learn "LCA".
Thank you, I catch a keyword. I'll study LCA algorithm.
I didn't solve this problem as well,because I didn't know how to know the distance between any two nodes quickly.QwQ
only three possible ways l = a -> x -> y -> b l = a -> y -> x -> b l = a -> b
if l<=k and l%2==k%2 then we have a solution
Did the same but didn't work :(
I do not get it how to find the shortest possible path after adding x,y, we need that to check against k. Somebody explain?
Edit: Or is it expected to do a BFS to find it? That would be to slow.
You need to make use of precomputing depths, and LCA ( Least Common Ancestor ) of two nodes. Read more here.
The LCA does not help if the path after adding the new edge x,y is shorter than the one through the LCA.
Edit: After reading the other answer below I understand. We simply use LCA again to find path length from a to x and y etc. Thanks for explanation.
Read my comment below. After adding the edge the shortest path will have to be one of the three alternatives. ( It can be proven ).
The path between two vertices in the query may either go through the added edge or not. Analyze these cases individually, finding path lengths in O(1) using whatever fast LCA algorithm you prefer. Then if the difference between the length of the path obtained in some of these ways and the desired length if divisible by 2, answer is yes, otherwise no.
Root the tree at an arbitrary vertex. Precompute depths of each node to give distances between two nodes in $$$O(log(N))$$$ time using LCA.
When adding a new edge $$$(x,y)$$$, there are now three possible paths ( without going back and forth ), which are
original path between $$$(a,b)$$$
$$$(a,x), (x,y), (y,b)$$$
$$$(a,y), (y,x), (x,b)$$$
Now, if any of these paths can reach $$$b$$$ from $$$a$$$ in less than or equal to $$$k$$$ steps and has same parity as $$$k$$$, then answer is YES.
First we do not consider added edge. We can 'hang out' instead of actually making meaningful move as much as we need — which is, if we can arrive $$$b$$$ at $$$t$$$, we can hang out some even number of steps loafing back and forth.
Then we consider new edge. Since new edge form a cycle, it opens new possibility — by loafing around in cycle. If cycle length is $$$l$$$, we can arrive at
for any arbitrary nonnegative integer $a, b$, where $$$p$$$ is shortest time we can arrive at $$$b$$$ using the added edge. (If we are not using the new edge, we can't hang out on the cycle).
All we need is careful casework (there aren't many) and computing distance in trees using LCA or some other fast methods.
Am I the only one who solved A with binary search instead of much more obvious 1 liner solution?
If there is the point to which we get after $$$k$$$ steps from both $$$x$$$ and $$$y$$$ is
$$$x + k \cdot a = y - k \cdot b$$$ $$$k \cdot a + k \cdot b = y - x$$$ $$$k\cdot (a+b) = y -x$$$ $$$k = \frac{y-x}{a+b}$$$
So, if $$$(y-x)\%(a+b)=0$$$
then answer is $$$k$$$, in other case the answer is $$$-1$$$.
I realised this simple solution when I revisited problem A for locking it, after solving up to problem D.
this is owsam explanation but I used binary_search here
I used binary search too, and needed the editorial to make me think of manipulating the equation :)
How to solve C?
After each customer comes in, you have an effective range of temperature, let it be (x, y). For the next customer find the intersection of (x — t, y + t) (where t is difference between entry times) and his temperature range. That is your new effective range. Initial range is (m, m). If all the intersections are non-empty you can satisfy, otherwise no.
Thank you, it certainly makes sense to me now
I did the same thing but I got WA in pretest 3
I got the same result in the beginning. Apparently, I was breaking out of the for loop without taking all of the input.
yea one need to be careful of that
I got 1 WA for same reason. By coincedence it passes the example input QAQ
(lo - (ti+1 - ti), hi + (ti + 1 - ti))
ti+1
and updatelo
andhi
. (Not sure if this step can be optimised further but it passes the problem limits)My submission 71152069
I have a solution that is easier to implement in my opinion.
Loop through all pairs of customers. If it is impossible to reach the second Customer's range from the 1st Customer's range in the time difference between them, then the answer is impossible.
O(N^2) solution.
I think your solution will fail systest
It already passed 71138487
congratulations on becoming CM. Now I see why your solution passed.
Thanks!
How to solve C and D guys ?
For C
Let's say that we have minimal and maximal temperatures with which we can get to the next consumer, and if the intersection of our range and range (l,r) is not empty, then it's okay, now we just update our range — basically it would be equal to intersection of ours and (l, r).
My submission: 71146715
Thanks, I only know how to solve case (x < l) and (x > h) but not (l <= x <= h) :<
good explanation thanks Mr.Hakimov
For D
The main idea here is that for minimum we should build our array in such a way that bigger numbers have lower indexes and for maximum bigger numbers should have bigger indexes.
You can chek out my submission: 71159214
Thanks. But can I solve D problem using prefix array & suffix array ?
That's a good question, but I don't think that there is a necessity in them :)
If I use prefix-suffix array, what should I approach
how to solve D?
For Min: starting from the first '<', start at n and go down but if there are <<<< or something sort that subarray then for the rest just go down by 1 each time so say for the 2nd sample, my answer would be 5 4 3 7 2 1 6
Max: for max it's the same thing but all the numbers after a < are going up so 5 4 3 6 2 1 7
Thanks for the contest, have a good day problem setters <3
In Problem B of DIV2. the problem statement mentioned that the string can be "REORDERED" and not "REVERSED" but my code was failing the first testcase here : https://mirror.codeforces.com/contest/1304/submission/71145055
No, you can't reorder a string. You can reorder the list of strings.
Ohh Okay. But this got me very confused and thus wasted a lot of my time.
strings can be reordered not a particular string !
I can't see your code, but "Strings can be reordered" means order of concatenation can be changed, not the strings themselves
The list of strings can be reordered, not the strings themselfes.
My AC solution outputs the test case: 2 2 aa aa -> 2 aa. When I think it should be aaaa, 4. Can somebody explain me why !?
It is an invalid input because all strings must be distinct.
Can someone please tell me why this code for C is giving rte. The only place where an exception can be thrown is the assert in which case the test cases are wrong. https://mirror.codeforces.com/contest/1304/submission/71155599
Perhaps it has to do with your usage of the word "time"? I think it's a reserved keyword that can still do arithmetic with integers. You're right, the code itself doesn't seem like it can segfault as far as I can see.
I had submitted the same code without the assert line. That gave wa.
That doesn't necessarily imply much; undefined behavior is still within your set of possibilities. In fact, I'm much more inclined to think that you have UB somewhere; this would probably cause a segfault sometimes and a WA at others.
The thing is that I have been getting RTE only when I have included assert in the code. I have submitted the same code without assert thrice (introducing one useless variable each time so that it allows me to submit) and got WA in all those.
I've gotten several questions regarding this.
The problem is that you're "returning" the function while you haven't gotten the full test case yet. Some people used 'break' inside a loop. These codes generally got incorrect on pretest 3.
Yes that's the mistake. Thanks for pointing out and sorry for wasting your time.
I got similar Runtime error in Problem B today. It was resolved by removing #define int long long. I couldn't figure out Why it happened today, I haven't faced any problem due to this statement earlier.
My Submission link: Submission
You are returning from function, "solveTestCase", before taking all inputs. Instead return only at the end of the function.
Okay yes. That is the error. Thanks for pointing out!
Every time........!
I feel exactly the same. :(
Thanks for the round, hope pretests were good enough.... I wish everyone to increase their rating ;)
Oh,just five minutes after the contest over my solution passed all the examples.:( The code for the round are a little bit long. I think a longer time will be better.:)
Why does codeforces skip main test and don't take the best submission? I missed my chance of becoming Master today.
I don't understand what is wrong in my submission, the answer is printed but still it shows run time error. Here is my submission 71154644
if(second.size()==0) It will give run time error .
Could you explain why?
Because second.size does not returns an int value therefore second.size() -1 will not be -1.
here i come #808080
really sad, failed B on test 13.
It was such a good contest for the beginners. As the problems were not so hard as before :) But I think it should be harder, especially the Problem F.
If contest was 4 hours instead 2 I was solve all :-(
My color is going to change. I love these questions!!!
Thank you for strong pretests!
Question B : Why there is run time error coming in https://mirror.codeforces.com/contest/1304/submission/71161367 this code can anyone tell me?
because of this loop for(i=v.size()-1;i>=0;i--). v.size() does not return int value.
https://mirror.codeforces.com/contest/1304/submission/71145443 : what's wrong with this code
The problem is multi-case. which means you can't puts("NO") then simply return, or as the input continues, in fact your program will read the wrong data.
oh! thanks...
What is the mistake in this code, I am getting wa on prestest 8
code: https://mirror.codeforces.com/contest/1304/submission/71165457
If you erase elements in a set while iterating through it, especially your current pointer, you might end up skipping a few elements. This is shown when you run your code on the following case:
A different approach is to scrap the set entirely and instead use an array of strings, with boolean markers that say if you've used that string already (example, with the
mk
array).Thanks a lot man!
But why does it skips a few elements?
I didn't realize that you called a vector s, but it functions the same as a set in this context. My bad.
Imagine your vector like this:
Now you find
ba
to be a match withab
, so you erase them both. Where does the pointer go? It can only advance tocd
:Now you increment the pointer, and it ends up at:
Since you only check ahead of your current iterator for matches, you don't find anything else and terminate. There's probably a topic on StackOverflow addressing this issue, but the basic premise is to only increment when you don't erase.
I believe test cases for D are a bit weak?I changed my code for D a bit during contest as it had 1 mistake, but after the contest, it still passed....
71166353 works on pretest 4 on my machine, and on ideone link but failed during contest and also on custom invocation. MikeMirzayanov djm03178
71177225 unordered_map -> map => WA -> AC
the same code gives correct output on my machine and another ide and on codeforces if used with c++17 but fails with c++14, i want to understand why is that the case, exactly what is not working in this case.
have you figured it out?
no, changing the order of input strings makes the test case pass in custom invocation on cf, when i tried to debug in cf custom invocation it was weird, somehow the entries in my unordered_map were getting corrupted during the execution. AK18
AK18 however the logic is same, unordered_map -> map should make no difference really, to me it seems like deep magic
I just changed unordered_map -> map and used C++14, it's AC. I guess it has something to do with the unordered map which I am not aware of. 71278944
The problem is
int count_r = freq[r];
. It causes theunordered_map
to insertr
if there was no such element. By result, rehashing can occur, and therefore all iterators are invalidated, affecting the loopfor(auto x: freq)
in a bad way.In contrast, using
map::operator[]
doesn't affect iterators at all. Check these two documents:https://en.cppreference.com/w/cpp/container/unordered_map/operator_at https://en.cppreference.com/w/cpp/container/map/operator_at
Thanks :)
My solution of B is failing in this test case but somehow it managed to pass system testing —
3 3
tab
bat
tab
All strings are guaranteed to be distinct, so your test case isn't valid.
sorry
where i am wrong? https://mirror.codeforces.com/contest/1304/submission/71174871 problem C
i am iterating in reverse, finding the largest intersection possible so that both current and previous customer are satisfied with temperature
Not sure if I should be posting this here, but:
I just got a message saying that my solution for problem E coincides with that of some other participants. This is likely because I used the CP Algorithms implementation for LCA which you can find here: https://cp-algorithms.com/graph/lca.html
Although I added a few additional methods in my source code, a big chunk of my solution was for the LCA structure. So I guess that could've set off the response. I hope this clears things up.
If you need any more information, please let me know. MikeMirzayanov
I am not sure whether I should comment here . but i just got a warning about coinciding my code with another user.Since I am new here , I dint know about the codes copying from ideone . I was using IDEONE in default setting. My code is https://mirror.codeforces.com/contest/1304/submission/71137281. And the guy who copied my code is https://mirror.codeforces.com/profile/8bit_thug I request you not to do this. this kills contest spirit. And yeah Since He submmitted code after 3 minutes when I submitted hence it is cleared that he copied my code. Moreover all his submissions are skipped. Do I need to provide more information? MikeMirzayanov
My solutions for this contest were skipped most likely because I used the implementation of LCA from here which is probably where some other participants picked the code up from.
djm03178 can you look into this?
Sorry, there's nothing that can be done from my side.
Alright. MikeMirzayanov
Мое решение 71159863 по задаче 1304E совпадает с решением другого пользователя, так как видимо мы использовали один и тот же источник, а именно https://e-maxx.ru/algo/lca.
I got a message from User system regarding code similarity about the E problem (71164831). I have used the code for lowest common ancestor from this site (same code published in the site mentioned by other affected users) which was last updated on 15th June 2018 (here) which is conclusive evidence of this being published well before the contest.
I hope this is the right place to put this, otherwise, please tell me where I should write this. I received the following message:
For the solution of problem E, I used the RMQ (range minimum query) and LCA (lowest common ancestor) implementations from https://github.com/kth-competitive-programming/kactl/
Specifically from https://github.com/kth-competitive-programming/kactl/blob/master/content/data-structures/RMQ.h and https://github.com/kth-competitive-programming/kactl/blob/master/content/graph/LCA.h
This code was online long before the start of the round, so I hope, this issue can be resolved.
Thanks for the round btw. I enjoyed it.
Can someone answer why the compiler of Codefoces gives run time error if i have not type casted size of a vector whereas most of the other compilers don't give that error. In this contest only i got stuck in problem B due to this error.
Me too
the .size() function returns an unsigned integer, so when you try to do.size() — 1 when the size is 0, it overflows and causes runtime error.
Got that...but when i did this for(long long i=a.size()-1;i>=0;i--), it gave me run time error but for this for(int i=a.size()-1;i>=0;i--) it did not. Can you tell me why this happened? And thanks in advance :)
Can someone please explain how I am getting a different output for E on my local compiler than the codeforces judge.71178404
I am the getting the expected output on my machine. I believe the logic is correct. https://ideone.com/LfR13i Expected output with same input
Nice problemset!
Hello MikeMirzayanov, I have received a message about being disqualified from the contest, because of plagiarism. I have used the LCA calculation from cp-algorithm. Here is a link to the web archive, as evidence, that the code has been published before the contest. I have not used any online IDE. Kindly look into this, Thanks a lot!
Hi MikeMirzayanov, I have received the same email, I have also used the LCA part from cp-algorithmm, same source as animal-liberty and also quite a few others as mentioned in the email. Link to source.
Hey,
My solutions were skipped because one of them coincided with solutions of other participants.
It was 100% caused because of this implementation of LCA, which I use for a long time.
Regarding rules, one can use publicly available implementations posted before the round.
MikeMirzayanov can you do something about this?
Me in this contest:
Firstly, solve problem C, and then B-A-D-E-F.
After solving all the problems, I looked at the standings, and found rank 2 is only 61 points lower than me, and he has locked all his problems and started hacking.
So I locked my ABCDE and started hacking too.
When I opened a solution to problem B, I was surprised to find there was a very silly BUG. A code with such silly BUG wouldn't pass the pretests.
So I took a look at the statement, only to find that I had misread the problem. I thought I can reverse any strings as well as reorder them.
1000 points! If I had not made such a silly mistake, I would probably get on the 1st place, but now I couldn't resubmit because I had locked my problem. So I poured out my sadness to jiangly, who had solved all the problems too and become rank 3 at that time.
Here is the chat history:
Yes, I misread the problem again. I forgot that all the strings are distinct.
So from my story we can conclude that it's very important to read the statement carefully, but if you misread the statement, you still have chance to pass the problem.:)
Lol same. I also thought I need to check the length of the only palindromic string I will add in the middle and changed my code in the last minute of the contest. And after 5 minutes comes the realization that all the string have the same length. Lost 500 points and went from +45 to -13.
I just found out that I also misread. Thank you.
In problem D, you can solve for max LIS and re-use it to find min LIS by manipulating the string, ie. reversing and inversing — replacing $$$<$$$ and $$$>$$$ with one another. Here is my solution.
Great contest!
My contest history for this contest is suddenly deleted.Why this happened?
Rating changes for the last round are temporarily rolled back. They will be returned soon.
apology for poor english
where were you when top rate dies
i was sat at work writin code when telegram ring
'top rated is die'
'no'
and you???????
hello in solution B try this 2 3 AAA AAA and it will answer you 3 AAA i think it should be 6 AAAAAA anyone can help me with this i can't see in description that say the same string doesn't count
It says "All strings are distinct."
great contest, but I would have liked if you could have removed problem F1. It is extremely trivial (I think div2C). F2 is the real deal and is a great problem. There was no reason to add F1. (and just because of the long legend and its place in the problemset, F1 is rated 2300, while it is more like 1500).
Again, great problems, especially E and F2, but don't add subtasks which add no value to the problemset.
I agree that F1 isn't very interesting by itself, but the subtask is there mostly because of the difficulty gap between E and F2, and I don't think it's that trivial to be a D2C as you can see how many participants have solved it (both during contest and post contest). I still think it's at least as hard as E. In fact, F1 was initially planned to be F itself, and I improved the solution to make a harder version which is F2 now.
In the end, I think it did quite a job being a bridge between E and F2. For those who couldn't generalize the idea for F, they could write a naive solution to try F1 only, and they were rewarded more than those who couldn't even manage to do it in time.
Well sir, F1 was a very obvious DP, was it not? Once you see the pictures in the samples, you immediately come up with the DP!!!! The transition is so easy! It needs no insight!
The prefix and suffix maximum precomputation was very natural too, like you first came up with the transition, and then decided "yeah, I need prefix and suffix max".
As for bridging the difficulty is concerned, on the other hand, I feel this problem left div2 participants with an even less amount of time for F2. F2 was kinda short to write but because of lazy segtree (in my solution) it is potentially hard to debug. A participant may feel:
but of course you don't agree that the DP was trivial. But I showed this problem to my friends and they agreed that F1 was instantly obvious. F2 on the other hand I really enjoyed, thank you.