46

Codeforces Global Round 17 Editorial

 2 years ago
source link: http://codeforces.com/blog/entry/97179
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
By Keshi, 25 hours ago, In English

1610A - Anti Light's Cell Guessing

Idea: Anti-Light, Preparation: DeadlyCritic

Hints
Solution
Implementation

1610B - Kalindrome Array

Idea: -zeus-, Keshi, Preparation: AmShZ, Keshi

Hint
Solution
Implementation

1610C - Keshi Is Throwing a Party

Idea: Keshi, Preparation: Keshi

Hints
Solution
Implementation

1610D - Not Quite Lee

Idea: DeadlyCritic, Preparation: DeadlyCritic

Hints
Solution
Implementation

1610E - AmShZ and G.O.A.T.

Idea: AmShZ, Preparation: AmShZ

Hints
Solution
Implementation

1610F - Mashtali: a Space Oddysey

Idea: AliShahali1382, Preparation: AliShahali1382

Hint
Solution
Implementation

1610G - AmShZ Wins a Bet

Idea: AmShZ, Keshi, Preparation: AmShZ, Keshi, alireza_kaviani, AliShahali1382

Hints
Solution
Implementation

1610H - Squid Game

Idea: Tet, AliShahali1382, Preparation: AliShahali1382

Solution
Implementation

1610I - Mashtali vs AtCoder

Idea: AliShahali1382, Preparation: AliShahali1382

Solution
Implementation

22 hours ago, # |

errorgorn cluck cluck cluck!

  • 15 hours ago, # ^ |

    Rev. 3  

    +49

    lol in all seriousness, no hard feeling about it. as a fellow problemsetter i also understand how hard it is to create strong pretets for problems because theres no way you can kill every possible weird thing people do

    i still remember in RAIF round there was the A had some condition like if (a==0 || b==0) and someone wrote if (a*b==0). Theres no way anyone will be able to predict that lol

    honestly, i enjoyed this contest. having FGHI to jump around and finally solving G was really fun, thanks for setting this contest :)

    update:

    now we are both stupid chicken

    • 13 hours ago, # ^ |

      blobheart

      shit! what a stupid hack test

      • 13 hours ago, # ^ |

        Rev. 2  

        +28

        You should see this too...

        In fact this thing TLEs on n=40 locally most of the times but cf reruns TLE submissions so I had to make n larger.

        K*re khar

22 hours ago, # |

Btw just saying, the story in D was about the fact that we didn't have D days before the contest, because of the testers' feedback and also because the fact that I didn't solve C and D until about then, I decided to add D to fix the gap, it wasn't perfect however. Hopefully made the round better.

  • 8 hours ago, # ^ |

    It kinda fixed the gap according to the numbers, and imo it is a decent problem. Won't ask for more from problem D in a div 1+2.

    P/S: It indeed made the round better.

    • 8 hours ago, # ^ |

      Thanks for your feedback. Makes me happy.

22 hours ago, # |

Just a little suggestion: we should use and instead of and to make the editorial more pleasant to read.

  • 17 hours ago, # ^ |

    Thanks!

21 hour(s) ago, # |

In problem I, am I the only person who actually solved the AtCoder problem in contest without looking at it?

21 hour(s) ago, # |

Lol! Testcases in ques.3 were pretty dumb..

19 hours ago, # |

I think hint 3 from problem D is missing the sum symbol on the RHS.

  • 17 hours ago, # ^ |

    Thanks!

17 hours ago, # |

136659229 Can anyone tell me what is wrong in this code of B (Kalindrome Array). All similar codes got AC.

  • 15 hours ago, # ^ |

    Integer's cache so that your '==' could be wrong.use int is ok.

    • 14 hours ago, # ^ |

      Thanks, It solved my problem. But I never faced such type of problem with Integer before. What was the reason now?

      • 14 hours ago, # ^ |

        The reason is simple you can't compare two objects with ==, cause it checks their references equality, instead you have to use the equals method.

      • 14 hours ago, # ^ |

        Rev. 2  

        +3

        Integer will cache value between -127 to 128, and you can use '==' within this scope.if beyond this scope you should use 'equals' instead of '=='.For more details, you can see the source code of Integer.

      • 13 hours ago, # ^ |

        The reason is not coding in IDEA or ignoring IDEA's warning about objects comparison

17 hours ago, # |

