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

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

We will hold AtCoder Beginner Contest 160.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +97
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -22 Проголосовать: не нравится

So why was the discuss about AtCoder written here?amazing!

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

Hope to get a good result!

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

Another Contest in Home quarantine :D

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

C001_scrambled for first test case. I am participating here for the first time. It throws RE.Can somebody help with the reason??

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

Either this is not one of my good days of programming or I don't know, i ussually do ABCD and now i can't do C

»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится -47 Проголосовать: не нравится

Edit: Please Ignore. I didn't realize the contest was still going on.

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

Very First time I solved Problem E myself in single attempt,Nice Contest! thanks for good contest

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

Anyone please explain solution to problem F.

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

    The base of the idea is like this.

    Let's suppose there are two edges connecting node (x,y) and node (x,z) and the node x is root. And let's define the number of the nodes belonging to the y-rooted subtree(subtree whose root node is y), as A, and the number of the nodes belonging to the z-rooted subtree, as B.

    Now we can count the number of the ways in which writing 1 on vertex y(or z) and writing each of the numbers 2 ~ A(or B) on the nodes of the y(or z)-rooted subtree. Let's define this number as C, D each.

    In short, the number of ways writing A numbers on the nodes of y-rooted tree is C, and the number of ways writing B numbers on the nodes of z-rooted tree is D.

    In this case, the number of ways writing (A+B+1) numbers on y-rooted tree, z-rooted tree, and the node x is C*D*(A+B)!/A!/B!(It contains combination).

    Sorry for many definition.

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

    First: answer for given root is: $$$\frac{n!}{s_1s_2\ldots s_n}$$$, where $$$s_i$$$ is size of subtree rooted at $$$i$$$. Why? Because a permutation is valid iff value at any node is less than any other value in its subtree, probability of this holding for specific node $$$i$$$ is $$$\frac{1}{s_i}$$$ and those are all independent.

    Now run dfs from one fixed root and calculate for each vertex size of its subtree. For any vertex $$$v$$$ except for the root let's consider two parts of the tree splits to when edge between $$$v$$$ and its parent. If the root is inside $$$v$$$ subtree size of upper subtree with size $$$n - s_i$$$ will be included in calculating the result, otherwise lower subtree with $$$s_i$$$ will. Thus for each such node we want to multiply all answers in its subtree by $$$\frac{1}{n - s_i}$$$. The latter is equivalent to multiplying all values by $$$\frac{1}{n - s_i}$$$, and those in $$$v$$$ subtrees by $$$n - s_i$$$. To perform sequence of operations: multiply all values in a subtree by $$$x$$$, and at the end extract value from each node we can just: whenever we multiply all values in a subtree multiply the value at its root only, and at the end use basic dfs to calculate for each vertex product of values on path from root to this vertex.

    EDIT: to be precise: the formula I described includes dividing by size of root's subtree, while the solution divides by all except for the root. Thus we need to divide answer for all vertices $$$n$$$.

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

Can anyone explain C problem statement was not clear to me ?

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

    You have N cities around this lake and you can traverse it clockwise or anti-clockwise. You have to pass through every city and total distance travelled is sum of distances between every two cities in your path.

    In second sample, one city is in position 0 degrees ("north of the lake") and the last is in position 15. If you walked anti-clockwise (array is circular, remember), you could go from the 0-th city to the 2-th in 5 degress, because $$$(0 - 15) \ mod \ 20 = 5$$$.

    Solution.

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

