Привет, Codeforces!
13 октября 2019 года в 12:05 MSK состоится Codeforces Round #592 (Div. 2). Обратите внимание на необычное время начала раунда!
Раунд будет рейтинговым для участников второго дивизиона (с рейтингом менее 2100). Условия будут доступны как на русском, так и на английском языках.
Этот раунд проводится по задачам регионального этапа Всероссийской командной олимпиады школьников по программированию 2019, проходящего в Саратове. Задачи вместе со мной придумывали и готовили Иван BledDest Андросов и Владимир vovuh Петров.
Хотелось бы сказать большое спасибо Ивану isaf27 Сафонову за помощь в подготовке задач, Михаилу MikeMirzayanov Мирзаянову за замечательные системы Codeforces и Polygon, а также Ивану CaseRuten Худошину, Ивану Ivan19981305 Георгиеву, Леониду Peinot Миронову, Антону anon20016 Лебедеву, Ксении Pavlova Павловой и Дмитрию dmitrii.krasnihin Краснихину за прорешивание задач.
Участникам будет предложено семь задач и два часа на их решение. Разбалловка будет объявлена позднее.
UPD Разбалловка 500-1000-1500-1750-2500-2500-3000
UPD Разбор задач
I wish the round be nice without any DDOS attack, in queue or without any delaying, best of lucks.
Thank you. Today there is no Queueforces, no DDOS attack, all statements are clear and also problems are good.
The only thing bad is your rank :P
()
too koonet
:|
Is it rated?
I really hope no DDOS attack again again!
A friendly time to Chinese.
Hope this round will no DDOS.
Yep,but for me it is a right time to have supper,so maybe I'll be hungry solving the problems.
Even I'm Chinese, I still want the round to be later. The darkness has given me dark eyes, but I use them to find bugs.
China is a good country...
I think so.
Sounds interesting, but maybe you can change it into darkness...XD
Thanks. It's my fault.
I agree
Thanks to the time,I can participate for an official contest after a long period of time.
Thanks to the contest writers.
Contest with unusual time, keeps the hackers from the crime <3. Hope a great contest for everyone!!
Short problem statements, please!
Желаю удачи и провести раунд без DDOS атак)
I wish no DDOS, no long queue, more Accept
A friendly time … Hope this round will no DDOS. no queue & Compact statement.
Rated Div.2 and a friendly time to Chinese again!!!
When contest will be start,open some problem in new window..May be it will be useful if DDOS attack happend.
You can simply just open the "Complete Problemset" page!
Wish me good rating
I wish you all too.
you too
Score distribution?
The Saratov olympiads are popular on Codeforces :)
Score........... :3
Why cant I submit my code on problem A? it says I have already submited the same code (I submited different codes for several times it says the same always), and in "My Submitions" there is nothing. os I cant submit my code on problem A.
How to solve B?
The solution is max{N, 2 * (N — positionOfTheFirstStaircase), 2 * (positionOfTheLastStaircase + 1)}
Is N really needed in the maximum comparison?
If there is no staircase the solution is N
Isn't answer for following 14?
Actually, nevermind.
I used BFS and start point is (floor,room)=(0,0)(0,s.size()-1)(1,0)(1,s.size()-1)
No need to use BFS or DFS actually, the solution is always fixed, you can use two pointers on each end of array, then you decrease the n, when you see 1's on either side you do the followings;
10000 or 00001 -> If 1's is at first or last means = n*2 (where n is array size)
In other situations like following, answer is always decreasing;
initially n = 5;
00010 -> n = 4 here, ans = 2*n = 8
00100 -> n = 3 here, ans = 2*n = 6
01000 -> again n = 4 here, ans = 2*n = 8
It does not matter how many 1's we have, the point is we need to have at least one 1's and position of 1's
01110 -> again n = 4 here, ans = 2*n = 8
there are only two possible cases either you start from leftmost room and use rightmost stair or start from rightmost room and use leftmost stair. ans is maximum of these two cases.
What on earth is test case 5 for C
:(
I can totally feel you bro... i wrote a solution which worked for 10^6 test cases that I randomly generated using Chelper and my code passed without any error, but this case 5 totally took my life.
try this if you use exgcd approach:
1000000000000 90000000000000007 100000 77777
Answer should be
899999922230 99991 99999977779
My exgcd template failed on this because of long long overflow when multiplying
Nice catch! I got -1 in my implementation...
Thanks for your sample so much. And how to use __int128 without Compilation error in Codeforces?
me,too.I also got a Compilation error when I used __int128 to avoid the overflow with exgcd.And I also want to konw can we use __int128 in Codeforces?
Codeforces runs on 32-bit system so __int128 is not supported.
In this problem __int64 is enough to get accepted, where an extra mod should be added. Here is my code.
If you really want to solve that equation, maybe you could try something like this:
The goal is to find the smallest possible $$$y$$$ such that $$$wx+dy=p$$$.
We could first divide both $$$w$$$, $$$d$$$ and $$$p$$$ by $$$gcd(w, d)$$$ then $$$w$$$ and $$$d$$$ become coprimes.
We take $$$mod\ w$$$ and the equation becomes something like $$$dy=p \ (mod\ w)$$$. Thus $$$y=p\times {d}^{-1}\ (mod\ w)$$$.
For coprimes, modular inverse always exists and could be found by extended euclidean algorithm.
So nice!It fits well with the data range.Perhaps cuz I am too inflexible when learning euclidean algorithm.
Why we need to find the smallest value of y? I get all of your explanation except that smallest y part. Please help me out.
Maybe you would like to check this out.
Will this solution work if the value of w and d is big (1e9) ?
I believe so (as 1e18 could still be handled by long long). But it may require more careful implementation.
What is C's solution?I solved A,B and D, but I could't solve C.:(
first check if the (p % (gcd of(w,d) != 0) then the answer -1.
then you should know the min number of draw matches you need cuz of (d<w) and more number of winning matches.
so you should precalculate this : Mod[ (i*d) % w ] = min ( Mod[ (i*d) % w ] , i ) for each (0 <= i <= w-1) calculate def=(p%w) and now you know the min number of draw matches you need to achieve ( def = (Mod[def] * d) % w )
the number of draw matches is Mod[def] and the number of winning matches is ( ( p — (Mod[def]*d) ) / w ) just make sure the sum of them less or equal to n then print them
Thank you for the easy-to-understand explanation!
Why condition (p % (gcd of(w,d) != 0) is correct? I think its correct if w and d can be <0. But in our task we have to find >= 0 multipliers. For example, n = 100(its doesnt matter), p = 17, w = 7, d = 6 (answer = -1, but the condition passes it). So, can someone explain me why do we need this condition?
it is correct in all situations.
I didn't say it's the only condition.
it just to make the approach faster.
after calculating the answer check if the values are valid, that's mean ((a+b)<=n &&(a>=0)&&(b>=0))
your example : 17 7 6 def = 17 % 7 = 3
Mod[0]=0
Mod[1]=6
Mod[2]=5
Mod[3]=4
Mod[4]=3
Mod[5]=2
Mod[6]=1
Mod[def] = Mod[3] = 4
so the numbers of draw matches are 4
then the winning matches are equal to (p-(Mod[def]*d))/w .
which is (17-(4*6))/7=(-7)/7 = -1 .
(a<0) is not valid value.
then the answer is (-1) .
What is Approach for C??
So weak at number therory, How to solve C...
Diophantine equations i guess.
I implemented Extended Euclidean alg and got one of the solutions of the eqn
x*w + y*d = p
and then the general soln for this eqn isx = x0 + k*(d/g) and y = y0 -k*(w/g)
. So I ran a loop for k from 0 to 1000000 and found ifx+y<=n
if yes then I print x y and n-x-y. But this is giving me wrong ans on test 4. :(k
may be less than 0, but on test 4 it doesn't matter:( I tried the same way as you.I missed this case when k<0 shit. Thank you
Even when k varies from -1e6 to 1e6 ; this does not help... I did the same mistake in contest and then got help from a friend to figure out that k can be huge too...
Reason — your x0 and y0 will always be less than d ( or w ; which ever you use to find particular solution ) ;
and then x = x0 + k * (d/g) when k has upper bound = 1e6 can only take you somewhere upto 1e11 even in best case.
Then how would you ( and also I will )find solutions whose actual answer is something like ( 1e16 , 0 , 0 )
This is only true for y. You need the possibility to decrease the number. Only possible when transforming $$$w$$$ draws into $$$d$$$ wins not vice-versa.
So do you mean we can vary k from -1e6 to 1e6 finding x0 first and then y0 ;
And then vary k again from -1e6 to 1e6 in case we don't get a (x,y) ; but this time find y0 first and use it to find x0 ?
I have tried the diophantine equation but no luck. What a bad problem for C..
same here but could not cross test case 5
try this test: 4 7 3 2
answer: 1 2 1
your answer might be: -1
i've got WA 5 too.
tried it but my aswer is 1 2 1
No, my solution gives 1 2 1 but failed at test case 5.
Edit: Overflow seems to be the issue.
Overflow was not an issue, I used big integer library and diophantine function still it did not cross test case 4.
i think that the case 4 is not about overflow
Same here. Stuck on test case 7.
I tried to solve it using extended GCD algorithm. This helps you to find (x, y) such what:
wx + dy = p, though after finding a initial value of (x, y) you need to somehow convert it into a valid solution (Here is where I got totally stuck)
You can use extended Euclidean algorithm to find x and y(keep in mind there can be more than one solution to the linear combination, so you need to take the one where y is minimal while still being >= 0).
brute force would work cuz small contraints on w or d
I used brute force but got TLE on test 66
Me too. It was enough to check if the solution exists by checking divisibility of p by gcd(w,d)...
binary search and binary search and more binary search... no number theory no nothing only binary search... at least that's how I did it
could you explain your approach ??
First I search for an x(number of wins) such that there "may" exist a possible y(number of draw) value so that x*w + y*d = p. (if n = 30, p = 60, w = 3, d = 1, and you pick x = 1, even y = 29 won't be enough to get 60 points and if x = 30 you are way over 60 point mark and there does not exist a way to reduce points.) Notice the "may"? because even you pick a valid x, then remaining points you need to gain is rem = p-(x*w), and if (rem%d != 0) then there does not exist any y for which you can gain p points (because there won't exist a y for which rem = y*d). But d <= 1e5. So all we need is pick some x such that rem%d = 0. how to pick such x? brute force. start from the initial x that we found. then run loop for (x+i) where (i runs from 0 to 1e5). and another similar loop for (x-i).
Legend_of_Azkaban coudnt understood this part "So all we need is pick some x such that rem%d = 0. how to pick such x? brute force. start from the initial x that we found. then run loop for (x+i) where (i runs from 0 to 1e5). and another similar loop for (x-i)" Can you explain? Thanks :)
I assume you understood the part why we need such x such that rem%d = 0. The explanation of the next part is: say you have a number a <= 1e5. Now from any number x to x + 1e5, (that is x, x+1, x+2....x+1e5)it's guaranteed that there exists at least one such number c within this range that is a multiple of a. Now if you will consider only the multiples of some number b, that is you want to find one multiple of a from x, x+b, x+2b... then your search space should be x to x+ b*1e5. that's what I did, start from x and go to x+1e5. In the meantime see how rem changes. rem = p -x*w(initially). then rem = (p-x*w) -x, (p-x*w)-2*x, (p-x*w) — 3*x...(as you increase x by 1 every time, you are only considering multiple of x). Now if I run this loop till x = 1e5, then I traverse a range from rem to rem — x*1e5. And if that does not give us any multiple of 'd', then we won't find any even if we continue searching. Here We need to consider both increase and decrease of x. because maybe if you keep increasing x you may find x*w > p , before you have reached a multiple of d. But if you decrease the value of x, you will find one correct multiple of d.
https://codeforces.me/blog/entry/70516?#comment-549838
After contest, I solve F and G by myself, so C is the hardest for me...
Was E not a greedy solution?
We ca use Binary Search to find minimum difference, The Min. element or Max. element in the final array after applying operations will be from the original array.
can you please briefly explain, how can binary search be applied on E?
We can do binary search on the ans(i.e minimum possible difference between max and min element). let's say we want to find if it is possible to apply <=k operations such that difference is less than equal to X. we can traverse the array and for ith element we can assume it to be the min. element than max. value must be a[i]+X; so now all the values less than a[i] must be made equal to a[i] and all values greater than a[i]+x must be made equal to a[i]+X, so we can find number of operations required to achieve this if we sort the original array and keep prefix sum, similarly we will assume the ith element to be max. value in array and min. value will then be equal to a[i]-X. and then find number of operations required. we will finally keep the min. number of operations required after traversing the array so if this value is less than equal to k than do right = X-1; else left=X+1;
I guess, E is ternary search within binary search.
Yes it worked for me.
i solved it greedy
increase / decrease elements which frequency is less to the next element
I solved it by greedy.I hope it passes the main system cases too!
It will surely pass Bro!!!
Solutions of other participants and tests are locked for the next 30 minutes, since there is an onsite competition using the same problems. When it finishes, we will open the data for everyone.
We also need 30 more minutes to submit more problems :)
so is the system testing delayed by 30 minutes or it'll start normally?
how to solve C??
We can employ brute force. Iterate over all possible numbers of draws from zero to $$$W-1$$$. We can easily compute the number of wins necessary with a given number of draws and whether this configuration is possible (this requires that $$$P = Di$$$ mod $$$W$$$, where $$$i$$$ is the number of draws, and that $$$(P - Di) / W + D$$$ is at most $$$N$$$, since we need to have an integer number of wins and can have at most $$$N$$$ wins and draws). As soon as we find a working configuration, just print it and exit.
We now prove that this is optimal--in other words, this will find a solution if one exists. Note that if there exists a solution $$$(x, y, z)$$$ with $$$y \geq W$$$, $$$(x+D, y-W, z)$$$ is also a valid solution. Moreover, the total number of wins and draws in the second solution is lower than in the first, meaning the second solution is more likely to fit within our $$$N$$$ game limit. Thus, any optimal solution will have $$$0 \leq y < W$$$, as desired, so our solution will find a solution if one exists.
How one can prove that number of draws must be below $$$W$$$? I iterated to 10^7 but couldn't prover that it's correct.
As shown in the proof above, if there exists a solution with at least $$$W$$$ draws, there also exists one with $$$W$$$ fewer draws than this solution, so by this logic, we can reduce the number of draws by $$$W$$$ until it's less than $$$W$$$.
I musunderstanded. Thought that $$$y$$$ is number of losses. And I iterated over $$$z$$$ instead of $$$y$$$. But pretests has been passed. Thanks.
You can transform $$$W$$$ draws into $$$D$$$ wins.
I dont quite understand the notation you wrote, is W is as same as w in problem (same with D)?
Yes.
I really liked your solution. Above all its simplicity. Very good idea
Tank you Sir!
That helps me a lot,and when I passed this problem I konw that the exgcd is not unique to solve problems like this.It is only faster than O(N).
There's only one things you didn't mention that we must let P>=Di or we'll WA62,but anyway there maybe only me who don't think about it!
maybe
$$$(P-Di)/W + D$$$ is at most $$$N$$$
should be
$$$(P-Di)/W + i$$$ is at most $$$N$$$.
Am I right?
Finally a successful round with no delay,queue and most importantly no DDOS
I think C can be done using Linear Diophantine Equation, but I don't know how to find x, y, z so that x+y+z = n is satisfied. Any hints?
the z is variable, u should just minimize y due to w > d (it should be correct, but i had wa5 too :(
yeah i know, z is variable. but i didnt know how to use Linear Diophantine Equation to find such x and y so that z can be obtained which satisfies x+y+z = n.
You can just brute force on y, because it's at most W — 1, because you can always replace W draws with D wins and minimize it.
find solution with minimum x+y such that x,y >= 0.
It is the core part of my submission code with some comment. due to overflow issue, you should use python.
if n-(x+y)<0:
t=(n-(x+y))*g//(d-w) + (0 if (n-(x+y))*g%(d-w)==0 else 1);
x+=t*d//g;
y-=t*w//g;
I have an solution: the problem can become this: xa+yb=c (a&b&c are known)
And make y+x as minimum as possible (z = n-x-y)
to achieve this we must let y as small as possible (since a>b) ,so (c-yb)%a=0
because y must <a so try all the y,the smallest is the answer.
No DDOS attack No in queue, Finally codeforces was back.
Thanks to MikeMirzayanov and every on works in this awesome platform ^_^
UPD: WOW and Fast system test !!
Problem C makes me feel like I'm in ICPC onsite, instead of Codeforces. (╯^╰)
Yes it troubles many people!
How to solve D?
First, the answer is $$$-1$$$ unless the tree is a line (i.e. all vertices have degree $$$2$$$, except for two, which have degree $$$1$$$). Proof: suppose vertex $$$A$$$ is connected to vertices $$$B, C,$$$ and $$$D$$$. By considering the paths $$$B-A-C$$$, $$$C-A-D$$$, and $$$D-A-B$$$, we see that all four of these vertices must have different colors, but with only three colors, this is impossible.
If the tree is a line, then there are six possible configurations, each of which results from fixing the colors of one of the endpoints and the vertex adjacent to it. We can simply brute-force all six configurations and print the best one.
The tree has to be a straight line to have any solution, since if it has more than 2 degree it can't be satisfied with 3 colors. After that the color has only 6 possibility: $$$[1,2,3,1,2,3,..]$$$ $$$[2,3,1,2,3,1,..]$$$ .. and all other permutations of $$$(1,2,3)$$$ repeated
wow! thanks.
something wrong in my solution, but idea was the same(
Couple small corrections and it passed:
https://codeforces.me/contest/1244/submission/62530591
Thanks!!
What's the approach to solving E?
We employ a greedy approach. Start by sorting the data. Then, until we're out of moves and in increasing order of $$$i$$$, increase elements $$$0$$$ through $$$i$$$ to the value of element $$$i+1$$$ and decrease elements $$$N-1$$$ through $$$N-1-i$$$ to the value of element $$$N-2-i$$$.
On our first iteration our answer decreases by one with each of our moves (since we are increasing/decreasing the minimum/maximum with every move), on our second iteration our answer decreases by one after every other move (since we need to increase the lowest two elements now each time we want to raise the minimum, and similarly for the maximum), and so on. It's relatively easy to see that we can't do any better, since at each step we're choosing the most efficient possible way of closing the gap.
can you please explain with a small example?
In sample case one, the sorted data is $$$1, 3, 5, 7$$$, and we have five moves. First, when $$$i=0$$$, we use our first two moves to increase the $$$1$$$ to $$$3$$$ and the next two moves to decrease the $$$7$$$ to $$$5$$$. Thus, we have one move left and have the array $$$3, 3, 5, 5$$$. Now, we have $$$i=1$$$, and we want to increase the first and second elements to the value of the third. With only one move, the closest we can get is the array $$$3, 4, 5, 5$$$ which has range $$$5-3=2$$$.
Can anyone find the mistake with my algorithm? I WA on pretest 8.
I defined Lcost(i) to be the cost to make subarray [1..i] equal to a[i] and Rcost(i) to be the cost to make subarray [i..n] equal to a[i]. Then used two pointers: For each l such that a[l] < a[l+1], let r be the minimum r such that Lcost(l) + Rcost(r) <= k. Since Lcost is increasing, r will be increasing as we iterate over l. Finally, we have some extra moves we are allowed to make: extra = k — Lcost(l) — Rcost(r). First, if r = l+1, then we can decrease the gap by floor(extra/min(l, n-r+1)). If r > l+1, then we try to fill the two gaps greedily: if l < n-r+1, then try to increase l first, then decrease r. Otherwise, do the opposite. There is an edge case which is we constrain l to increase by no more than a[l+1]-a[l] (this should not be necessary for r).
I return the minimum of the answers for each valid l.
I started solving C before thinking that I can totally solve C fast. But a very very wrong decision :( from my side. And now I am totally going down in rating.
Is it possible to solve problem C using binary search?
I tried Binary Search for y inside a binary search for x .. i got a WA on test 4 :\
Binary search cannot work because of the boundary not being clearly defined. A
y
may not satisfy the equation due to divisibility buty-1
may.Solution for C: Assume, that you have $$$X$$$ won, $$$Y$$$ draw games. Say, that you won't take $$$y$$$ more, that $$$w$$$, beacause, in other way we will get $$$(w + (y\mod{w})) * d + x * w\leftrightarrow w*(x+d) + d * (y\mod{w})$$$, and y will be less, that w. If we know Y, we can get X: $$$(p-y*d)\div{d}$$$ check, that this answer is correct, and print it, if true.
D was very interesting problem, how to solve it?
Observation: If there is a node with more than/equal to three edges, whatever you paint you will get a path of three nodes with "only two" colours. So any valid painting must be a list/degenerate tree. The colour pattern must be a sequence of "RGB"/"RBG"/...
tree is a line if not answer = -1. After that you calculate all case and chose a best case =))
RIP testcase 5 for C
C really difficul with me :((
Could someone tell what was the use of small constraints of w,d in C. How was it useful for brute force and when will the answer be -1?
For number theory solution, one may need to solve a diophantine equation $$$xw + yd = p$$$. Take mod and we have $$$yd=p$$$ mod $$$w$$$. This "small" constraints enable brute force solving but not taking modular inverse.
problem C really difficul with me :((
What is pretest 8 for E??
I tried to solve C but I Got Wa on test 5 using Binary search I don't know why my idea is wrong, anyone can help ?
I was searching for number of wins so my start = 0, end = n, them (n — mid) will be number of draw matches, So total points so far = mid * w + (n-mid)*d, Now the idea,
if total points < p, I should win more matches, So start = mid + 1 and continue searching.
if total points == p, So I can win with this number of wins and this number of draws with 0 lose matches.
if total points > p, (rem now is the number of draw matches),
I will try to make the team lose from o to rem matches using the same idea(binary search) if I found at sometime I can make the same exact point this will be answer otherwise I will continue searching using the same idea of binary search
code: 62490213
That will not work.
Why? I Tried a lot of cases and it works,
please can you explain ?
tyr out this one 30 60 9 4 one of the answer would be 4 6 20
I can't solve problem A
I don't like this round
poor you :)
Too many shit problems in a single div2 nowadays.
Come on, even div2s got some dignity. Show some respect. Please don't shove bunch of div2Cs in div2s like people don't give a shit.
Great round, make more rounds like this!
Please don't just shove a bunch of div2Cs in a row in div2s. Come on, even div2s got some dignity :|
Too many shit problems in a single div2 nowadays :|
??
What @maxorand implies is not that he can't solve the problems, but that he thinks that the problem are too easy (too many problems with the difficulty of a Div2 C).
+1. DEF are all at same level.
I am glad that the round passed without DDoS attack :)
C is more difficult than D, E and F.
Unfortunatly did read E and F after contest :/
I think you misread E. E was not easy
You are right, implementation is not that simple as I thought first.
Отличный раунд, однако так как в раунде 7 задач, по моему мнению он должен был бы длиться не 2 часа, а 2 часа 15 минут или 2 часа 30 минут. Тогда бы многие успели бы сдать еще задачи, в том числе и я.
А если бы он длился 24 часа, то многие еще больше успели бы сдать...
То есть, С у вас упала из-за того, что раунд был коротким? :)
In C you can just brute force on Y from 0 to 1234567, it's work but don't know why, can somebody explain?
$$$Y$$$ can be at most $$$w - 1$$$, if its more than $$$w$$$, then transform them to $$$d$$$ wins instead of $$$w$$$ draws.
thank you
the (p — d * i) % w will form a cycle and you just need to find the i that (p — d * i) % w equal to zero
cycle with at most w elements, because only w reminders exist, so if it is'n good i in first w tries output is -1
why it doesn't work for 100000, it is given in problem that w is max 100000.
work https://codeforces.me/contest/1244/submission/62505565
I did exactly same but got wrong answer on test case 62
you missed cases like the one given in below comments: 2 1 5 3
Bro the mistake was that, i didn,t checked that (p — d * i) >= 0
Most system fail in today's Div 2 C. I wonder why they keep such weak pretests?
to invite more hacks.
Problem C pretest were too weak, constrains were not checked.
OMG!! so many system test fails for C on Test 62.
try 2 1 5 3
thank you.I've made a mistake in my program.
Congrats to Tynoo for the hack creating test 62.
Lol, nice system tests on C. What is approach failed?
Powerless to solve problem C when I haven't known diophante before.
You dont need it. You can just brute for all number of draws < W. (1e5)
How to solve C?I got a wrong answer on test 62...
It's a good choice to give up C :)
It's a good choice,indeed.
So, very nice round)) Everything was cool except C. Only 500+ solutions from more than 1500 have been accepted :(
Thanks so much... First time become blue <3 thanks ^^
what is pretest 6th in d??
Loved the contest!
Спасибо за очередной едук !!! ( Внимание! Задачи не отсортированы по сложности )
what is the core logic behind F?
The observation is if we have a contiguous subsegment of single coloured cells, they would never flip. If we have a contiguous subsegment of alternating black and white cells, the length of this segment would decrease by 2 each time we flip it. (You can view this as the cells on the ends of this segment are absorbed by the single coloured segments adjacent to them). Based on this, we may work out the max possible number of flips each position could do.
Okay, I get it. Thank you :)
Excuse me... Why my code get skipped?
За задачу С вполне можно было дать и 2000+.
The problems of this round are sooooooooooooo hard to implement!
If you got WA on test case 49 in problem C, you may miswrote p>n*w as p>=n*w in the beginning like me...TAT I submitted it very early and in the rest of competition I did nothing... What a pity!
I really liked the problems, but spent too much time on C :(
Can someone explain why brute force works on C? I brute forced for values of x between (p-n*d)/(w-d) and p/w. Isn't this still o(P)?
p <= 1e17
I tried to brute force on x it didn't work .. then i tried to brute force on y i got accepted , can anyone explain please ?
you cant brute force on x cuz it could be between [1,min(n,p/w)]
but y can be only between [1,w-1]
proof : if y=w then y*d=w*d
rewrite it like this y*d=w*(a1) where (a1=d)
you can see (a1<y) cuz (w>d)
so it's better to consider (a1) winning matches than (y) draw matches
I want to try to solve more problems like C, Kindly can anyone suggest those problems?
Editorials?
Very sorry to write this, but big downvote for problem C! A well-known problem. The statement itself contains exactly the equation you need to solve (x * w + y * d = p). And you have to deal with int64 overflow when solving it with extended Euclid! (test 7) WTF
More than 10 people in the top 40 did not pass C
During the contest, I use exgcd for problem C, then I realized that the answer in problem C may cause longlong overflow, so I tried to use __int128, and then
So I wonder if it is possible to solve problem C by using exgcd(No matter in python or C++).
link
Thanks
What's the idea/observation behind this specific solution? I understood till the line " p /= g, d /= g, w /= g; "
What's happening after that?
link
Thanks
Okay, I have one more question. Does it ensure that x+y will be minimum as I can see you've checked for the only root found from the modInv? Otherwise shouldn't I be looking around for other roots?
I guess it is minimum. Since $$$d < w$$$ and we must use either $$$wx$$$ or $$$dy$$$ to "fill" $$$p$$$, it seems to be optimal to use the smallest possible $$$y$$$.
And there should only be one $$$y$$$ under $$$w$$$.
Found a blog-post to overcome the overflow including proof on the comment section. Works fine for this problem as well. Avoid overflow in linear diophantine equation
You can use this BigInt struct.
???? My rating is lost???
Me too, there may be some technical problems.
:((( the first time I become expert :<<< so sad.. may be it's unrated :(
Everyone's rating history is lost, as I am not able to see anyone in rating lists. Something wrong with the system.
It's back :D
is this contest unrated?because a few minutes ago i had updated ratings but now it is back to one which was before the contest
Oh my god , is this round unrated ?
I'm a step away from the master .
Sorry it is a DDOS attack.
hiahiahiahia!!!!!
Why after the contest my rating was up, and after 2 hours it was resumed to the previous state?
Me too.What's going on?
Плохой раунд, ИМХО
+ матеша фу
RIP my rating. I was racking my brain trying to figure out a counterexample to my heuristic for B but turns out it was just a simple off-by-one bug.
Also had no luck figuring out the number theory required to solve C analytically, and missed the brute force solution.
Editorial ?
Nice article to read for C.
(https://math.stackexchange.com/questions/20717/how-to-find-solutions-of-linear-diophantine-ax-by-c?rq=1)
why Y can be atmost W-1 in problem C ?
If y == w, we can say that we won d matches (y == w -> y*d == w*d)
I can't understand.
If y=k*w+r and x=x0 — solution, so: y=r and x=x0+k*d — solution too, because: r + (x0+k*d)<r+x0+k*w<=n (This thing reminded me about Pell's equation xD)
Can somebody help me, why am i getting runtime error ? https://codeforces.me/contest/1244/submission/62522364
C was the only problem out of 7 I couldn't solve myself. Maybe once I will start reading all statements and won't stay on 1 for the whole round :P
Editorial, please?
I took a lot of time thinking about C and later started solving D. When I finished the code, I saw: "Contest has ended. Thanks for your participation." :'(
Relatable.
Meh, graphs are a weakness for me. E though, I thought I had a chance of solving, but I kept failing at pretest 13
edit: And it turns out it's an integer overflow bug. I'm just off my game this round
When the editorial will be avialable? C very interesting problem:)
How to solve Problem C using Linear Diophantine Equation?
Specially after finding x,y by using Linear Diophantine Equation how to maintain x+y<=n?
Once you form equation for
x = x1 - k*b/gcd(a,b)
andy = y1 + k*a/gcd(a,b)
.x1
andy1
are two coefficient you get from extended euclid algo. Check which one is negativex1
ory1
. From that you can derive one inequalityk>=c1
.Now known x+y <= n. Plug in equation of x and y in that. Only unknown in that equation is k. Solving this inequality will give you something like
k<=c2
.All values of k will give you one answer which satisfy above two inequaliteis.
k>=c1
andk<=c2
PS: This answer helped me understanding solution for Diophantine Equation. https://math.stackexchange.com/questions/20717/how-to-find-solutions-of-linear-diophantine-ax-by-c?rq=1
How can you be sure that there(x1 & y1) will always a negative value?
And what is c1 and c2?
Its or condition.
Not and condition.
the most difficult problem for me was C, without it or putting it as the last one, the contest could have been a good div3
Thanks a lot.The time is friendly to Chinese.And no DDOS attack
Since when does E div 2 can be solved using greedy only?
why G problem is not that much hard ?
I think problem G is very easy,easier than problem D.
Same feeling
My English is not good...
In fact problem C is not as hard as you think,you don't need "exgcd" to solve solution.
Chinese solution
you see, $$$1 \leq d < w \leq 10^5$$$ .
Greedy, $$$w>d$$$ ,so we can make $$$x$$$ bigger,and you can implementation $$$d$$$
code:
I felt that the ordering of difficulty of questions in this contest was: A<B<D<F<E<G<C.
I should have gave up C to have a look at problem E QAQ
How to solve E?
Hi can anyone please tell me why my solution for D Problem keeps getting Memory Limit Exceeded Verdict ? 62615746. Thank You