Hello Codeforces!
$$$\newline$$$
It's been a while, today AkiLotus and I are delighted to invite you to participate in Codeforces Round 983 (Div. 2). This round will be rated for all participants with a rating lower than 2100.
Our round will start on Nov/01/2024 17:35 (Moscow time). You will be given 6 problems and 120 minutes to solve them.
This contest is a collaboration between AkiLotus, his friends and Code Mely, a Vietnamese community and an individual passionate about Computer Science. Reach out to us here.
Special thanks to:
- MikeMirzayanov for interesting Codeforces and Polygon platform.
- Artyom123 for coordinating the round.
- Teja-Smart, Xylenox for preparing sauce for chicken nuggets.
- Our talented authors: MofK, Kuroni, AkiLotus, thanhchauns2
- Our testers: cdkrot, unalive, neko_nyaaaaaaaaaaaaaaaaa, Ste, Pirate_King, Kude, tablemoon, blitztage, Dominater069, Hyperbolic, stefdasca,xuanquang1999, Railgun, towrist, mwen, FairyWinx, tibinyte, dorijanlendvaj, kokokuro, nor, SPyofgame.
- Our testers and preparation team from Code Mely: me, bibimoni, Yugi.Hacker, mp1309, nguyenphong233, CoolManGame, Tran_Thi_Thanh_Van, fanwen, DOCUTEE
- KFC for their chicken nuggets again.
- You for participating.
$$$\newline$$$
Score distribution: $$$500 - 750 - 1250 - 1750 - 2250 - 3000$$$
Happy coding! Our chicken nuggets and Fubao bless you.
UPD1: Editorial is published.
UPD2: Congratulations to the winners!
Div. 1 + Div. 2:
Div. 2 (official):
- Vincella
- SUPERLWR-beta
- BlackLily
- leolin0214
- TAIYANGFENG
- xiaowangba
- piasticOuO
- Nikephoros2Phocas
- SkyWave2024
- zsj6315
First solves:
- A: Vincella (00:01:19)
- B: Vincella (00:05:48)
- C: intij_tk (00:04:36)
- D: penguin133 (Div.1, 00:11:27), Tonni_and_Huy (official, 00:20:33)
- E: awesomeguy856 (Div.1, 00:20:09), kaiboy (official, 00:37:08)
- F: peti1234 (Div.1, 00:19:54), rainboy (official, 00:36:03)
As an author, good luck.
As a tester, good luck!
qp
bd
dp
greedy
Oops! I'll be at ICPC2024 Nanjing Ragional when the contest is scheduled. Hope I will be able to achieve Cu for my first ICPC contest, and good luck to everyone participating codeforces or ICPC~
all the best bro, mine online round is on 11 nov hope my team will qualify for the offline regionals round
wish you good luck~
As a taster, i tasted and the problems were indeed quite tasty
As a tester, good luck
As a tester, I hope you all enjoy this round and perform well to achieve the rank you truly deserve.
As a tester, don't eat KFC before the contest if you can't tolerate spicy food.
As a sauce preparer, I can confirm that the nuggets are very tasty!
Yes, they looked tasty I haven’t tasted tho.
Can we take it as a hint that there will be a problem that could be solved with chicken nugget theorem.
As a contestant, practice 1526B - I Hate 1111
As a tester, good luck :)
As an author, I'm honored to bring you the score distribution for this round. Good luck.
That announce was made 8days ago mean 10day before contest. Seems like they are prepared...(Excited)
Yessss
you forgot to thank Mike Mirzayanov.
OMG Vietnamese round
While saving Cats and Dogs, We kept celebrating with Chickens Pigs and Goats. Hypocrite Humans.
Good KFC.
omg kuroni round
omg kuroni round
Damn.. did you guyz really forgot to thank our lord and saviour MikeMirzayanov...
Damn, I'll alert him.
looking forward the result.
bro you ain't a tester, who are you trying to fool.
As a contestant, how can I become a tester $$$??$$$
same question here.
usually testers are authors' friends
be a tester and contestant at the same time
Mary skelter fan spotted omg
how bro feels saying 'brethren' and 'admirable'
Special thanks to KFC was what really hit me <3
Is KFC preparing a round?
Guys, my exam is starting in a month (I gave a practical exam today).
I have all of my syllabus to read.
Should I do this contest?
Cf contest >>>>>> School
My last exam finished today and I guess you studed more then me
hope full solve
I think the team loves chicken nuggets more than their code :D
Pray that i solve atleast 1 problem(s) this time :')
Yo, this guy's my senior at the college and he freakin' wants to be unrated!
time to celebrate and rank up
If we write down all the red letters we get the word : Kangokutou Which is a term that is often used in Japanese literature and media to refer to isolated islands designated for imprisoning criminals, similar to the concept of Alcatraz Island in the United States. It may also appear in fictional works to evoke themes of isolation, confinement, and punishment SOS?
OMG This looks like a Halloween edition !!!!! :)
As a tester, I'm curious about AkiLotus's profile character
As a anime fan, I'm also curious..
If this character is from an anime please tell me the name of the anime.
I hope I can officially announce her soon in a future round. ;)
as a 20yrs fan, kuroni orz
As a compiler, I cant complain.
wish this contest will be interesting
I am writing to request that MikeMirzayanov postpone the contest, as it is Diwali in many regions of India today.
unfortunately the world doesn't revolve around India
I am from India. And I am embarrassed seeing these kind of immature comments from people from India.
Haa kattue tujhe kya fark padega
I am Hindu. And I am embarrassed seeing these kind of immature comments from people from our Religion.
Btw, Belated Happy Diwali to you toooo !!!
Happy Diwali, but what was so embarrassing when someone ask to postpone the contest?, this year during eid one guy asked to postpone the contest, and it was indeed postponed, but when I asked, I get hate from my own people.
who cares
return specialist?
good luck
Good luck everybody!
Goodluck for everyone
excited
(D) is Mucho Texto
B had so many edge cases but atleast i solved it
Really ? 289203244
wow sick, for me it's a little bit more 289255586
quite the same TBH
i meant i didnt think about odd even got 3 WA there lol i also solved similarly though
I see
So close yet so far, i actually couldn't debug it :/ 28928125
You kind of over-complicated it.
Reason why i am still a newbie :'/
well you should practice more problems ,and that too consistently, if you actually care about ratings.
Yes, at least i don't wanna end this as a newbie
don't debug for simple code/problem, hack yourself and you will grow
hack myself what-
take a 1 min break then try to find a counter example to break your own code.
I do this every time I got WA in live contest.
Ohhh- Well actually I came up with the logic in like around last 10 minutes & sadly couldn't find a counter example even after trying a number of tests :/ will have to sleep over this one ig
Samples in C are useless
It's a trend ig, it's always been like this.
time to touch grass
Ofcourse it is on us to read statement carefully, but it would have been so nice if the fact that we are given an identity permutation was clearly stated in Problem B. No way a problem with such a trivial solution has taken so much time for so many people to AC.
how did you solve it?
my solution I think its simple ~~~~~
~~~~~
since given array is identity permutation we can simply split the array into three parts $$$[1,..,k-1], [k], [k+1,...,n]$$$. Since everything in first subarray is smaller than $$$k$$$, its median is also smaler than $$$k$$$. Similarly median of the third subarray is greater than $$$k$$$. Now, for median of medians part we have only three numbers with one each on either side of $$$k$$$.
Only edge case is that size of subarrays should be odd.
$$$[k]$$$ is already odd.
If $$$[1,...,k-1]$$$ is of even length then $$$[k+2,...,n]$$$ must also have even length (otherwise $$$even +1 + odd = even \neq parity(n)$$$. So just split them further into $$$[1]$$$ and $$$[2,...,k-1]$$$. Similarly split $$$[k+1,...,n]$$$ into $$$[k+1]$$$ and $$$[k+2,...,n]$$$ if need be.
So you either split into $$$3$$$ subarrays or $$$5$$$ subarrays always. In both cases we have equal number of medians less than $$$k$$$ and greater than $$$k$$$, so overall median is still $$$k$$$.
D is solvable with $$$n-3$$$ queries. We have to find the array $$$p$$$. After the first positive value $$$p$$$ is strictly increasing.
Iterating from $$$n-2$$$ to $$$1$$$ we can find $$$p_{n-1}$$$.
$$$p_{n-1}=i$$$ if the $$$(n-1, i)$$$ path doesn't cross $$$0$$$ for the first time.
After that we can do the same for $$$p_{n-2}$$$ iterating from $$$p_{n-1}-1$$$. And so on. Using the observation that node $$$1$$$ has exactly $$$2$$$ adjacent nodes we can save one more query.
Here is my solution: 289236088
did you know that function res() does not return?
Is E really just a knowledge check on how to solve a system of equations for the specific matrix? Or is there an easy solution?
just get the relation between v[i] and v[i+2] for all i and make them all non-negative by adding minimum value. then check whether it's valid
WAforces, I'm feeling -3 intel for making 4WAs in B and 1 WA in C
real. it's so stressful when you keep getting WAs lol
ABC was SpeedForces for me, but D was a great problem... too bad I couldn't solve it lol
WTF man why is my solution for C wrong?
hope this helps 289278230
What is your solution?
Step_1: sort array a
Step_2: binary search a[i] + a[i+1] in a. Called the result j for example (it infers the array a[i] a[i+1]... a[j] fits the problem requirement, every triplet will fit x+y>z etc.)
UPD: seriously my code is simpler, just read it. It's 4-5 liner code only...
Yes I got it thanks
could u tell why this approach fails? cant check the failing testcase
try this:
2 and 2 is the output
which i believe is correct?
correct, nvm
i figured out that my code fails if there is a x + y <= z pattern in middle of array where i or j dont reach
1 1 1 3 4 5 9 10 11 22 30
i stops at 11 and j stops at 3 so res is 8 but correct res is 7 considering the correct seq to be 5 9 10 11 and changing the rest of the values
Problem D gives correct answer on my compiler, but wrong answer on CF
...
Was there an easy solution for C? I tried to memoize with both start and end index of sorted lengths and got TLE
Yes, Try to check for every position in a sorted array, If this was the minimum, how much are valid ?, it can be done in O(N*Log2(N))
Damn for C I boiled down to that all numbers revolve around median of the sorted array, so any number i.e. greater than median + 2 and any number smaller than median — 1 would be modified. Something like this, was not able to get it right for the sample test cases and time got over. Might be I was overthinking.
My approach:
It is sufficient to ensure that
a1 + a2 > mx
, wherea1
anda2
are the two smallest elements of the array, andmx
is the largest.We can change the maximum element of the array. So, sort the array and iterate from the end. Let's stay
mx1 = largest element
,mx2 = second largest
and so on...For each
mxi
, we find the number of operations required such thata1 + a2 > mxi
. To do that, we find the first pairai
andai+1
such thatai + ai+1 > mx
, and number of operations is simplyi - 1
, as we must change all elements smaller thanai
.The answer is
min(op1, op2, ...)
, whereopi
= minimum number of operations formxi
Implementation
But I saw n was in range 2*(1e5), I thought a N^2 algorithm would result in TLE, Im saying O(N^2) since you're checking
for each
It can be done in Nlog(N). Check the implementation above. You can store
v[i] + v[i+1]
in an array, then to find the first pair withai + ai+1 > mx
, just find the upperbound ofmx
in this array.gotcha!
I think maybe I can't go to sleep tonight.
I practice very hard for two months, and I finally make it.
congrats
becoming master?
It seems I get rank 5 and become Master.
then congrats MASTER :)
Inspiring!
Congrats!
Congrats MASTER!
damn man big W
in B i thought there's actually an array given in the input :(
How to solve E? Also Is it possible to construct the answer(operations) array from the final element (if we know the element which will be equal after the operations are done)?
It should be something around difference array.
Try some special operations. If you apply an operation on every even position, only $$$a_1,a_n$$$ will decrease $$$1$$$.
Now lets first decrease $$$a_i,a_{i+1}$$$ by $$$1$$$. Apply an operation on $$$i+1$$$, then only $$$a_{i+1},a_{i+2}$$$ will increase $$$1$$$.
Do it from $$$1 \to n - 2$$$ and clear $$$a_i$$$ using $$$a_{i+1}$$$. Finally, there is only one non-zero number in the array.
What these operations can do is change any 2 elements by either of [+1, +1], [-1, -1], [+1. -1], [-1, +1] these operations. From these it will always be possible to make all the elements equal since n is odd. Is this correct? Can you explain Hint 3, I didn't get it.
Sorry for the late reply (I went to sleep after posting the commnt :()
Actually you only need the operation [+1,+1] or [-1,-1]. Let's define $$$inc(i,x) $$$ means that let $$$i,i+1$$$ both increase $$$x$$$ and $$$dec(i,x)$$$ for the same.
Consider element $$$i $$$ and $$$i +1$$$,
If $$$a_i < a_{i +1}$$$, do $$$dec (i,a_i)$$$ so that $$$a_i = 0$$$.
Otherwise, do $$$inc(i+1, a_i)$$$ and now $$$a_i < a_{i +1}$$$.
Keep doing it until there are only two non-zero number in the array and decrease them By there min so only one of them left.
Now we have $$$n-1$$$ zeros and using $$$inc(i,\text{left_number})$$$ to make them equal.
Oh that's really cool. Thanks.
The answer to your second question is yes. It is easy to construct the array of operations given the final state, since we just need to solve the linear system
where $$$x_i$$$ is the number of times you applied the operation with index $$$i$$$, $$$a$$$ is the input and $$$s$$$ is a vector with the final state (in the problem all the entries of $$$s$$$ are the same however this method applies for every $$$s$$$). It is trivial to see that the $$$k$$$-th row of $$$M^{-1}$$$ is a cyclic shift by k of the upper row of $$$M^{-1}$$$, so you can solve this system easily with convolution/fft.
However, for the problem itself there are way simpler solutions.
Can you explain a little detailed how to use FFT to solve such equations?
Sure, for vector $$$v$$$, denote by $$$w_{v,i}$$$ the vector $$$v$$$ cyclically shifted by integer $$$i$$$.
We know that
To solve the system, just multiply $$$M^{-1}$$$ by $$$u=s-a$$$. Of course, you can't do this naively because it would be $$$\mathcal{O}(N^{2})$$$. However, notice that on the vector
every single entry is the dot product of a certain cyclic shift of $$$v$$$ and $$$u$$$. If you consider a vector $$$r=\begin{bmatrix} v,v\end{bmatrix}$$$ then $$$(\star)$$$ is just some of the entries of the convolution of $$$r$$$ and $$$u$$$.
Could we use this to solve? It got me WA
The link you gave is for tridiagonal matrices, $$$M$$$ is not tridiagonal because of the "corner entries" $$$M_{0,n-1}$$$ and $$$M_{0,n-1}$$$.
Take a look at the Variants section, there is a solution for the matrix which is the same as in this problem.
Yes, you can solve with it, but you'll need to store the intermediate results as fractions instead of doing double division and then do a little bit of reconstruction on top of that to get the integer answer.
Then yes, you can solve it with that. I used fft because I am more used to it, but I would expect that there is a linear solution like the one described there.
It got me WA on test 6 however, though I copy pasted the whole function from wiki. It's hard to deal with precision here. Maybe FFT is more reliable in this situation.
Thanks for sharing. Will go through these concepts to get better at it.
ACs on problem D rose drastically at the end._.
Can u tell me how to improve speed solving greedy problems? That's only stopping me from Expert
Write out some cases and see the pattern. That's quite a good strategy actually.
damn i am not skilled at greedy problems at all...
Greedy is hard. Especially the proof part.
Is there anyone who also used a[N] instead of a[2N] on Problem A to declare the array? Just wasted almost 0.5h on it and the unstable mindset finally results in the thorough collapse:(
How many you solved finally?
only ABC, and the "pretests accepted" solution of C is even submitted on the very last time of the round (only 10+ minutes left). I think at least I could solve 3~4 problems much quicker without this annoying bug:( But it's totally my own fault I have to admit, and nothing to accuse about the authors and the statements.
misread the question thought a[i] = a[j] only allowed if i <= j. Thought about the problem like this for half an hour. What a waste :(
I make other mistake of overthinking the problem. Also cost 0.5h
After all the fog clears, it's just res_min = cnt1&1, res_max = min(cnt0, cnt1)
lol I've discovered the fun fact that it's exactly how CF Div.2 AB features. The solution is as easy as you could hardly believe, but if you fell into the trap of overthinking then it would just be rather complex or even impossible to solve
Might someday we will brave enough to rainboy the contest (doing problem in E-D-C-B-A order)
Very true. It's very hard to remain calm and "think simple" during contests. I always overcomplicate under pressure
My E solution
Consider the difference array.
Let $$$d[i] = a[i] - a[(i-1) \mod n]$$$ (0-indexed).
We can see that the sum of $$$d[i]$$$ does not change. Thus, if the sum of $$$d[i]$$$ is not zero, there is no solution. Otherwise, we can always construct a solution.
Our target is to make $$$d[i] = 0$$$ for all $$$0 \leq i < n$$$.
An operation for $$$i$$$ (denoted as $$$\text{op}(i)$$$) is equivalent to: $$$d[i-1]++, d[i]++, d[i+1]--, d[i+2]--$$$ (mod $$$n$$$).
Merging operations:
Since $$$n$$$ is ODD, $$$\text{op}(i) + \text{op}(i+2) + \ldots + \text{op}(i-1)$$$ results in $$$d[i-1]++, d[i+1]--$$$.
Next, make $$$d[i-1]++, d[i+1]--$$$, then perform $$$d[i+1]++, d[i+3]--$$$, etc. to achieve $$$d[i]--, d[i-1]++$$$.
The implementation is painful. Can't finishit in the contest ;)
Sum of $$$d_i$$$ is always $$$0$$$, so there always exists a solution for an input.
it took me much time to arrive at this solution but the implementation is very simple 289836310
What is the problem with me??? Every contest its one thing or the other.
Sometimes I am able to find out the solution of a problem but unable to implement it quickly. I figured out some solution for D. But I was unable to implement it properly in 40 mins. I was juggling between different approaches. How do I calm my mind and implement the solution first properly? Is it just the lack of practice and nervousness that gets to me or is there something wrong with my time management?
It's lack of confidence if you lose your focus on your own algorithm without a clear WA/TLE verdict.
Practice daily to gain confidence. Confidence isn't grow by words mate.
I had the same problem as you, and there is no trick. Just compete in more contests. Today i had solution for D in like 5 mins, but had no idea how to implement it, but i didnt panic and figured it out quite quickly after writing down some simple code. It all comes with experience, you cant speed it up.
I am unable to put my mind to focus..Its just that it keeps wandering here and there.
I am really demotivated right now because it is happening repeatedly with me now. I find some solution during contest, it doesn't work. Just after the contest (when my brain knows the contest is over, there's no time limit) I submit it and get an AC within 10 mins. But in the last 30 mins of the contest ending, I am just unable to even debug my code properly.
почему гениальные идеи приходят когда я сру
In problem D can any other node except root have degree more than 2?
no
Why?
cuz everything else is path thus they need to be a straight line, thus a degree of at max 2 for every node except 0.
1. Each node that was initially adjacent to the node 0 will be the end of some path.
2. A path is a tree whose vertices can be listed in the order v1,v2,…,vk such that the edges are (vi,vi+1) (1≤i<k ).
If we remove root node 0 and all adjacent edges, this tree will turn into a forest consisting of only paths.
think this through — can you figure out now?
Thx got it now.
missed problem D cause i swaped 2 variables in my code bruh
Thank you guys and
Code Mely
for the amazing contest!Please anyone can explain me 3rd question
E has a cute trick. Write W[i] = V[i] + V[i+1]. https://codeforces.me/contest/2032/submission/289289897
So now we have an operation $$$[+1, +3, +3, +1]$$$, how is it easier?
A[i+1] + W[i] + W[i+1] = T differences, W[i+2] = W[i] + A[i+1] — A[i+2]. Say W[0] = w. Use above eqn to fill out W. Each W[i] = aw+b will have a=1. Sum all rows to find the real W[0] ("extra = ..." in the code)
Now from W solve for V, its easier to solve the n equations W[i] = V[i] + V[i+1]
The problems were mostly good ,the issue with D is it just gives away the solution because there are so many limitations(conditions) so you just implement it, and the difference between D and E is too huge.
Special thanks to everyone for They breathe oxygen. and seriously for you.
it 's unrated.
Why is the result for this test case for problem C 1 and not 2?
1 1 1 2
Even if we replace the middle 1 with 2, then we get 1 2 1 2, and the triple1 2 1
is degenerate.we can change 2 to 1. i.e [1,1,1,2] -> [1,1,1,1]
replacing 2 with 1 is optimal —
1 1 1 1
what is wrong with this solution for C? :
always check the two smallest numbers and if thier sum <= biggest number then replace the samllest with the biggest
you can also replace the biggest with the smallest
Consider 1 7 1 1 1 1 1 1 10. Your code replaces all thr ones with 10, but you can also replace the 10 with 1
consider the case
1, 1, 1, 1, 10.
Is it better to replace the first 3 ones with a 10? or the last 10 with a one?
Auto comment: topic has been updated by AkiLotus (previous revision, new revision, compare).
For E, one can add $$$1$$$ to $$$a_i$$$ and $$$a_{i+1}$$$ equivalently by applying $$$\frac{n+1}{2}$$$ operations on $$$i+1,i+3,\dots,i-2,i$$$, and what remains is simple.
P.S. cf logout my account automatically before the contest start, so I thought I hadn't registered. MISS THE CHANCE TO BECOME MASTER AGAIN!!
It was possible to late register
How to stop being stupid?
finally got expert :)
wow, amazing :0 I hope I will reach green tomorrow.
Can anyone teach me problem E?
Can someone explain this. At problem C there is this part in test case 3 test line 13 and its like this : 4 1 1 2 3 The correct answer by the judge is 2 but if we remove 2 than that would mean no triplet. Can someone see to this or am I tripping. (the error : wrong answer 13th numbers differ — expected: '2', found: '1')
you need to replace, not remove. So after replace 1 1 to 3 3, we will get 4 3 3 2 3 which is the most optimal operation that satisfy the condition.
Makes sense. I forgot that when I was making the solution on the paper I thought of it for one moment as removing since it would make it simpler and got carried out on it.
top1codeforces is clearly using GPT. Why is he still getting first solves credits on A?
Interesting. I actually didn't diagnose every code (relying on the submission order to credit), and I also didn't know how to distinguish LLM-generated code from regular ones. Would love some enlightenment, and if feeling solid enough, I could change it accordingly.
(Might take a day or two however, it's midnight in my place right now)
He got banned after solving A-F in today's div3 in 6 mins 💀
Updated :skull:
Mistook the operation ai += aj in C and got WA forever...
I really enjoyed problem D, the first interactive problem I have ever solved during a contest
why exactly does this approach fail for C ? cant really see the testcase
Thank you very much for the contest.
My hack on problem F got
Unexpected verdict
, AkiLotus can you fix it please?Apparently a tester solution also failed your hack. I'm trying to work on it, thank you for pointing out.
The fix is done. I don't know if the hack could be redone though (I never saw such happen before), but I believe you could hack that solution again.
Thank you so much! I've rehacked it and it works :)