wilcot's blog

By wilcot, history, 7 years ago,

Very interesting contest.

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

• +45

 » 7 years ago, # |   +21 L: For each color check all cells in its bounding box. It will work in O(n3), because if bounding box has dimensions w and h, then there should be at least w + h - 1 cells of this color.J: Run 1 iteration of Boruvka's algorithm.
•  » » 7 years ago, # ^ |   0 It seems that the tests are too weak.An O(n3logn) solution with BIT can pass problem L and an O(mlogm) solution using Kruskal can pass problem J.
•  » » » 7 years ago, # ^ |   0 I got O(n3log4(n) accepted...
•  » » » » 7 years ago, # ^ | ← Rev. 3 →   +79 That should be logarithm overflow.
•  » » » 7 years ago, # ^ |   +5 I've got TLE with my O(n^3) solution :/
•  » » 7 years ago, # ^ | ← Rev. 2 →   +10 We solved problem L with O(N^3) complexity and got TLE!
•  » » 7 years ago, # ^ | ← Rev. 2 →   0 Maybe someone can explain L more verbosely? I can't understand neither aid nor witua's team explanations :( I didn't realized how to solve cases like this 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 2 3 3 3 3 3 3 3 1 2 3 4 4 4 4 4 4 4 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 12 13 14 15 16 17 18 1 2 3 4 19 20 21 22 23 ... 1 2 3 4 2 3 4 3 4 4 
•  » » » 7 years ago, # ^ |   +6 Suppose that n = m for simplicity.We want to prove that . We have that (as explained above), multiply both sides by n and obtain that .
•  » » » 7 years ago, # ^ |   +5 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.
•  » » 7 years ago, # ^ |   +8 I didn't realize there is an easy solution in L and solved it in O(n2) time similarly to this problem
•  » » » 7 years ago, # ^ |   +5 Can you please elaborate how you do it in O(n2)? It's not clear to me even after reading the hackerrank editorial...
•  » » » » 7 years ago, # ^ |   +11 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 in O(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 of b so can be handled in O(h(b) + w(b)).
•  » » » » » 7 years ago, # ^ |   +11 Oh, so this is O(n2)? That's what we did during the content, but we thought it is O(n3). 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!
 » 7 years ago, # |   +13 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.
 » 7 years ago, # |   +11 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.
•  » » 7 years ago, # ^ |   +7 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.
•  » » » 7 years ago, # ^ |   +11 Oh. Really easy proof!
•  » » 7 years ago, # ^ | ← Rev. 2 →   +20 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 answer N2 / 9.The numerator of the fraction is always  <  = N2, so to reach better answer, we should have smaller denominator. So, the length of the period shuld be  <  = 9.UPD: late
•  » » 7 years ago, # ^ | ← Rev. 3 →   0 For example if S = ("ab" + "c" * 5 + "ab") * 2, then ( length(ab) * count(ab) ) ^ 2 / length(ab) = ( 2 * 4 ) ^ 2 / 2 = 32 and ( length(abcccccab) * count(abcccccab) ) ^ 2 / length(abcccccab) = ( 9 * 2 ) ^ 2 / 9 = 36
•  » » » 7 years ago, # ^ |   +5 Just take cycle = "c". Answer will be 100
•  » » » » 7 years ago, # ^ |   0 You are right, then instead of 'ccccc' -> 'cdefg'.
•  » » » » » 7 years ago, # ^ |   +11 You don't have defg in your alphabet.
•  » » » » » » 7 years ago, # ^ |   +5 Ah, ok. My bad. I haven't solved this problem and later forgot about a size of alphabet.
•  » » 7 years ago, # ^ | ← Rev. 2 →   +40 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·k2. On the other case some letter appears at least times. Solving inequality gives c ≤ 6.
 » 7 years ago, # |   -11 Lost 20 minutes on E thinking why TC #4 is going to be correct but not Error :D But later realised that Error can be correct.
 » 7 years ago, # |   0 How to solve I?
•  » » 7 years ago, # ^ | ← Rev. 3 →   0 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 I is not same as in Div.1 but corresponds to D)
•  » » 7 years ago, # ^ |   0 It seems we never need to take balls from three different boxes. Does anyone have a proof?
•  » » » 7 years ago, # ^ |   0 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.
•  » » » » 7 years ago, # ^ |   0 It should probably be ... when there are some empty set of boxes which ((initially had at least 2 balls of some color) or (we didn't get box from them yet)) because it's possible there are no duplicates in boxes at all.
 » 7 years ago, # |   0 How to solve H? I got WA 41
 » 7 years ago, # |   0 How to solve C?
 » 7 years ago, # |   +54 You may want to check out our short descriptions of the solutions.
 » 7 years ago, # |   +8 Explain, please, how to participate Grand Prix of Ukraine ???
 » 7 years ago, # |   0 How can I upsolve the contest?
 » 7 years ago, # |   0 Where can I find the problemset?