Very interesting contest.

But, how to solve task L, G and J?

Thanks in advance.

# | User | Rating |
---|---|---|

1 | Petr | 3325 |

2 | Um_nik | 3284 |

3 | Syloviaely | 3258 |

4 | tourist | 3206 |

5 | anta | 3106 |

6 | fateice | 3099 |

7 | mnbvmar | 3096 |

8 | OO0OOO00O0OOO0O0…O | 3083 |

9 | Radewoosh | 3076 |

10 | HYPERHYPERHYPERC…R | 3071 |

# | User | Contrib. |
---|---|---|

1 | tourist | 183 |

2 | rng_58 | 169 |

3 | csacademy | 163 |

4 | Petr | 158 |

5 | Swistakk | 152 |

5 | lewin | 152 |

7 | matthew99 | 146 |

8 | Errichto | 142 |

9 | Zlobober | 141 |

10 | adamant | 140 |

10 | BledDest | 140 |

Very interesting contest.

But, how to solve task L, G and J?

Thanks in advance.

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/21/2018 02:07:52 (d3).

Desktop version, switch to mobile version.

User lists

Name |
---|

L: For each color check all cells in its bounding box. It will work in

O(n^{3}), because if bounding box has dimensionswandh, then there should be at leastw+h- 1 cells of this color.J: Run 1 iteration of Boruvka's algorithm.

It seems that the tests are too weak.

An

O(n^{3}logn) solution with BIT can pass problem L and anO(mlogm) solution using Kruskal can pass problem J.I got

O(n^{3}log^{4}(n) accepted...That should be logarithm overflow.

I've got TLE with my O(n^3) solution :/

We solved problem L with O(N^3) complexity and got TLE!

Maybe someone can explain

Lmore verbosely? I can't understand neither aid nor witua's team explanations :(I didn't realized how to solve cases

like thisSuppose that

n=mfor simplicity.We want to prove that . We have that (as explained above), multiply both sides bynand obtain that .You can also approach it from the other end — instead of trying to find all boxes contained inside this box, you may try to find all boxes which contain given box.

Just pick any row which intersects with our box and check all colors presented in this row — there will be

O(n) of them, and clearly any valid box containing our box should have at least one cell in this row, because of connectivity.P.S. We had to optimize it a little bit

(like "let's only check boxes which have area larger or equal than area of our box")because initially it gave TL.I didn't realize there is an easy solution in L and solved it in

O(n^{2}) time similarly to this problemCan you please elaborate how you do it in

O(n^{2})? It's not clear to me even after reading the hackerrank editorial...For each component choose some point to be its' representative. Now consider some bounding box

b. Calculate amount of representatives inside it with prefix sums inO(1). Some components were added to the answer incorrectly, some components were not added to the answer, but should be. Both of them going through the border ofbso can be handled inO(h(b) +w(b)).Oh, so this is

O(n^{2})? That's what we did during the content, but we thought it isO(n^{3}). Actually makes sense, number of cells in a connected component is at least len(border) / 4, and I see a similar explanation in the thread-starting comment. Thanks!G: We can take size of each pile module A + B.

ProofIt's obviously correct when second player wins smaller game (make turn to the same pile as first player it's possible, or use his strategy in smaller game otherwise). First player makes first move as in smaller game and becomes second.

Only one player can make a move on the one pile, because size of pile < A + B. Then both players should always choose the biggest pile, so we can just iterate the process.

How to solve

The Most Expensive Gift?Our solution was to check all possible cycles of length <= 6. And it got

AC. I am not sure if it is right.At least one of the characters has to be present times. So we definitely have some subsequence with score . So checking all cycles up to 9 definitely works. We didn't reduce the bound any further as this was enough to pass.

Oh. Really easy proof!

Hm. One can proof why we can check all periods of length <= 9. Because due to the Dirichlet principle one letter will occur ≥

N/ 3 times. So, using one letter we can reach answerN^{2}/ 9.The numerator of the fraction is always < =

N^{2}, so to reach better answer, we should have smaller denominator. So, the length of the period shuld be < = 9.UPD: late

For example if S =

`("ab" + "c" * 5 + "ab") * 2`

, then`( length(ab) * count(ab) ) ^ 2 / length(ab) = ( 2 * 4 ) ^ 2 / 2 =`

32and`( length(abcccccab) * count(abcccccab) ) ^ 2 / length(abcccccab) = ( 9 * 2 ) ^ 2 / 9 =`

36Just take cycle = "

c". Answer will be 100You are right, then instead of 'ccccc' -> 'cdefg'.

You don't have

defgin your alphabet.Ah, ok. My bad. I haven't solved this problem and later forgot about a size of alphabet.

Actually, c<=6 is correct bound.

Let k be the number of times cycle of length c appears in the string. So its score is

c·k^{2}. On the other case some letter appears at least times. Solving inequality givesc≤ 6.Lost 20 minutes on

Ethinking why TC #4 is going to be correct but not Error :D But later realised that Error can be correct.How to solve I?

Count occurrences of

`"1"`

in each line and each row. Then go`up->down`

, and later`left->right`

, and try to cut pie. After you cut it into`n^2`

pieces, check every peace if it has exactly 1`"1"`

.(UPD: somehow Div.2

Iis not same as in Div.1 but corresponds to D)It seems we never need to take balls from three different boxes. Does anyone have a proof?

I’m not sure it’s ok, but I believe there is an equivalent problem, where after you get a ball, you remove all balls with the same color, and the game ends when there are some empty set of boxes which initially had at least 2 balls of some color. This is a state game, where the state is the mask of balls that you removed. And all the final states can be covered by states where you emptied one or two boxes (and possibly some other along the way, but they are irellevant). There is only one minimax path along this graph, and it will always end up in some state where you emptied one or two boxes. Now, supposing that you have infinite computing power and you find the optimal final state to converge to, you can then apply the strategy to only clear those boxes.

It should probably be

because it's possible there are no duplicates in boxes at all.

How to solve H? I got WA 41

How to solve C?

You may want to check out our short descriptions of the solutions.

Explain, please, how to participate Grand Prix of Ukraine ???

How can I upsolve the contest?

Where can I find the problemset?