Hello, Codeforces! 🤯
green_gold_dog, ace5, bashkort and I salyg1n are pleased to invite you to participate in Codeforces Round 897 (Div. 2), which will take place on Monday, September 11, 2023 in 17:35.
This round will be rated for participants whose rating is below 2100.
You will be given 6 tasks and 2 hours to solve them. We recommend reading all the tasks. Interactive tasks may occur in the round, so we suggest reading this post.
We want to thank:
Aleks5d for coordinating the round and improving one of the tasks. 🤓
daubi, Nutella3000, arbuzick, alegsandyr, maomao90, FairyWinx, zwezdinv, valerikk, danya111, EJIC_B_KEDAX, dushenkov, fishy15, makrav, pakhomovee, alexashkins, Kihihihi, asafiul, Ivan_len, ArtAlex, Undying, JustNik77, Pavarishko and 3e4 for testing the round and giving valuable feedback. 🙏 orz
ryskmax for being the only blue tester and giving valuable feedback. 🐳
DimaTomsk and ilyakrasnovv for viewing some of the tasks and giving valuable feedback. 🤠
stepanov.aa for not testing the round. 🦥 :(
The authors of the task 5. Overtaking from IOI 2023 for bashkort taking a gold medal. 🥇 Too dead? Yes, so am I.
MikeMirzayanov and geranazavr555 for the excellent codeforces and polygon platforms. 🦖 Thank you!
We hope you'll enjoy our problems! Good luck!
UPD. Score distribution: $$$500 - 1000 - 1250 - 2000 - (2000 + 1000) - 4000$$$.
UPD2. Congratulations to the winners!
Div. 2
Div. 1
UPD3. Editorial.
Auto comment: topic has been updated by salyg1n (previous revision, new revision, compare).
Finally ez rating
As a tester, I ask to downvote this comment instead of round announcement
i downvoted both , problem C gave tle on pretest 4 and same logic passed in c++
Yeah, I totally agree. You shouldn't give instructions on how to output in Java for a problem that's impossible to solve in Java if someone follows those instructions.
Problem C seemed so simple yet turned out to be the most painful one. Just wouldnt work with Java
Negative contribution :)
The hidden texts are cute :)
waiting for the challenge ......
omg, two contests in two days!
Good luck everyone!
score distribution?
It will published later on...btw it is mentioned above...
I’ve seen that, but I think it’s a little bit too late and also I want to determine whether to participate in this contest earlier.
good contest!
Don't swear, It is bad
Hopefully I reach closer to cm
Given my past results in Division 2., I am hopeful that I can reach newbie rank again.
As a tester, I will write this round from my second acc 😈
That cliff 1250-2000 :(
Score distribution gives speedforces vibes.
:((
MikeMirzayanov can you please check your inbox?
so why the announcement is "P(G) is't a set" but not "P(G) isn't a set"
what does is't mean,,
too interactive contest
In my opinion problem C has an issue, if there are already $$$2*N+1$$$ queries, why am I not allowed to go to next case myself? Instead I have to input -1 to jump to next case. Why? Because of this, I had a big penalty.
got runtime error 2 times because of this
This ruined my contest. Literally i got 4 runtime errors on pretest 2 for this reason. In the question it was mentioned if 2*n+1 moves are done then the game finishes. Also there were no pretests that had 2*n+1 moves to make it more clearer.
+1
The same thing happened with me, got multiple runtime errors and couldn't fix it until the contest got finished. Ruined the whole focus on the other problems.
https://codeforces.net/contest/1867/submission/223010304 I guess it does terminate after 2*n + 1 moves . Can you check in this submission ?
Firstly you are doing one operation outside the loop and then for each iteration in loop you are doing 2 operations and the loop runs for 2n+1 times resulting in 1+2*(2n+1) operations that is more than the required 2n+2 I/O operations needed
Same here.
salyg1n, green_gold_dog, ace5, bashkort. Isn't it a mistake on author's part? If so, can we manually set my current AC time to my first attempt in problem C? (As it would've been AC in first attempt without this issue)
Exactly spent 1.5 hr while submitting the same code as I can’t notice any error. The round should be unrated.
+1
Hopefully my 2.9s Python submission for C doesn't TLE
Why the java language can't pass the C question, but the C++ language passes. Experience the worst race, hopefully not counting the rankings
Same thing here. I first tried submitting various java solutions only to get TLE. Same logic in C++ passed in first go.
Unfair play
Sounds like a skill issue to me.
lmao based
Same issue.
My best guess is for test like #4 where T = 100000, the system judge does not generate the input data for next test in stdin fast enough after the previous test complete.
I tried to simulate stdin for 100000 tests each with n = 1 on local machine like below. It measured 185 msec. So the fact that test #4 always TLE in system tests suggest some kind of delay introduced by system test for Java submissions.
After using a hack to workaround test #4 which always TLE in System Verdict, this submission https://codeforces.net/contest/1867/submission/223000398 is Accepted with runtime 1949 msec on test #6 where the input array has length 100000 and MEX 100000. It is unclear exactly how many IO interactions in test #6 as it depends on how greedily the Judge choose y each time.
Overall, the interactive IOs delays of problem C is too much for the given limit of T and timeout, and the problem is partially to do with the System Test. Problem C should either use a smaller limit like 10000 for T or a bigger timeout so to accept legit Java solutions without losing any generality of the problem.
I think a lot of people got stuck on E since n odd and k even has no solution, until they realize that n and k are both even, and the problem becomes completely trivial. Not a great problem imo.
same I almost wasted 30 minutes about thinking it and then I reread the question did it in 5 minutes and then went for e2 made the logic but guess what forgot to print ? in making query and didn't make it whole time I was thinking about my solution but the error was in my code :(
Completely ruined my contest. But it's my fault, I missed "Even".
what???i completely didn't realize n and k are both even even at this time!!! sad about this...
I don't know the completely trivial solution :(
Can you explain it?
The problem E2 is such a good joke.
How to progress from solution for E1 to E2?
Instead of querying all [i-k+1, i] for the remaining n%k, you can just query half of it first then the remaining half using only 51 queries.
Why problem C is unsolvable in java , even java legends like SecondThread and profchi used c++ for this problem.
if it's div2 E , F , then it can be beared but atleast div2 problem A B C should be solvable in java. I got 4 unnecessary penalties.
maybe you should learn from SecondThread and profchi :)
even they submitted in c++ after getting tle in java
Never gonna attempt a contest with interactive problems again.
Problem E is kinda easy, right?
Yes.
queueforces and I hate interactive problems
A: Arrange b[i] by the reverse order of a[i] so the value of {a[i]-b[i]} will be pairwise distinct.
B: For every pair of symmetrical positions i and j, if s[i]==s[j] then we can let l[i]==l[j]==0 or 1 (make 0 or 2 occurences of '1' in t), if s[i]!=s[j] we need let l[i]!=l[j] (make 1 occurence of '1' in t). If n is odd, we can let l[(n+1)/2]==0 or 1 (make 0 or 1 occurences of '1' in t). Let the number of first kind of pair is a, and second kind of pair is b, the answer is b+2*k (0<=k<=a) if n is even, and b+k (0<=k<=2*a+1) if n is odd.
C: In the first move alice choose x=MEX(S) (the initial MEX of S), and in after moves alice always add the number removed by Bob back, then the final value will be the second MEX of initial S. This is the optimal strategy.
D: If k==1, we can only make b[i]=i. If k>=2, we build a functional grpah from b (a graph with n nodes and add edges (i-->b[i]) for 1<=i<=n), and we only need to check if the size of every cycles in this graph is k.
E2: If n%k==0 we can query for n/k segments of length k. Otherwise, observe that if we let r=n%k and make such queries: query(1), query(1+r/2), query(1+r), we can get the xor sum of segment [1, k+r]. Then we can query for floor(n/k)-1 segments of length k for the remained part.
F: I've tried for random approach but got WA on testcase 24.
problem D : if a linear chain of size > k is connected to a k length cycle then how is possible to generate a pattern to get array B?
We can just build it in parts:
Let $$$n = 5$$$, $$$k = 2$$$, $$$b = [2, 1, 2, 3, 4]$$$
Operations:
Can you see how this can be generalised?
yes got it, thank you.
Start from the beginning of the chain and set first $$$k-1$$$ elements. Continue until you reach the cycle, then set the cycle
Actually, I think quite easy to kill random approaches for F, one can just construct a tree with all possible subtrees of size k except for 1 which random will find it hard to find.
I see now that you have n and k as even integers in the interaction section. But why not mention that in the initial problem statement?
The $$$n \leq k^2 \leq 2500$$$ was weird as well. Also that has to be one of the easiest D2E ever once you notice all that.
Ackchyually, you must know that $$$n$$$ and $$$k$$$ would be even, when the problem is E1.
I saw that the numbers are even only after reading this comment. It's my own fault, and it's stupid to think about it now, but most likely I would have passed this task if I had seen it.
lol this comment deserves most likes!
Why bitwise operator in easy problems (such as A, B) again?
Where do you see bitwise operator that much. Xor in binary strings = flipping i-th digit. Problem A isn't about bitwise at all
Is it just me or problem E1 is actually easier than B and C :D
Wait really? I didn't even see, I wasted up my time trying D :/
Why is the C problem so TLE-constrained for python……
For Java as well
I use python and got TLE on problem B testcase 11, problem C testcase 4 with default input() method during the contest. But after adding
They all passed the test.
A really frustrated experience for me though.
The game ends when Bob cannot make a move or after 2⋅n+1 moves
so why did i need to take another input after completing the 2*n+1 moves which resulted in me getting 4 runtime errorsYeah, that was very confusing
I don't think there was any ambiguity in the problem statement. The interaction guide says that after you output $$$x$$$, you should read an integer $$$y$$$. It never says that you should read $$$y$$$ only if the game is not already over or that you should read $$$y$$$ only if Bob is making a move: every time you output an $$$x$$$, you need to read a $$$y$$$.
It's particularly easy to get tripped up on interactive problems by making incorrect assumptions about the I/O format, which is why you should always read the interaction section of the statement carefully before beginning to implement your solution.
Whenever i encounter an interactive problem in the future this contest would remind me to read the I/O format completely before attempting it. Thnx
It was not clear enough, since it was mentioned in the problem statement that after 2n+1 moves, the last move would be of Alice's.
"To make a move, output an integer $$$x$$$ ($$$0 \le x \le 10^9$$$) — the number you want to add to the set $$$S$$$. $$$S$$$ must not contain $$$x$$$ at the time of the move. Then, read one integer $$$y$$$ ($$$−2 \le y \le 10^9$$$)."
What about this is not clear? Remember that for implementation details, you should always trust the Interaction section instead of assumptions based on the statement of the problem.
I'm not complaining, as I didn't solve the problem myself, but it kinda is the job of the testers to remove the confusing parts of the problem statement, and personally, I feel like that is something they should have pointed out so it could've been edited.
I am ecstatic about solving 1 problem in just 40 minutes this time. Huge improvement from the last contest where I spent 1+ hrs on 1 problem.
In problem C, the game is supposed to end after 2*n+1 moves right? so when I ran a loop till 2*n+1 it kept giving me Wrong Answer, when I ran a infinite loop it passed. Why is that? Can someone explain? If the game is supposed to end after 2*n+1 moves, then why should I go further and read y=-1 to end the game?
"To make a move, output an integer $$$x$$$ ($$$0 \le x \le 10^9$$$) — the number you want to add to the set $$$S$$$. $$$S$$$ must not contain $$$x$$$ at the time of the move. Then, read one integer $$$y$$$ ($$$−2 \le y \le 10^9$$$)."
Is it not clear that after every time you output $$$x$$$, you need to read in $$$y$$$?
In pdf version of problem C input and output exlpanation was missing.
Yep thanks, I get it now. Should have read the statement more carefully.
In this entire duration i somehow managed to solve A,wt shall i do, i am really getting depressed,i am soo weak, wt do i need to practice in order to be able to be good at cp .
Maybe these help:
Solve more. Whole cp is just trying to see patterns of problems already solved by you in new problems.
It's okay man, I got WA two times on pA this contest also and I almost gave up and just quit. The point is that you need to keep calm and try observing some key observations. Also if div 2 is too hard you can try div 3, 4 and atcoder. GL!
RIP Ratings,
Thanks to 1867C - Salyg1n and the MEX Game
Thought that the game in C literally ends after $$$2\cdot n + 1$$$ turns, turns out that it was needed to read the -1 from the input (couldln't solve D in time anyway, so w/e).
The first three questions are not difficult to distinguish, and the description of question B is too abstract, which is not a language that human beings can understand for me
I am sure of my approach for C but still giving WA on test 2. Never solved an interactive problem before. I’d appreciate if someone can point out my mistake
According your code, I think when Nextmove = n; it will wrong. Like this: n = 2 a[] = 0 1 Step 1: A:2 B:1 Step 2: A:1 B:0 Step 3: A:0 B:-1 -> it need n+1 loops
my aproach was fine its just that I didn't take the input for the move after 2n+1
Just tell me one thing, colors of high grades, in div2 D we just had to find out if k-1 going in a cycle like in union find will end up not visiting the same element again. Was this the answer to it? Like array 2 3 5 3 4 so going like 1 -> 2 -> 3 -> 5 -> 4 -> 3 ...
Not necessarily, you can do this to k nodes without them being in a cycle, I will explain solution.
If k==1, and there's an element not in a cycle then the answer is no, because any element that is connected to itself can be made into an array on its own, but if an element is connected to something else, you can't make an array of size 2 , so no. If k>1, and there's a cycle with size not equal to k, then answer is no, that's because in a cycle of size !=k after k steps from a node you will either repeat a node, or not get to the node you want. Now if all cycles are k then answer is yes because you can do elements that are not in a cycle with the node after k steps
I just checked that every path from a non-zero element leads into a cycle of length $$$k$$$.
Lets take the sample test case. n.= 5, k = 3 2 3 5 3 4
What cycle are you forming of length k can you mark?
Well it's a functional graph where each node $$$i$$$ has an outward edge to $$$b_i$$$. So there is a cycle $$$3,5,4$$$. and if you start at any other node and keep following the outward edges, you will end up at that cycle, which has length $$$k=3$$$.
Oh, and if $$$k=1$$$, then each non-zero must point to itself.
Great round, thanks a lot for making the interactive problem not the hardest one, this is the first time I was able to solve one and it made my day!
Nice problems, I only wonder why couldn't you write simple and clear limitations in E, for me they were confusing and unclear tbh.
E1 was so easy but i did x-- instead of x++ in a while loop and couldn't debug in 20 minutes.So disappointed .
Can't see any passing Java solution for Problem C at all. Did anyone else checked?
UnfairForces
Found one.
222934542
salyg1n Watch out for the TLE Java submissions of Problem C. Those submissions are very insightful and can easily tell that the problem wasn't properly tested for a language other than C++.
I even tried using fast I/O in Java.
Do something about that, as the same logic is getting passed in C++.
System.out.println() is every slow so I used c++ for this task. If it was not interactive we can use fast output
Thank you for the awesome contest <3
from now whenever i will see Interactive tasks in blog... i will go to bed :(
Best round ever!!! Thanks a lot!!! Why am i so stupid, that i didn't saw, that in E we have only even $$$n, k$$$... Waste like an hour with odd numbers, but solved for even in 20 minutes... Could have solved D...
Btw, i think you should have written in the statement, that $$$n, k$$$ are even not ONLY in input format... Or at least make a notification about it...
I pass the C problem with great difficulty!!!Why python can't pass the C problem????
Interactive Forces :)
Screencast with commentary
I'm in. I'm too green.
I don't know how many dislikes this will get but, is it normal if you start problem D when 1 hour 10 minutes is left and still not able to fully come up with a solution which has a logical background. Even if after 10 minutes my intuition said something to do with graph cycles, I was not able to come up with a logical solution to base my intuition. Does it happen to everyone and how you fix it? Doing more problems doesn't logically seems correct for solving problem D or is it? :')
I accidentally understood the proof of solution by YocyCraft while answering one of the comments, but I couldn't solve it myself. I guess practise makes perfect. At least you got the idea to use functional graphs
Knowing properties of successor (functional) graphs may help, more specifically that in each component of a successor graph there is one and only one cycle (I completely forgot about that one during the contest).
I loved problem D but I couldn't even think that it's graph and cycles xD, please anyone suggest to me good problems similar to this D.
It only takes a few simulations of the operation on the sketchpad to discover the cyclic.
can anyone tell approaches of problem 2 xor palindrome
Hints:
Consider the indices $$$i=1,2,\dots,\big\lfloor\frac{N}{2}\big\rfloor$$$.
If $$$s_i=s_{n+1-i}$$$, then we must use either $$$0$$$ or $$$2$$$ ones at these indices.
If $$$s_i\ne s_{n+1-i}$$$, then we must use exactly $$$1$$$ one to flip one of these two bits.
Furthermore, if $$$N$$$ is odd, then we can flip the bit in the middle if we want to.
Let $$$A$$$ be the number of indices $$$i=1,2,\dots,\big\lfloor\frac{N}{2}\big\rfloor$$$ such that $$$s_i=s_{n+1-i}$$$
Let $$$B$$$ be the number of indices $$$i=1,2,\dots,\big\lfloor\frac{N}{2}\big\rfloor$$$ such that $$$s_i\ne s_{n+1-i}$$$
Then the only possible number of bits we can use is $$$2a+B+c$$$ for $$$a\in\{0,1,\dots A\}$$$, and $$$c\in\{0,N\%2\}$$$.
Can someone pls tell why my C failed on system testing?
why this code by java get TLE ? 222937329 but this code by c++ get AC 222942899
They are exactly the same code
MikeMirzayanov
Because C++ > Java
Not fair every code pass with c++ should pass by java
Where do rules say so?
If it's fair Why Codeforces allow to use different languages One get ac because he know c++ And another one get tle because he write java?? The competition is for those who can solve the problems using any language allowed by the site
Well it's known that python is ~100 times slower than C++ and Java, yet it's allowed to use in competition. However a lot of problems can't be solved on python. Same with Java. I guess C++ is the best language for olympiad programming, that's why people use it and problems are made for C++ and MAYBE you can pass using other languages, but no one guarantees you that
P. S. I don't know for sure, but maybe there are IO optimisations in Java which can make your solution pass
Unfortunately that's not true.
Our target is to get an accepted code within the given time and memory limit. It doesn't matter which language we use. If we use a slower language it is not their fault.
The time limit and constraints are decided by the problem setter. In some problems, the setter wanted to allow some complexity and not allow slightly greater one. In these cases, they won't care about different/slower languages.
Find a language faster than C++, it will become mainstream and they'll stop worrying about C++ time limits.
UnfairForces
bashkort ace5
Accepted solution using Java
Problem C has either too big T or too tight time limit. For example, it could have a limit of T like 10000 instead of 100000. As a result, the problem would be more effective to accept Java solution with the right idea and algorithm. The way it is requires low level IO hacks to squeeze the last IO efficiency to possibly and barely meet the time limit, and as a result the IO code is messy and has poor readability etc, which is NOT the purpose no should be the focus of the problem.
Exactly, the authors should make t equal to 1e4
The problem C said,
The game ends when Bob cannot make a move or after 2*n+1 moves (in which case Alice's move will be the last one).
This code got the wrong answer during the contest as I wrote code according to the 2*n+1 move.
And after the contest, this one gets ac as I write code according to 2*n+2 move. Why does this happen?
IMHO:
2*n+1 is Alice's last move, after this Bob replies with -1 (which goes to your "n" in the outer loop).
2*n+2 reads "-1" and moves to the next test case.
E2 can be done in maximum of 51 queries ,right? Why is the constraint 57 then?
Because author studies in 57th school
The constraint does not have to be at the tight lower bound. 51 might serve as a big hint; author might have other legit ideas to solve the problem etc.
did you find that there're a lot of 57 in the problem set?
My O(n) code for B got rejected in PyPy but got accepted in python, same exact code . Look into my submissions: https://codeforces.net/submissions/jagan028
It seems PyPy struggles more with IO: 223000606
alwayss use FAST I/O with python , add this to your code and it will get AC :
import sys
input = lambda: sys.stdin.buffer.readline().decode().rstrip()
t = int(input()) .........
Your code currently spend most time reading in data. What you need is a faster input:
import sys
input = sys.stdin.readline
This is a must for all python/pypy coders, otherwise you will TLE a lot. Just copy the faster input into your template.
Back to back IND vs pak match and back to back contests
Worst Cf round ever encountered. No announcements made during the ongoing contest to clarify various confusions in the statement.
Feels like C was forcefully made an interactive problem.
bruh
Congrats on reaching cyan!
is it just me or E1 and E2 are very easy??
Dammn Bro, A Big Yes, in fact after solving E1, E2 was kinda obvious. I should have attempted these questions 1st before D :(
constructive algorithms x7
Just upsolved E1 and E2, they both seem much much easier than the normal E of Div2, Anyone else who thinks the same?
Yeah it was very easy to observe and implement.I wasted all my time trying to solve D.It took me just 15 minutes to solve E after contest without any hint.Regret XD
MikeMirzayanov salyg1n geranazavr555
I registered to this contest when I was 2100+, so I was labeled as out of competition. The rating is not updated for me. Can you fix this?
Maybe problem E2 is a bit easier than D?
Maybe you're right :)
i'm wondering why my solution to div2 d cannot pass the pretest#2 on the 568th input.
my solution:
add edges: from i to b[i]
check if every i is in a loop case: i is in a loop if the length of the loop is not k, "no" case: i is not in a loop
update: i know.
Can someone explain how can't a be converted to b in examples test case 2 of b=[2,4,3,1] ,,,, using a=[3] and then a=[1,2,4] ? fk this shit.
Array a should be of length k only.
.
Video Editorial for A — E2 I hope it will Helpful for Newbies and Pupils ... LINK TO YOUTUBE
green_gold_dog ace5 bashkort salyg1n
screw this contest!! who the hell wrote the C problem ?!! the game ends after 2*n+1 MOVES so why do I have to take the input after n+1 moves for ALICE ???!!!! i hope the author starts learning simple ENGLISH !! ruined the whole contest for me !
pls read "interaction protocol" again: "To make a move, output an integer x — the number you want to add to the set. Then, read one integer y"
wheres the editorial?
So, no editorial for this contest?
When will editorial be out?
RIP editorials
Can anybody give some hints for F?
I feel that the order of E needs to be swapped with D, both in terms of the difficulty of thinking about it and the difficulty of implementing it in code. I just started writing E after the contest, and realized that the difficulty of thinking about E is really not too high.
You can find this gap in the two codes I submitted: E2 D
In problems C, I try to use the scan rather than cin to get the output of Bob. But I get the Idleness limit exceeded :) Can someone tell me why can't use scan?
it's not about the input, you have to do output correctly (fflush(stdout) for printf or cout << std::flush/cout << std::endl for cout)
Interesting problems! I love it!!!
div2D. how to prove that if there is a cycle of length x!=k, then the answer is NO? thanks in advance
ps: actually, that's not the main question. i just can't find mistake in my thoughts: it's obviously that we must have at least one cycle of length k. also, for every V that is not in cycle, we can place it to the right place using vertices that lie in cycle of length k. now consider vertices that are in cycle of length x!=k. for such vertices we can cut cycle by some edge and add some fake vertices and edges (that will fill the space for vertices that are in cycle of length k, because the last move is operation with cycle of length k and we don't care about such 'fake' numbers) so that our new cycle has length k or 2*k. thus the necessary and sufficient is just to have at least one cycle of length k. where am i wrong?
pps: nvm got it thanks <3
Whenever you do a single "move", you write a cycle of length k into the array. Later, you can overwrite parts of that cycle with another cycle of length k. However, that doesn't allow you to create a cycle of length!=k, because if you overwrite any part of the old cycle then the old cycle is simply broken, it can't become a cycle of different length.
oooooohhhh
E2 can be actually done in 51(49+2) operations instead of 57.
If n=2500 and k=50, then it takes n/k=50 operations.
Otherwise, my submission E2 handles something like n=2498 and k=50 in 51=49+2 operations.
BTW, you should maybe modify your comment. I read this as
51*(49+2)
operations.I meant 51 expressed as 49+2 and not 51*(49+2). Sorry, for the confusion.
Why so few div2 contests this month? I can see only 2 div2 on calender for this month.
Nice problems imo!
I liked that they had cute solutions with short implementations, and the proof difficulty is very appropriate.
I want to clarify that my solution matched with some one according to system but I don't think except the template anything has matched. Your solution 222949914 for the problem 1867C significantly coincides with solutions subodh.r/222945531, Mr.Roamer/222949914. This are the 2 solutions. And the template we both used is available here https://youtu.be/8ymiMHQPgZY Pls review the solutions if possible. I apologise for the delay in doing this comment.__