How to solve F? I can't even get close to a bruteforce solution of O(n*n).

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

    The O(N^2) solution is as follows:

    Root the tree at k. Now, we observe that this problem bijects to listing nodes in order such that all parents appear before their children. Let the number of ways to order nodes in the subtree of v be s[v]. We observe that through combinatorics, s[v] is the product of s[i] for all i that are children of v, multiplied by (stsize[v] — 1)!, divided by the product of s[i]!. The part with the factorials corresponds to the number of ways to order the different subtrees relative to each other. Thus, this can be solved in O(N) per root if we precompute the factorials and the multiplicative inverses.

    To speed up to O(N logN), a further idea is needed. (Hint: consider how to reroot the tree.)

    Edit: divide by the product of stsize[i], not s[i]. I'm a bit of an idiot...

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

      $$$O(n log n)$$$? Why. It can be quite easily in $$$O(n)$$$. I guess your $$$O(n log n)$$$ uses some data structure like HLD, which is way more harder to implement than simple DFS.

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

      Could you please explain in a bit more detail s[v] is the product of s[i] for all i that are children of v, multiplied by (stsize[v] — 1)!, divided by the product of s[i]! ?

      I understand that $$$(stsize[v] — 1)!$$$ will give us permutations of relative subtrees, but doesn't it also count permutation of relative subtrees of different depths? Wouldn't that count bad permutations?

      Thanks

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

        That's why we divide by the product of s[i]!, to avoid further permuting the already permuted subtrees.

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

          So shouldn't it be divide by product of stsize[i]!? Still, I can't see how that works ;_;. I understand the solution and I managed to code the rerooting thing and get AC, but I don't understand the DP recurrence =(

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

            Yeah it's stsize[i]... I made a small mistake in the explanation. Thanks for pointing it out!

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

            can you explain the rerooting solution

            thanks

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

              Yea sure.

              You calculate $$$dp$$$ for one root (let's say 1). Then you do a DFS and each time you're going from node $$$u$$$ to node $$$v$$$, you want to reroot this tree, making $$$v$$$ its new root. So think like you're basically "rotating" this tree.

              So at first, you'll know that $$$ans[1] = dp[1]$$$, because you calculated $$$dp$$$ rooted at 1.

              So what changes? To calculate $$$dp[u]$$$, we use size of subtree rooted on $$$u$$$ and the size of all subtrees of its childs.

              So now $$$v$$$ is no longer a child of $$$u$$$, then $$$dp[u]$$$ will have to get rid of all of it's dependencies of $$$v$$$.

              Since

              $$$ dp[u] = (size[u]-1)! * (\frac{dp[v1]}{size[v1]!} . \frac{dp[v2]}{size[v2]!} . \ ...) $$$

              Then we have to multiply $$$dp[u]$$$ by $$$size[v]!$$$.

              Additionally, $$$size[u]$$$ will change because $$$v$$$ is not a child of $$$u$$$ anymore, so $$$size[u] = size[u] - size[v]$$$. But that means that our $$$dp$$$ changes too, so you'll have to divide $$$dp[u]$$$ by $$$(size[u] - 1)!$$$, recalculate $$$size[u]$$$ and multiply it again by $$$(size[u] - 1)!$$$

              These changes apply to $$$dp[v]$$$ too! Now $$$u$$$ is a child of $$$v$$$, so $$$size[v]$$$ increases by (the old) $$$size[u]$$$ and you have to recalculate $$$dp[v]$$$.

              This makes MUCH more sense if you draw it on your notebook.

              After recalculating $$$dp[u]$$$ and $$$dp[v]$$$, $$$ans[v] = dp[v]$$$, you call dfs recursively to child $$$v$$$ (now it's as if you didn't do any rerooting and you had just calculated everything rooted at $$$v$$$).

              After the recursive calls end (you're back at node $$$u$$$, you restore $$$dp[u]$$$, $$$dp[v]$$$, $$$size[u]$$$ and $$$size[v]$$$. You can do this part in a smart way or just use some auxiliary variables.

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

          OOOOO! Maybe I got it!

          Out of $$$size[v]!$$$ possible permutations for a child v of u, we have $$$dp[v]$$$ good ones. That means that there's a $$$\frac{dp[v]}{size[v]!}$$$ probability for a permutation to be good.

          So let $$$vi$$$ be the $$$i$$$-th child of $$$u$$$.

          So out of a total of $$$(size[u]-1)!$$$ possible permutations for ALL children of $$$u$$$, we have a probability of $$$\frac{dp[v1]}{size[v1]!}$$$ of it being a good permutation from subtree of child 1, $$$\frac{dp[v2]}{size[v2]!}$$$ of it being a good permutation from subtree of child 2 and so on.

          So

          $$$ dp[u] = (size[u]-1)! * (\frac{dp[v1]}{size[v1]!} . \frac{dp[v2]}{size[v2]!} . \ ...) $$$
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I tried to implement E with given ordering of the apples, noticed a minute before end that it would be more wise to reorder them by deliciousness.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +39 Проголосовать: не нравится

I am just going to leave this here.

Problem F

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

    At atcoder, it's kind of difficult to have new questions (at least in beginner contests)

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

    Can you explain DP formula there? I can't get it...

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

      I didn't read the editorial however here is my solution.

      I am also too lazy to write any formulas but here is my solution.

      Let's assume that the tree is rooted so i need to calculate the number of topological sortings for this tree beginning at node 1 now let's assume that node $$$X$$$ has 1 child then $$$dp[X] = dp[child]$$$ i.e just append $$$X$$$ on the topological sorting of it's child. However in case $$$X$$$ has 2 children this means I have 2 arrays and I want to find the number of ways to merge them into one array such that the order of each array still stands meaning the $$$i-th$$$ number comes before the $$$(i+1)-th$$$ number array-wise, this can be done using stars and bars. this way I can merge any topological sorting with the current topolgical sorting of all previous children.

      After calculating $$$dp[X]$$$ for each node we calculate $$$dp2[X]$$$ for each node which is the answer for all the tree excluding the subtree rooted at $$$X$$$ this part should be pretty standard. then merge $$$dp[X]$$$ with $$$dp2[X]$$$ using stars and bars.

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

        can you provide code?

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

      Suppose you have a rooted tree with $$$1$$$ as the root. Let $$$dp[x]$$$ equal the number of ways to distribute $$$|x|$$$ consecutive values on the subtree rooted at $$$x$$$, with the lowest value assigned to $$$x$$$. Then for leaves this equals 1, and we want $$$dp[1]$$$. If node $$$r$$$ has $$$k$$$ children $$$n_1,\ldots,n_k$$$, then think about first putting the lowest value at $$$r$$$, and then distributing the remaining $$$|r|-1$$$ values on the subtrees. A way to do this is to distribute values on each individual subtrees, and then "interleaving" these distributions. So you get the product $$$dp[n_1]dp[n_2]\cdots dp[n_k]$$$ times multinomial coefficient $$$C(|r|-1,[|n_1|,|n_2|,\ldots,|n_k|])$$$, where the multinomial coefficient gives the number of ways to interleave the distributions from different subtrees.

      Then for other roots, use re-rooting.

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

    Damn, makes me miss CSAcademy: this kind of short statement problem was like lots of their other good quality problems :'(

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

Why this doesnt work ? https://atcoder.jp/contests/abc160/submissions/11310758

Insert all elements in a vector and sort.

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

    Because coloring all the colorless apples red, before coloring any of them green is not always optimal.

    Ex.:

    2 1 2 2 2
    2 2
    1 1
    10 10
    

    The answer is 22, but your code gives 21.

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

    I didn't go through your whole code, but here is what I did.

    1. First sort A, B, C array in descending order.
    2. Make a new array(Let it be F) by taking the first X and first Y of B.
    3. Sort the new array F in descending order.
    4. Now try replacing the smallest element of F by the largest element of C.
    5. Do it until Del(Ci) — Del(Fj) > 0.(Why? Because If we replace now, our sum will decrease).

    Here is my simple implementation: Submission

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

    When you use a colorless apple you must decide which color it has to become based on which color has the worst apple who was being eaten before coloring this one(because that's the one you want to discard). If you mix all the apples you don't get to choose by this criteria and fail to reach maximum value.

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

What is an idea in task F? I don't get it? How to count it?

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

Where will the editorials to the problems be posted ? Somewhere on Atcoder site or on codeforces ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Man, the re-rooting in F was tough. :(

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

For problem F, I think I can use dp to get the answer for $$$numberofways(root)$$$, for an assignment starting with "1" at some fixed root. The expression has a multinomial coefficient so worst case has a $$$\log n$$$ factor, for a total of $$$O(n\log n)$$$. Then I think the answer for a node adjacent to root can be obtained from the above answer, by changing some individual factors. It seems the total number of such changes as I change from node to node will equal the sum of degrees, so the answer should stay $$$O(n\log n)$$$. Can someone who solved it tell me if this is a good approach because I feel like it would take too long to implement.

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

can somebody tell me which topics are used in d and e

»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится +10 Проголосовать: не нравится

Brief Solutions:

  1. Simple check ---- O(1)

  2. The answer will 1000*(n/500)+5*((n%500)/5) ---- O(1)

  3. For every starting position i, the distance will be a[n-1]-a[i]+(i-1>=0?(k-a[n-1])+a[i-1]:0). Then take the minimum for all i — O(n)

  4. Form a graph, and then run bfs starting from each node. Then count the nodes at a distance k for every k. Since, every pair (i, j) appears twice, divide the answer by 2. Perhaps there exists a O(n) someone can explain. — O(n^2)

  5. First sort set A, B, C. Greedily take top x apples from set A, top y apples from set B and then atmost top (x+y) apples from set C. Sort them and take the top (x+y). — O(AlogA+BlogB+cLogC+(x+y)log(x+y))

  6. I couldn't solve myself :(

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

Can someone explain a O(n) solution for D? I think there exists a linear time solution.

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

Time to go to Codechef, #Quarantine

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

The editorial says there there is an O(N) solution for F.

However, if I am not mistaken, the computation of multiplicative inverse is needed, which is O(logN). Thus, shouldn't it be O(N logN) overall?

Edit: oops, I meant logM. Thanks to ahshafi for pointing out my mistake!

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

Why this approach doesn't work for D ( I got 5 WA )

for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                int distance_direct_path = j - i, distance_bridge_path = abs(x - i) + abs(y - j) + 1;
                ans[min(distance_bridge_path, distance_direct_path)]++;
                if (distance_direct_path == distance_bridge_path)
                    ans[distance_direct_path]++;
            }
}
»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +2 Проголосовать: не нравится

Brief soln
A : Do it.

B : Greedy.

C : perimeter — longest interval length.

D : There might be more efficient ways, but for this problem size of input ($$$n = 2,000$$$) is small enough to run $$$n$$$ BFS and just add everything. This gives $$$O(n^2)$$$ algorithm.

E : Take $$$X$$$ best red and $$$Y$$$ best green. Now, from these, we can replace some of these to colorless ones to get better result. while we can improve (smallest in bag < largest colorless out of bag), we improve greedily. If we look at colorless one from biggest to smallest, we can easily maintain with priority queue. Code is easier than explaining. https://atcoder.jp/contests/abc160/submissions/11286026

F : We root the tree at 1 and solve for 1. Note that what we compute is actually number of permutations which does not violate order of tree. Consider some statement like this. If a subtree rooted at node 5 has (5, 6, 7, 8, 9), in the final permutation, 5 must be the first of subsequence (5, 6, 7, 8, 9) where order of 6,7,8,9 does not matter. If we throw any permutation at random, we have 1/5 chance sufficing this criterion. Observe that sufficing one statement does not change probability of sufficing another, so we compute answer for 1.
By DFS, we can compute $$$f(a, b)$$$ where $$$a$$$ is parent of $$$b$$$, $$$f(a, b)$$$ = number of nodes in subtree rooted at $$$b$$$. With this notation, we can write the answer above as $$$n!$$$ divided by some product of $$$f$$$s. When we change root to something adjacent of current node, note that exactly 2 edge changes it's 'direction'. We can compute all values in $$$O(n)$$$ dfs calls, but I implemented $$$f$$$ function with map so my solution is $$$O(n \log n)$$$. https://atcoder.jp/contests/abc160/submissions/11298787

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

    I think there is another O(n^2) solution not using BFS in problem D. We can figure out the shortest path from vertex A to vertex B (A<B) is among two cases: [A — B](the length of this path is B-A), [A — X — Y — B](the length of this path is abs(A-X)+abs(B-Y)+1). For each pair we can just compare these two numbers and find the length of the shortest path.

»
6 лет назад, скрыть # |
Rev. 5  
Проголосовать: нравится +4 Проголосовать: не нравится

So here's how I solved F(got AC just after contest has ended) :(

Let as solve for a specific node x as root which has p children:

Let it's children be x1,x2,x3...,xp respectively. Let their subtree sizes be s1,s2,....sp respectively.

Obviously we have to distribute s1 numbers to subtree rooted at x1, s2 numbers to subtree rooted at x2,..... , sp numbers to subtree rooted at xp.

Thus we have the following recursive solution: solve(x)=solve(x1)*solve(x2)*....*solve(xp)* (NUMBER OF WAYS TO DISTRIBUTE n-1 NUMBERS TO SETS OF s1,s2,....,sp).

The last value is a simple combinatorics problem which is equal to (n-1)!/(s1! * s2! *....sp!).

The factorials can be precomputed and thus we can get the value for a particular root in O(n * log(n) ) time. (log term for doing modular inverse of factorials).

The values for remaining nodes can be found by re-rooting technique.

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

How to solve D?

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

    You can calculate the distance for every pair of nodes in the graph with N BFS (for every node). After that, you will have a matrix dist of distances, where position [i][j] represents the distance from i to j.

    Then, you just count the number of times the k-th distance appears above the main diagonal of the matrix.

    vector<int> counter(n);
    
    for(int i=0; i<n; i++)
            for(int j=i+1; j<n; j++)
                counter[dist[i][j]]++;
    

    This solution is O(N²), which is enough for the restrictions.

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

So,How to slove the problem F?

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

so,how to solve the problem F?post

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Could anyone please link more problems like problem F (tree dp, rerooting)? Or could you please tell me where to find similar problems?

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

Problem D can be solved in $$$O(N)$$$.

Hint: use difference array and prefix sum.

Spoiler
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится -6 Проголосовать: не нравится

    Oh, I only got an $$$O(n^2)$$$ solution using an algorithm like bucket sort. I didn't think about using difference array and prefix sum:(

    Perhaps my algorithm is easier to code, but its efficiency is very low...

    My code is below:

    #include <bits/stdc++.h>
    using namespace std;
    const int maxN=2005;int n,x,y,s[maxN][maxN],ans[maxN],t[maxN*maxN];
    int main() {cin>>n>>x>>y;
    	for (int i=1;i<n;i++)
    		for (int j=i+1;j<=n;j++) s[i][j]=min(j-i,abs(x-i)+1+abs(y-j));
    	for (int i=1;i<n;i++)
    		for (int j=i+1;j<=n;j++) t[s[i][j]]++;
    	for (int k=1;k<n;k++) cout<<t[k]<<'\n';
    }
    
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://atcoder.jp/contests/abc160/submissions/11326931

This is my submission for problem C ,can anybody tell me why i am getting a runtime error on the testcases. I am new to programming ,please help.

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

I don't know why this approach doesn't work for E. ( I got 6 WA )

Here is my solution: https://atcoder.jp/contests/abc160/submissions/11367454

Is there anyone who save me?

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

Any help for Task D. The editorial in AtCoder is in Japanese I think. And I am not able to understand that

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

Can someone explain how we reach the formula in the editorial of problem F? Thanks in advance!

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

    Let $$$size[u]$$$ be the size of the subtree rooted at node $$$u$$$.

    Consider you're starting the process in node $$$u$$$. Then the number of answers for $$$u$$$ is the number of possible permutations of size $$$size[u]$$$ such that a child never comes before its parent in this permutation. Why is that? Because if we start at $$$u$$$. We write $$$1$$$ on it, then we go to its children, write first number between $$$2$$$ and $$$size[u]$$$ that hasn't been written yet and so on. So a child's number will never be smaller than its parents in this permutation.

    Now to get to the $$$dp$$$ formula, read this: https://codeforces.me/blog/entry/75262?#comment-594252

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

Supplementary editorial and sample codes for last 4 problems AtCoder ABC 160

»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится +3 Проголосовать: не нравится

There is another solution to E! I'll introduce another variable,N,and assume N,A,B,C,X,Y all have magnitude 1e5,to show time complexities.

Brute Force(the big idea)
Optimization 0
Optimization 1

Here's my code

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

E can be solved using ternary search as well.

Link