![](/style/images/good.png)
![](/style/images/bad.png)
Codeforces Global Round 17 Editorial
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.
![In English](http://codeforces.org/s/56581/images/flags/24/gb.png)
1610A - Anti Light's Cell Guessing
Idea: Anti-Light, Preparation: DeadlyCritic
1610B - Kalindrome Array
Idea: -zeus-, Keshi, Preparation: AmShZ, Keshi
1610C - Keshi Is Throwing a Party
Idea: Keshi, Preparation: Keshi
1610D - Not Quite Lee
Idea: DeadlyCritic, Preparation: DeadlyCritic
1610E - AmShZ and G.O.A.T.
Idea: AmShZ, Preparation: AmShZ
1610F - Mashtali: a Space Oddysey
Idea: AliShahali1382, Preparation: AliShahali1382
1610G - AmShZ Wins a Bet
Idea: AmShZ, Keshi, Preparation: AmShZ, Keshi, alireza_kaviani, AliShahali1382
1610H - Squid Game
Idea: Tet, AliShahali1382, Preparation: AliShahali1382
1610I - Mashtali vs AtCoder
Idea: AliShahali1382, Preparation: AliShahali1382
![paperclip-16x16.png](http://codeforces.org/s/56581/images/icons/paperclip-16x16.png)
22 hours ago, # |
errorgorn cluck cluck cluck!
-
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 wroteif (a*b==0)
. Theres no way anyone will be able to predict that lolhonestly, 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
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.
22 hours ago, # |
Just a little suggestion: we should use and instead of and to make the editorial more pleasant to read.
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..
17 hours ago, # |
136659229 Can anyone tell me what is wrong in this code of B (Kalindrome Array). All similar codes got AC.
-
Integer's cache so that your '==' could be wrong.use int is ok.
-
Thanks, It solved my problem. But I never faced such type of problem with Integer before. What was the reason now?
-
17 hours ago, # |
For problem C if the constraints supported O(N*N),then would DP work?
-
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.
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
-
I guess it should have been, "If g is odd ci(ci-1) % (2g) == 0"
Second para of This Comment might help -
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.
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?
-
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
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?
-
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
-
My solution uses a similar kind of idea (see 136678450):
Lemma 1: We only delete contiguous valid bracket sequences
Proof sketchThen, 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
wheres
is a valid bracket sequence. Let be the position where the suffixt
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 suffixs)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 suffixt
, 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'
wheres'
is some subsequence ofs
, andt'
is the optimal solution for the suffixt
. So, we actually ask whether(s')t'
is lexicographically smaller thant'
, and we can already decide this after looking at all characters of(s')
:- If
(s')
is not a prefix oft'
, we know due to our comparisons which string is smaller. - If
(s')
is a prefix oft'
, I claim that(s')t'
is smaller. This is because removing the prefix(s')
fromt'
would also be a valid solution for the suffixt
, but must be larger thant'
by the optimality oft'
. Therefore, it is easy to see that appending another copy of(s')
to the beginning oft'
will make the string even smaller.
I claim that if we use this optimization, the code runs in time .
Why is this? - Either we include the first
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!!
-
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.
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
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|;
-
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).
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, # |
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).
First time to solve C in a contest! "A" was weird not gonna lie but for me the contest was very interesting :D
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK