Блог пользователя cyand1317

Автор cyand1317, история, 7 лет назад, По-английски

Greetings!

Codeforces Round 418 (Div. 2) has just come to an end. This is my first round here, and hope you all enjoyed the contest! > <

Seems the statements still created a few issues :( Anyway hope you liked it, and the characters feature the Monogatari anime series. Let me state again that the statements has little to do with the actual plot — they're inspired by five theme songs actually — and I'm not spoiling anyone of the series! ^ ^

Sympathy for those failing system tests on B... This problem was intended to experience a lot of hacks but somehow there are not so many.

Here are the detailed solutions to the problems. Feel free to write in the comments if there's anything incorrect or unclear.

Tutorial is loading...
Solution 1
Solution 2
Tutorial is loading...
Solution 1
Solution 2 - Casework
Tutorial is loading...
Solution
Tutorial is loading...
Solution 1 - DP on trees
Solution 2 - Greedy

One more thing — Staying up late is bad for health.

Tutorial is loading...
Solution 1 - O(n^5)
Solution 2 - O(n^3) by KAN

This is the round with the most solutions so far perhaps? There are at least 3 × 2 × 3 × 3 × 3 = 162 different ways to pass all problems in this round =D

Pla-tinum happy though I'm supposed to be
Pla-tinum sad is somehow how I get

Personally I'd like to express my gratitude to the community for creating this amazing first-time experience for me. Thank you, and see you next round. Probably it will be for Ha... Well, let's wait and see :)

Cheers \(^ ^)/

Разбор задач Codeforces Round 418 (Div. 2)
  • Проголосовать: нравится
  • +222
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for fast editorial :)

Please fast rating update too :)

»
7 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

Bonus. Figure out why solution 2 is not hackable.
Because all permutations of b (maybe except sorted) is valid?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thank you for the great problems, especially problem C and D :)

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +30 Проголосовать: не нравится

    You have got 803 rating in one contest! This is the biggest change I have ever seen. LOL

    Translation: Is there any kind of operation like this? O(∩_∩)O

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +20 Проголосовать: не нравится

Problem E is awesome. I had a O(n^6) solution at the beginning and made it O(n^5) soon. Then I spent nearly an hour to optimize it. Finally I got a O(n^4) solution and the contest ended.

Anyway this problem is a really graceful dynamic programming problem in my opinion, which made me doubt whether I was solving problem in topcoder. Just an analogy, don't mind :)

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +15 Проголосовать: не нравится

    Agree.

    I also had an O(n^6) solution at the beginning, made it O(n^5) soon, but when I was writing the code I found that there's a useless dimension in my DP status, deleting it resulted in an O(n^4) solution...

    • »
      »
      »
      7 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

      What is the O(n^4) solution? I know an O(n^5) solution using DP state comprising of index, 2_left_in_last_level, 3_left_in_last_level, 2_left_in_current_level and 3_left_in_current_level.

      • »
        »
        »
        »
        7 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

        It can be seen that you have to connect exactly one point left in the last level if there has one. So you just need to keep the number of points in the last level. When the current level becomes the last level, calculate the number of ways of these points connect to some points on the right (but we don't care about what these points are), which is actually equal to the number of permutation with repetition.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +28 Проголосовать: не нравится

        2_left_in_last_level and 3_left_in_last_level can be merged: remain_degrees_in_last_level = (2_left_in_last_level + 2 * 3_left_in_last_level).

        In the O(n^5) solution, we multiply the answer by (2_left_in_last_level) and then decrease (2_left_in_last_level) by 1 if we choose a vertex with 1 remaining degree in last level, or multiply the answer by (3_left_in_last_level) and then decrease (3_left_in_last_level) by 1 and increase (2_left_in_last_level) by 1 if we choose a vertex with 2 remaining degrees in last level.

        In fact we can precalculate the number to be multiplied when we change the level: (remain_degrees_in_last_level)! / 2^(3_left_in_last_level). (can be proved with combination knowledge)

        In the O(n^4) solution, we just merge 2_left_in_last_level and 3_left_in_last_level into remain_degrees_in_last_level, and multiply the answer by (remain_degrees_in_last_level)! / 2^(3_left_in_last_level) when we change the level, no longer caring whether to choose a vertex with 1 or 2 remaining degree(s) in last level.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      You did a good job :)

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +18 Проголосовать: не нравится

    Thanks for your appreciation! What a pity you didn't make it > <

    Actually O(n5) is one of the intended solutions, if implemented with a constant factor of 1 / 8 or lower. I also feel this problem quite TC-ish myself.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      But I think memory limit is too tight for n^5 solution.

      I got dp[2][2*N][2*N][N][N] and passed with 247MB.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Yes, perhaps the ML should have been larger in order to let all O(n5) solutions pass easily. But you can try some different DP that would use an f[2][N][N][N][N] array.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +25 Проголосовать: не нравится

    If it's Topcoder, you won't come up with a polynomial-time algorithm at the beginning. lol

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you tell me how I can improve my dynamic programming skills ? I had no idea how to approach that problem at all.

    Thanks.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

why is my solution got TLE ?

cyand1317

27649598

same complexity passed with many others

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

anyone who completed problem c in java ?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    with python3 i can not make less than 5.5s :(

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Yeah you can do some precomputation and solve all cases before you take in queries (there are only n*26 different cases) and then just print out the queries as you get them. Ran in less than 500ms.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone please explain the solution for Problem — C.I am not able to understand the editorial.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Which particular part of it? Perhaps I can make it clearer.

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

    Clearly, given a color c and a number of repaints m you could bash through all possible intervals and find the maximum valid substring, but this would take too long, with n(n+1)/2 possible intervals and q queries, taking O(n^2*q) time.

    We can resolve this issue as there are 26n possible queries (as there are 26 letters in the alphabet and m is constrained to [1,n]. Therefore we run through every possible query and store its answer in an array Ans[c][m]. (this takes O(n^2*26) time)

    To run through every possible query we look at every possible color and every single possible subinterval, and find the minimum number of recolors needed to make that interval valid. We compare the size of this interval to the size currently stored in Ans[c][r-l+1-t], and store the maximum of the two.

    However, this only finds the maximum value when exactly m colors are recolored, but in some cases not all m colors need to be recolored, for example take string axaxa for favorite color a, a maximum of 2 recolors will be needed even if we have more than 2 recolors available. Therefore, for each color we iterate through [1,m] and if Ans[c][j] is less than Ans[c][j-1], we replace Ans[c][j] with Ans[c][j-1]. Using the above example, Ans[a][2] would = 5 while Ans[a][3] would = 0, and so we set Ans[a][3] to 5. (Restating what I said above: the maximum vaild substring given a number of recolors m is equal to the maximum valid substring that can be obtained by any number p such that 1<=p<=m. We originally only found answers which used exactly m recolors.)

    Then we handle each query by using this 2-D array as the solutions are precomputed.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Problem C. Got TLE with O(nq) solution. Any idea how to fix it? http://codeforces.com/contest/814/submission/27651582

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Try adding the following code lines:

    int main( ) { 
      ios_base::sync_with_stdio( 0 );
      cin.tie( 0 );
    
      // Your code here
    
    }
    

    I think that you got TLE because the input file is too large and cin/cout is a little bit slow without the lines above.

»
7 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Bonus for C in O(nq) can be easily done using two pointers (sliding window).

Spoiler

Check my submission for better understanding. Code

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I have the same solution and interesting in if there is a guarantee about working less than 2 seconds ? I was hoping only on power of computers of the verification system. As I know, approximate number of actions per second about 100 millions. So, we have O(n * q) ~ 300 millions actions and only 2 seconds.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +7 Проголосовать: не нравится

      Though the solution with complexity O(n * q) passes, you can still optimize that solution. As m <  = 1500, the total number of unique queries can be 26 * 1500(as there can be 26 different alphabets for each m). Hence the queries in the input will repeat. So you can save the answers for the queries as you encounter them, and if that query is repeated again, you can simply print it directly without solving again. You can do this by maintaining an array dp[27][1510]. Here are my submissions with and without this optimization.

      Submission 1: 27657218

      Submission 2: 27657190

      There is a huge difference in time.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I think it's similar to O(n^2 * 26 + q) as I understand, but I'm interesting in if there are some guaratees without optomization.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I did C using Binary Search on the answer and checking whether for the particular value of answer is it possible to paint a subsegment by combining it with the sliding window. Code

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can't understand the description of E. Must the graph be a tree?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    No, the second sample itself is not a tree. But if you construct the shortest path graph, that will be a tree because there is a unique shortest-path from every vertex to the capital. Apart from these edges of the tree, edges can be present between siblings nodes in the tree.

»
7 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Could someone explain me a solution of problem D, please.

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    I solved D with Dynamic programming(memoization): D[1111][2][2][2]: D[node][|set1|_is_odd?][|set2|_is_odd?][node_belogs_to_set2?]

    Then the core part becomes

    D[node][odd1][odd2][at_odd2] = (odd1 && !at_odd2) || (odd2 && at_odd2) ? area[node]: -area[node] + get_optimal_combination(direct_children[node])

    Here, direct_children consists of literally indices of direct children, which means, for each y in direct_children[node], there is no other circle smaller than node which is parent of y.

    And get_optimal_combination is simple, too: this is just a sum of max(D[child][!odd1][odd2][false], D[child][odd1][!odd2][true]); (this is obvious so that I will omit the proof).

    Code here: http://codeforces.com/contest/814/submission/27661135

    P.S. I think this problem can solved using plain DFS without DP.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    If we define the level of a circle as the number of circles that completely enclose it, then for any circle, its effective area can be seen as sum of all the even levels minus the sum of all the odd levels. My solution was to move to the second plane all circles whose level is 1, that is, all the circles that have exactly one circle enclosing them. It's pretty easy to see why this works, but let me know if you need a proof. 27655767

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

In test case 6 of problem B:
10

1 2 3 4 5 6 7 8 4 10

1 2 3 4 5 6 7 6 9 10


my output is :

1 2 3 4 5 6 7 6 4 10

Jury's answer was :

1 2 3 4 5 6 7 8 9 10

But the problem says,it satisfies any permutations maintaing (n-1) matches..I can't find any errors with my output.It would be very helpful if someone helps me with my confusion.Thanks in advance.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    @TajirHas9 the answer should be a permutation of 1,2,3....n .Read the problem statement again!

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you very much.I noticed that now.I thought any permutation is acceptable.But problem statement says 1 to n inclusive indeed. :(

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I can't understand how spaciousness is defined in problem D?Is it unique for given set of circles.How are those odd ranges chosen?P

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    The spaciousness is the total area that is covered by an odd number of dancers. So, for example, if a region is covered by only one dancer, this region is included in the computation of total spaciousness, if a region is covered by exactly two dancers, it is not.

    Your goal in the problem is to maximize the total spaciousness by allocating some dancers to dance only after midnight and some to dance only before midnight.

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

c problem .....in the editorial code->what is the use of this loop:-

for (int i = 1; i < MAXN; ++i)
            ans[c][i] = std::max(ans[c][i], ans[c][i &mdash; 1]);
  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    isn't for (int i = 1; i < MAXN; ++i) ans[c][i] = std::max(ans[c][i], ans[c][i - 1]);

  • »
    »
    7 лет назад, # ^ |
    Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

    The mean of ans[c][i] : the best ans when exactly change i times.

    You can not change so many times with string : aaaaaaaaa and query 4 a

    So that you should get a prefix max。

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I don't understand what is this "26" in the editorial of problem C

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    You have to precompute for each possible color, and there are 26 alphabets so 26 possible colors.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Can anybody explain how the tree structure in problem D can be built in O(n log n) ?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +33 Проголосовать: не нравится

    Using BST and scanning line.

    First we divide each circle into two arcs,the upper one and the lower one.Then process all arcs from left to right,inserting and deleting arcs in the BST.

    In the BST we sort the arc by vertical order.(As no circles intersect,each pair of arcs can be compared vertically).

    When we insert an upper arc,we can find the closest arc which is on top of it. If the closest arc which is on top of it is an upper arc,then the closest arc is the parent of the arc being inserted.Otherwise,we find a lower arc or no arc at all.If no arc at all,the arc being inserted can't be contained by any other circle.If a lower arc is found,this lower arc should have the same parent as the arc being inserted.

    There're some computational geomatry problems employing this technique in Chinese OI.

    Poor English,a better explanation is needed.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Ah ha~~~ What do you mean by using 'Let's wait and see." ~ ^_^

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is problem C a form of a classic DP problem??

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    I think it's quite classic. It's not DP but preprocessing + sliding-window method actually, though the memorizations are a bit alike.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      can you tell me the name of the classical problem which is similar to that problem??

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I mean, this technique is similar to DP, though it isn't. There are quite a few DP problems on strings out there but I can't think of one right now. Perhaps someone else might help.

      • »
        »
        »
        »
        7 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        I think the most classical idea in this problem is "noticing" you are dealing with an alphabet with 26 letters, so you can preprocess individually. Exploring this idea is useful for a handful of problems that have different approaches. Even tries would not have the same complexity if your alphabet was greater. You could find a longest non decreasing subsequence of characters in O(26*n), as another example.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I couldn't understand DP on trees for problem D.Can someone explain a bit more on that DP part?

Thanks in advance and sorry if the question seemed to be trivial.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

how could u construct the tree for D in ?

particularly plz specific how to deal with two circles tangent with each other.

coz i used sweepline + set which leads to Wrong answer on 4 >.<

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I the same WA on testcase 6

    • »
      »
      »
      7 лет назад, # ^ |
      Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

      wa on case 6 may be the wrong idea with dp >>

      what i did is for each i's son

      but it is wrong, we should count his brothers in

      which should be

      and then

      hmm, exactly the same as the solution.

      • »
        »
        »
        »
        7 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        Thank U all the same though I use greedy algorithm... I was considering that methods discussed above by liu_runda is too complicated Maybe we could only deal with upper arcs (Keep trying...

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          ah okay, for that one, u can draw two graphs, if the one with shorter distance to it is upper arcs, the current circle we are looking at, is contained by the circle which the particular upper arcs belongs to.On the other hand, if it is a lower arcs, they must have the same situation, which means they are brothers.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I don't understand the formular f[u][0/1][0/1] of D's solution. What does it mean?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    Let F[u][isOddGroup1][isOddGroup2] be the best sum for distributing the circles between first group and second group optimally, so you can either make the circle u in the first group or the second group, and either sum or subtract the circle u area according to the parameters isOddGroup1 and isOddGroup2 respectively.

  • »
    »
    7 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

    f[u][p1][p2] is the maximum total answer in the subtree of u, assuming there are p1 nodes assigned to the first group and p2 nodes assigned to the second group among u's ancestors. And we only need to care about the oddness/evenness of p1 and p2 so we store them modulo 2.

    Edit: Seems I was a bit too slow XD

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      For a node u, we look at its ancestor, that's clear. What's not clear is why we use u's subtree to calculate f instead of its ancestors. The provided solution does exactly that, doesn't it?

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

        In the editorial, p1 and p2 are kind of assumed. So f means "what's the best we can get in the subtree, if the ancestors are in this state." We calculate this value bottom-up, and u's value will be used by its parent.

        Other approaches may not use ideas like this, though.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can any one guide me how to do Problem c with top down dp approach.I have written the recursive implementation but i am unable to memoize ,that's why i am getting tle.Thanks in Advance.

Here is my solution link

»
7 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

In problem E, why can't we club p1 and p2, and club c1 and c2, and have dp[u][p1 + 2*p2][c1 + 2*c2], which denotes number of ways to build the graph with the first u vertices, with (p1 + 2*p2) plugs in the previous level, and (c1 + 2*c2) in the current one?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

why title of C and E is not English?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hello,

what do we mean by Figure out why solution 2 is not hackable.

what is the meaning of hackable and why is not hackable.

is the solution 1 hackable?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +16 Проголосовать: не нравится

    Solution 2 seems to have a complexity of O(k!*n). (though it's O(n+k) indeed)

    Both solution 1 and 2 are correct (not hackable).

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Can you please explain the general idea of the second solution?

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        This problem asks us to "detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing".

        The second solution is just a simple idea: to try every way to "replace each zero in a with an integer from b so that each integer from b is used exactly once", and then check if "the resulting sequence is not increasing".

        As this comment said, "all permutations of b (maybe except sorted) is valid". So the O(k!) loop will break; in O(1).

»
7 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

In problem D I can't understand this statement " consider a vertex u, and the parity (oddness/evenness) of number of nodes in its ancestors from the first and the second group."

in this matrix f[u][0/1][0/1] what represent the second and the third dimension I didn't get it

thank you in advance

»
7 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

You can solve D with pure DFS, no DP needed.

for every tree, Add the root to the first group, and the the children of the root to the second group , so answer = Area of Root + Area of each of the root's children, after that either add the area of the current circle to the total answer if the depth is even , or subtract the area if the depth is odd.

This works because, if The maximum depth of the tree is 2, it is optimal to put the root on one side and the root's children on the other side,then you simply add all the areas to the final answer,but if you add another smaller circle into the plane, you increase the depth by one so this new circle area will definitely get subtracted if put on any side,we solve this by adding its children(which have depth4) inside it(to decrease the loss of area),then same goes for circle of depth 5 and its children.

http://codeforces.com/contest/814/submission/27689113

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

Can you explain for me how to dp array WAYS of solution n ^ 3 in problems E.

I don't understand how it work and remarks in code such as // 2-0, 2-0 // 2-2, 2-0 .... etc !

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    Just a rough idea for understanding the sample solution: consider what happens when we add edges among vertices of the same level (with c1 "1-plug" vertices and c2 "2-plug" ones), and from a vertex in that level to a vertex in a new level (with c0 vertices). "Plugs" of certain vertices will decrease (some "2-plug" vertices become "1-plug" for example), depending on the edges we choose.

    We take a vertex and consider how they're connected to other vertices. The comments are in the form of "(the vertex we're currently considering) — (the vertex it's connected to)". e.g. "2-1, 2-0" means we take a "2-plug" vertex and connect it to a "1-plug" vertex in its own level and a vertex in the new level (denoted by 0). We can choose different vertices of the same "plugs" to connect to, so previous DP values are multiplied by number of such ways, like .

»
7 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Can someone explain their greedy solutions for D with proof of correctness ?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    The comment above by Kareem_Mohamed is a common one FYI (basically it's explaining exactly Solution 2 in the tutorial, I don't know why it's downvoted :/). I've seen a few approaches equivalent to this, but I'm also curious whether someone came up with other insights and ended up in the same solution.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Above all thanks for the great DP round. XD

Here is one question. For problem E's sample O(n3) solution, there is a part of constructing from subproblem which says

"if (c2 > 2) add(ways[c0][c1][c2], (ll)ways[c0][c1 + 2][c2 — 3] * ((c2 — 1) * (c2 — 2) / 2)); // 2-2, 2-2"

As c1, c2, c0 are all limited under 50. How can we guarantee we always have future information [c1 + 2] when we need to calculate f[c0][c1][c2]? For example, when calculating f[1][49][30], we don't have the memo of f[1][51][27] cause c1 is larger than 50.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    For indices larger than 50 the corresponding DP values are all 0 due to implicit array initialization. And note that DP values are calculated in c0-c2-c1 order so we can be sure the values we need at some time are all calculated before.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Well, I got this one, thank you!

      Would you pls give me a hint on how to set the initial value for ans[n][n — 1] = 1. Is there any physical meaning for this?

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        There is one way to build a graph with vertices numbered between n and n - 1 — "no vertices", and "no vertices" form the first level, that is, zero edges from the previous level need to be connected to it.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

cyand1317 could you explain the dp states in D?

For a node u, does f[u][0][0] mean that u belongs to the first group and has depth%2 = 0?

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I got an easy greedy solution for Problem D. Pretty straight forward 20 (actual) lines of code.

Submission

Basically take circles in decreasing order of radius. Find its immediate encompassing-circle. Then depending on the "tag" of that parent-circle, assign the "tag" for the current circle. Then add certain values of "tags".

Essentially I skipped the trees. And Dfs.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I'm having trouble understanding the problem D and it's example test cases. what does the area covered by an odd number of movement ranges of dancers who are moving. actually mean? how exactly is spaciousness calculated??

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How would you do the bonus for problem D?