For problem C if the constraints supported O(N*N),then would DP work?

  • 16 hours ago, # ^ |

    Yes, we can do something like this. dp(len) denotes if the length of the sequence is len, then what is the maximum count of right_most elements that we can add to this sequence. And for each i, with dp(len) we can update dp(len+1) if dp(len) > 0.

    • 15 hours ago, # ^ |

      I don't think 1-d DP will work, solely because the value of b[i]'s can differ and can produce different output, so I was asking about a solution based on dp[n][b[i]]!

17 hours ago, # |

Rev. 5  

-13

vscode txdy

16 hours ago, # |

I cant understand D's explaining gcd(c1,c2,…,ck)=g s=∑ ci(ci−1) / 2 i= (1...k) when g is odd s % g == 0 && ci / 2 % g == 0 why how to explain c1 = 3,c2 = 9

  • 15 hours ago, # ^ |

    I guess it should have been, "If g is odd ci(ci-1) % (2g) == 0"
    Second para of This Comment might help

  • 15 hours ago, # ^ |

    Me neither. Neither I understand what is "x" in x1c1+x2c2+…+xkck. I would understand it if the equation would be (x1c1 + c1/2) + (x2c2 + c2/2) + ... + (xkck + ck/2). For example if c1 would be 4, we can get sums like 2, 6, 10, ..., no 4, 8, 12, ...; or is "x" supposed not to be integer?

    Another point:∑i=1kxici=−sum is it supposed to be ∑i=1kxici=−s or what is "sum"?

    Btw sorry for formatting, but I don't know how it works on CF

16 hours ago, # |

How is the below solution wrong for problem B? I am not able to figure out the test case.

136636817

  • 15 hours ago, # ^ |

    136659229 Same happened with me. Whereas all similar codes got AC.

  • 11 hours ago, # ^ |

    Same, Got WA on 3414th token.

    Works with primitive type. OR, using Integer.equal(Integer) when comparing elements from list of Integer wrapper class also works. Not sure why!

    • 9 hours ago, # ^ |

      Yeah exactly.

  • 11 hours ago, # ^ |

    Rev. 3  

    +1

    You might get WA on this test:

    1 3 2 4 1

    Edit: the result is correct, my bad

16 hours ago, # |

Can someone pls explain the even case in problem D ?

16 hours ago, # |

Can anyone E in detail? I am not able to understand hint 1 properly.

15 hours ago, # |

I did read and tried to understand several explenations to C. But still do not get how or why the check "is it possible to invite x persons" works.

What is needed to understand that kind of logic?

  • 14 hours ago, # ^ |

    To break it down: We are going to invite X persons, and they are already sorted from poorer to richer from 1 through n We keep a counter of how many we invited until now : cnt

    When we are going to the i-th person we check for two things 1. we know we already invited cnt poorer persons (Since all people before i-th are poorer than him) if (b[i] >= cnt) then this condition is fulfilled 2. we know if we invited this person we are going to invite another (X-cnt-1) people (X: total invited, cnt: currently invited, 1: the i-th person himself) if(a[i] >= X-cnt-1) then this condition is fulfilled If both conditions are fulfilled, we invite this person and increase cnt by 1 after going through all n people, if (cnt >= X) then we can invite X people

    Hope this helps you

    • 10 hours ago, # ^ |

      Thanks, I couldn't understand this part from editorial, I really appreciate you helping in the comments.

15 hours ago, # |

I hope this doesn't get down-voted For problem D, I didn't get the solution proposed above. However, I was thinking of a solution from another angle. Firstly, Odd numbers can can have a sum of 0 by itself so we can have any number of odd numbers in our sequence, Even numbers can have a sum of 0 for sure if there is at least 1 odd number in the sequence since O+E = O. The problem I couldn't figure out, When can E numbers alone (Without any odd number in the sequence) have a sum of 0 I don't know if anyone solved it in this approach, and is it possible this way or the only solution is the one in the editorial?

  • 14 hours ago, # ^ |

    I did solve it in the way you described, and interestingly the answer to your question is the same condition as the editorial arrives at- if you bucket the even numbers by the maximum power of two that divides them, then to create a bad sequence, you need to have an odd number of elements from any one bucket, zero elements from the buckets below it, and any combination from the bucket above.

    For example, if we have 2, 2, 4, 4, 8, 8, 16, 16, 48

    We bucket it as follows {2, 2}, {4, 2}, {8, 2}, {16, 3}

    And the number of bad sequences u can create is -

    select odd number of 2's and no restriction on other buckets: 2C1 * 2^7

    select no 2's, odd number of 4's, and no restriction on other buckets: 2C1 * 2*5

    and so on.

    Solution: 136657523

    • 14 hours ago, # ^ |

      Rev. 2  

      0

      Never mind, I get it now. Thanks a lot

  • 14 hours ago, # ^ |

    You can suppose that number 2 means 2x+1, number 4 means 4y+2 and number 6 means 6z+3, your purpose is that you should make their sum equal to zero, you can solve it with Bezout theorem.

    • 13 hours ago, # ^ |

      Thanks a lot

14 hours ago, # |

Rev. 3  

+30

I have an alternate solution for G without hashing.

136722671

lemma 1
solution
  • 13 hours ago, # ^ |

    My solution 136674351 is a bit different.

    solution
  • 10 hours ago, # ^ |

    My solution uses a similar kind of idea (see 136678450):

    Lemma 1: We only delete contiguous valid bracket sequences

    Proof sketch

    Then, let's move from right to left and compute the optimal solution for a suffix starting at position . We represent this solution by computing for every the position of the first bracket contained in the optimal solution for the suffix starting at . Reconstructing the solution for the suffix from the is easy: the first bracket in the solution is at position , and the remainder is the optimal solution for the suffix starting at (which we can reconstruct recursively).

    How do we compute ? If the bracket at position is ), then since we cannot remove this bracket. So, assume that the bracket is (. If there is no matching ) bracket in the string, we will again have since we cannot remove this bracket by Lemma 1. So, the only case remaining is that the suffix starting at position looks like (s)t where s is a valid bracket sequence. Let be the position where the suffix t starts (which we can compute using a stack).

    To obtain a solution for the suffix (s)t, there are just two cases:

    • Either we include the first ( bracket, in which case we have to append the optimal solution for the suffix s)t, which is the suffix starting at position .
    • Or we delete the first ( bracket, in which case we have to delete the entire substring (s) and we will only keep the optimal solution for the suffix t, which is the suffix starting at position .

    Since we know the optimal solutions starting at position and , we can simply compare them character by character (using the values ) to decide which is lexicographically smaller, but this has a runtime of up to .

    Instead, notice that the solution where we keep the first ( bracket looks like (s')t' where s' is some subsequence of s, and t' is the optimal solution for the suffix t. So, we actually ask whether (s')t' is lexicographically smaller than t', and we can already decide this after looking at all characters of (s'):

    • If (s') is not a prefix of t', we know due to our comparisons which string is smaller.
    • If (s') is a prefix of t', I claim that (s')t' is smaller. This is because removing the prefix (s') from t' would also be a valid solution for the suffix t, but must be larger than t' by the optimality of t'. Therefore, it is easy to see that appending another copy of (s') to the beginning of t' will make the string even smaller.

    I claim that if we use this optimization, the code runs in time .

    Why is this?

13 hours ago, # |

Can someone please explain hint 3 in problem D, I can't understand what x is here and how we are arriving at the given equation? Thanks in advance!!

  • 4 hours ago, # ^ |

    I described how to arrive at the equation in the complete solution, it basically means we move the -th sequence, times(i.e. add to all the elements in the -th sequence). If it's possible to find -s such that the sum of resulting set of sequences is , then they will satisfy the equation. Also the other way around. (i.e. if it's possible to find such -# that the equation holds, then the resulting set of sequences after moving the -th sequence times, satisfies the second property in the statement)

13 hours ago, # |

Here are the video Solutions to the first 4 problems of the round in case you prefer that.

  • 10 hours ago, # ^ |

    Thank you

13 hours ago, # |

problem H was given 2100 rated tag(its a mistake ig). Anyone know how problem rating works.

12 hours ago, # |

who can explain the problem D,the solution can't understand。

11 hours ago, # |

Thanks for pointing out the typos.

9 hours ago, # |

Problem I is just the normal Hackenbush problem on a graph with cycles .

You can turn a cycle into a node using "Fusion Principle". And implement it using Heuristic Merging of sets in O(nlog^2) .

submission:136731363

9 hours ago, # |

Rev. 2  

0

My ideology for the first who have any problem -> as in question we have given that computer hide some cells and on query (suppose k) are done and it will return the k values that will be the distance of hidden cells from the cells that are done by user as query

manhattam formula is important-> |a1-a2| + |b1-b2|;

Think Yourself
Case 1
Case 2
Case 3
  • 3 hours ago, # ^ |

    For Case 3, we cannot query cells in opposite corners. An example is given in the notes for the problem's test cases. There are multiple cells on the board with the same distance from the opposite corners. We have to query the cells on one side of the board. For example, (0, 0) (0, n-1) or (0, 0) (0, m-1).

8 hours ago, # |

Rev. 2  

0

In problem B, why do we have to find only the minimum i that ai≠an+1−i? What about the next i's where ai != an+1-i? EDIT : I understood why

  • 7 hours ago, # ^ |

    If you find the minimum i(say i1) then if you get another i(say i2) after this where ai2 != an+1-i2 then you will check whether you can make it ai2 == an+1-i2 by removing ai2 or an+1-i2 (you can remove ai2 only if ai2 = ai1 or an+1-i2 only if an+1-i2 = ai1). Hope you get it.

  • 7 hours ago, # ^ |

    If you find the minimum i(say i1) then if you get another i(say i2) after this where ai2 != an+1-i2 then you will check whether you can make it ai2 == an+1-i2 by removing ai2 or an+1-i2 (you can remove ai2 only if ai2 = ai1 or an+1-i2 only if an+1-i2 = ai1). Hope you got it.

7 hours ago, # |

Your text to link here... Can anyone tell me what is wrong with this code? I am unable to see the test case in which it is giving WA (Problem B).

6 hours ago, # |

Rev. 2  

0

First time to solve C in a contest! "A" was weird not gonna lie but for me the contest was very interesting :D

6 hours ago, # |

Rev. 8  

-22

anyone having hard time with D, here's a try

consider a sequence c of length k having integers c1,c2,c3, ... ck.

Here each integer will correspond to some continuous numbers of length equal to that integer.

lets consider the case for c1, lets say series corresponding to c1 will start with integer x1. so series will look like x1,x1+1,x1+2,x1+3,... (c1 terms in total) which sums up to to c1*x1+(c1*(c1-1))/2 (lets call it series_sum) now we want,

series_sum(c1)+series_sum(c2)+series_sum(c3)+...+series_sum(ck) = 0

c1*x1+(c1*(c1-1))/2 + c2*x2+(c2*(c2-1))/2 + ... = 0

c1*x1+c2*x2+...+ck*xk = -( (c1*(c1-1))/2 + (c2*(c2-1))/2+ .. + (ck*(ck-1))/2 ) = s(lets call it s) sum of ci*xi will divide s if gcd(c1,c2,... ck) divides s

consider gcd(c1,c2,... ck) = g being odd:: in this case every (ci*(ci-1))/2 term will be divisible by g, because ci is divisible by g(g is gcd of ci's), and ci(ci-1) term will have a 2 in factor after dividing it by g, because ci*(ci-1) is even and dividing it by g did not kill any 2 from here(because g is odd), so (ci*(ci-1))/g is an even number so (ci*(ci-1))/(2*g) is an integer.

so every (ci*(ci-1))/2 term is divisible by g so their sum is also divisible by g

** number of sequences with odd gcd = (2^number_of_odd_numbers_in_input — 1)*(2^number_of_even_numbers_in_input)

g being even:: (in this case all ci's are even cz an odd number would make g odd) lets say count of factor 2 in gcd = cnt

consider 2 cases

ci's where count of factor 2 in ci is geater than cnt:

here (ci*(ci-1))/2 divided by g will be an integer beacuse ci*(ci-1) divided by g will be even.

ci's where count of factor 2 in ci is equal to cnt:

here (ci*(ci-1))/2 divided by g will not be integer cz we have less 2's(exactly 1 less) in numerator.

but if we can take even number of these ci's then their sum will be divisible by g. lets see why.

we can write (ci*(ci-1))/2 as ((2^cnt)*an_odd_number )/2

or ((2^cnt)*odd1)/2 + ((2^cnt)*odd2)/2 ..... (even number of terms in total)

= (2^cnt*(odd1+odd2+ ... even number of terms) )/2

= (2^cnt*(an_even_number))/2

which will be divisible by g.

here we got an extra factor 2 from an_even_number that we needed.

so when choosing sequences with gcd which has number of factor 2 count is cnt then we will choose even number of numbers with factor 2 count = cnt and any number of integer with factor 2 count greater than cnt.

cur_gcd_ways = (2^number_of_numbers_with_factor_2_count_greater_than_curent_gcd_factor_2_count)* (2^(number_of_numbers_with_factor_2_count_equal_to_curent_gcd_factor_2_count-1)-1)

** ways to choose non empty even number of items from n items are 2^(n-1) — 1.

when implementing, in even gcd cases we will iterate over number of factor 2 in gcd

sorry if there's any mistake 136762437

4 hours ago, # |

Is there a way to solve problem F using Euler cycle/Euler path idea?

34 minutes ago, # |

can anybody give link/info on why the solution to is when divides as specified on Hint 4 of Problem D


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK