MemSQL Start[c]UP 3.0 Round 1 is over!

Congratulations to moejy0viiiiiv, Petr, drinkless and tourist on solving all the problems!

Here are our solutions:

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Auto comment: topic has been translated by cerealguy (original revision, translated revision, compare)In 859G - Circle of Numbers, it is possible to compute

P(x) at multiple random roots of unity of degreenmodulo multiple random primes of formkn+ 1. If all the results are zero, the answer is probably`YES`

, otherwise it is certainly`NO`

.By the way, my solution of G which I submitted during the contest doesn't use polynomials at all. It is based on Chinese Remainder Theorem. It can be easily explained if

nis a product of two different primes,pandq. In this case, each pointion a circle can be mapped to cell in ap×qtable. The available operations are: adding the same number to all values in a row, to all values in a column, or to all values in the whole table. Now, the solution is simple: use the first operation to turn all values in the first column into zeros. Then, use the second operation to turn all values in the first row into zeros. Now, the answer is`YES`

if and only if all values in the table are zero. When generalized to arbitraryn, the solution becomes more complicated, but the basic idea is the same.I did something very close to the geometry interpretation, but I still don't see a convincing argument on why this works. I took every polygon with

pvertices and ensured that the average value of the points on it equals to zero. When you do this for allp-polygons forpa prime dividingN, you either obtain all zeroes (which means that the answer is YES, and you also have a certificate for it), or not, and then the answer is NO.In the contest, I had certain intuition backed by stress tests (the approach is only prone to false negatives, hence is quite simple to check). But I failed to produce a rigorous proof both during and after the contest. Anyone has an idea?

I revisited this topic, finally understood the editorial and found the answer. The algorithm I used in the contest is indeed correct and I can prove it using statements from the editorial.

We imagine the circle as a polynomial of degree

n-- we take the exponents modulon. For instance, whenn= 5 thenx^{2}*x^{4}=x^{1}as .What does multiplying this polynomial by

x^{n / p}- 1 mean in terms of the statement? It means that you subtract (in parallel) from each elementa_{i}the elementa_{i - k}(and rotate everything byk, but that can be safely ignored).When you subtract arithmetic mean of

pevenly spaced points, this equals to multiplying byx^{ni / p}- 1 for alliin (0,p- 1), summing the results and dividing byp. We can safely ignore the case wherei= 0, as this yields all zeros.The above is equivalent to multiplying . Note that each term of this sum is divisible by

x^{n / p}- 1, thus the whole sum is too. The product of these polynomials for allpis for some polynomialsB_{p}(x) (let's call them bullshit).We have .

The above in words means the following: if a solution exists then after doing all the steps, all coefficients will be zero -- the condition is necessary!

Note that the reverse implication doesn't necessarily hold, because we are not testing divisibility by the "bullshit". However, the operations we've done are exactly the operations allowed in the statement (selecting some evenly spaced points and adding a constant) and they are reversible, hence we obtain a certificate for the result -- the condition is also sufficient.

I am sure no one reads this anymore, but I nevertheless wanted to share it, as I am happy that my approach was indeed correct and not some heuristic that I was just lucky to pass with (although it is still true that I didn't have a formal proof during the contest).

Could someone explain the first sample test for problem D?

If we choose (1, 4), (1), then expected value will be 1 × 0.4 (

for1) + 1 × 0.55(for4) + 2 ×ProbablityOfWinning(1) = 1.75. Probablity of winning of 1 is 0.4 × 0.55 × 1 + 0.4 × .45 × 1 = .4In the first sample, the optimal bracket is

So, the prediction is that teams 1 and 4 will win in the first round, and team 1 will win in the second round. In the first round, team 1 wins with 40% probability (0.4 expected score), and team 4 wins with 55% probability (0.55 expected score). If team 1 advances to the second round, it wins with 100% probability, so the overall probability that it wins the second round is 40% (0.8 expected score). The total expected score is 0.4+0.55+0.8=1.75.

Thanks!

Is'nt solution for D just bruteforces all possible combinations and then returns the best option ?

What's the complexity for algo from this post ?

You can't brute force since if we have 2^6 rounds, that means 64 teams, which is 64 factorial placements. Complexity of the algorithm is something like O(N^2*2^N) which is very reasonable with 2<=N<=6

I think I figured it out, thanks.

"Another way to probabilistically test if the center of gravity is at the center is to choose a random prime

psuch thatn|p- 1, [...]"Could you please explain how to find such a prime?

I tried generating random integers of the form

x*n+ 1 until I find a prime. It seems to be fast enough — in the worst case, for somenin range [1, 10^{6}], it required 123 attempts. Why does it work? In particular, I'm interested in answers to these questions:xfrom?Is there maybe a better/faster solution?

x(there are more primes among small numbers).Thanks a lot! That's exactly what I was looking for.

Commented Code for E That WAs on Case #8

Can someone explain what I did wrong and/or provide a countercase that shows the flaw?

When I was looking through other sols to see if I had the right idea, to my surprise, Petr's sol seemed quite similar to mine, except for the way that we computed the size of our components. Is there an error in that area of my code in particular?

EDIT: Now AC after changing the component size finding to a recursive DFS...

One liner for B

2*ceil(2*sqrt(n))

OEIS Minimal perimeter of polyomino with n square cells

Wow, I thought that this is just a joke problem, but it has turned out there is much more to it:

Where are the author's solutions. They should be there !!

In problem G, the alternate solution: I can prove that it's sufficient to check that the center of gravity is exactly the center for

allsuch m. But I don't see why it's sufficent to check just m=1 (as long as you have sufficient precision)?Can't it happen that the center of gravity is exactly the center, but it's not exactly the center if you rotate by some coprime m?

If we define P(x) as in the problem, then the condition in question is equivalent to the nth cyclotomic polynomial P_n(x) dividing P(x). Now, it can be shown that the minimal polynomial of a primitive nth root of unity w is the cyclotomic polynomial. https://en.wikipedia.org/wiki/Cyclotomic_polynomial What this means is that if P(w) = 0 for a polynomial P, then P_n(x) divides P(x). Moreover, this condition is necessary and sufficient. In complex numbers, the center of mass is P(w) over the total number of points. Therefore, the condition "center of mass at zero" is necessary and sufficient.

Can someone explain me how to solve Problem C with DP in detail? Thank you

i tried a bottom-up approach. my idea was: at i-th position let both of them decide individually whether they want the

pie[i]piece. but there is a catch. personAwill eat the i-th pie iff he/she is contented with personB'sdecision on giving himself/herself the total amount of pie till (i+1)-th position (from n). otherwise he/she will keep the token and let personBeat thepie[i]. letdp[i][j][k](1<=i<=n,0<=j<=2,0<=k<=2) define the total amount of pie eaten by the person k (from n) till i while j has the token at i-th position.Code If Needed

For problem E:

Many AC code outputs 2 for this case, but I think only the assignment [1,2,3,4,5] exists. What am I missing?

`[1, 3, 4, 5, 2]`

Its better to post this tutorial link on the home page blog. I thought the editorial is not yet published.

Isn't the formula wrong here? It's possible to get a p[r][t] such that it's over 100% Am I reading this incorrectly?

I have the following concern regarding the solution for Problem D. When we calculate the scores namely,

`s[r][t]`

, we first initiate`s[r][t] = s[r-1][t] + p[r][t] * 2^(r-1)`

Then we find the maximum s[r-1][u] for certain values of u. My concern is that we are choosing the maximum s[r-1][u], but we don't consider it p[r][t] side. I mean for probability we take the expectation. We're conditioning on playing against certain u, but we don't consider that condition while computing the score, namely`p[r][t] * 2^(r-1)`

. Could someone comment on this?Can you help me? I don't understand why my code for problem E fails on the test 26... Can anyone explain, please? http://codeforces.com/contest/859/submission/30549464

30392672

Can someone please explain what meet does? Why does it equal j xor k?

I know it'd be an overkill, but just wanted to know for knowledge purpose, is F solvable using min cost flow algorithm?

can someone explain the intuition behind the problem C