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

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

We will hold NIKKEI Programming Contest 2019-2.

The point values will be announced later.

We are looking forward to your participation!

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

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

Is it for only Japanese or all participants?

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

Nice and interesting contest, thanks.

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

How to solve C?

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

Will the editorial be translated to English?

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

How to solve E?

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

    The construction is impossible if

    $$$K+(K+1)+\cdots+(K+2N-1) \gt (K + 2N) + \cdots+(K+3N-1)$$$

    . The above inequality is equivalent to $2K-2>N-1$.

    Otherwise, the construction is always possible. For example, if $$$K=4$$$ and $$$N=7$$$, $$$(4, 14), (5, 15), (6, 16), (7, 17), (8, 11), (9, 12), (10, 13)$$$ can be made into construction. That is, divide the numbers between $$$K$$$ and $$$K+2N-1$$$ into "middle half" and "non-middle half" and pair the numbers in ascending order.

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

      Can you elaborate the splitting, it looks to me like you are pairing middle and first element increasingly then the rest of them and please do tell what is the main idea behind such splitting. "middle half" and "non middle" didn't quite get to me.

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

        The idea is trial and error, and in my AC solution, I first chose $$$\lceil\frac{n}{2}\rceil$$$ smallest and largest numbers and paired them, then paired remaining numbers similarly. I thought I would get AC by trying the method for various small value of $$$K$$$ and $$$N$$$.

        My AC code

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

    I have another solution.

    First if k+k>n+1 ,there isn't a construction.

    Then just make the construction like this:

    (k,2n,k+2n),(k+2,2n-1,k+2n+1),(k+4,2n-2,k+2n+2)....

    the rest, just choose the first number in the construction from the left ,the second number in the construction from k+2n-1 to the left (of course they aren't used).

    Sort and match them with the rest numbers(bigger than k+2n and aren't used) from small to large.

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

Can anyone explain B?

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

    Think of the tree being constructed from root to the nodes on deeper levels.

    You can place any node in the numer of places parent nodes on that level exist.

    So, the first node is the root node. All nodes on level 1 must be childs of the root node (on level 0), so there is only one possibiliy to place them.

    Every nodes on level 2 can be placed as a child of every node of level 1. So the posibilities are numNodes(level1) * numNodes(level2)

    The same is true for all other levels, too, so we need to multiply them.

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

Can anyone tell me how to solve F?

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

    Really nice problem! I'll give the outline.of the solution.

    Firstly, note that by flipping each interior square, we alter the points that lie on two diagonally oriented rectangles (possibly degenerate, i.e. diagonals). There are $$$n+1$$$ such rectangles, and each interior point can be encoded with a pair $$$(a, b)$$$ denoting the rectangles they "flip" (we number the rectangles by their distance of the top vertex from the top left corner of the grid). Notice that $$$a, b$$$ have the same parity and are distinct.

    By flipping a point with code $$$(a,b)$$$, we flip the lights where at least one coordinate of their code is $$$a$$$ or $$$b$$$. Consider a graph on the numbers from $$$0$$$ to $$$n$$$ of the same parity. Our operation of flipping a light can be described as choosing two vertices $$$u,v$$$ and flip the edges with at least one endpoint $$$u,v$$$. A configuration of lights is nice iff the lights with the same code are consistent and there exist a sequence if operations to reduce our graph to the empty graph, where we start by drawing an edge between the numbers in the code of on lights.

    We claim that if our graph has $$$N$$$ vertices, then the task is always possible if $$$N$$$ is even, and the task is possible for $$$N$$$ is odd iff the degree of each vertex is even. The necessity can be proven simply by considering the parity of the degree of each vertex after each operation.

    To prove the sufficiency, firstly note that by performing operations on $$$(a,b),(b,c),(c,a)$$$ where $$$a,b,c$$$ are distinct, then we can flip only these 3 edges. For $$$N$$$ even, flip $$$(u,v)$$$ and then flip $$$(u,v),(v,w),(w,u)$$$ for all other $$$w$$$. This flips exactly one edge $$$(u,v)$$$. For $$$N$$$ odd, we claim that we can always flip an Eulerian cycle. Indeed, we can simply extend the cycle repeatedly by flipping a triangle.

    Finally, it remains to count such graphs. The $$$N$$$ even case is obvious. To count the $$$N$$$ odd case consider the graph of unfixed edges. For each connected component, we can choose the existence of all edges except a spanning tree (we need to be careful about the case where the sum of "degree" of all vertices in the component is odd if we consider only fixed edges, in which case the answer is $$$0$$$ since our unfixed edges can only alter the sum of degree by an even number). This gives an $$$O(n^2)$$$ solution.

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

      Thank you.I think very long time about "the sum of "degree" of all vertices in the component is odd if we consider only fixed edges, in which case the answer is 0".See your explanation I finally understand.Thank for you much.

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

Question B D1 = 0 is required for a tree to satisfy the condition, otherwise the answer is 0. In the following, D1 = 0. Consider one tree where the distance between vertex 1 and vertex i is Di, and for each vertex i other than vertex 1, let pi be the closest vertex to vertex 1 among the adjacent vertices. You can see that it is 1. On the other hand, if (p2, ..., pN) is defined such that Dpi = Di−1 (i ≥ 2), the tree consisting of the edges connecting vertex i and vertex pi is uniquely determined. Therefore, the number to be obtained is the number of (p2, ..., pN) where Dpi = Di-1 (i ≥ 2). When the number of i where Di = k is ck, the number is obtained by multiplying each integer i of 2 or more by cDi−1, so it can be obtained in linear time.

Question C B1 ≦ B2 ≦ .... ≦ BN may be set by first arranging the elements appropriately. Suppose you want to rearrange (A1, ..., AN) with (Ap1, ..., ApN). In other words, the condition that Ai ≦ Bi in the end and the condition that the number of swaps is up to N−2 times, respectively, the condition that should be (p1, ..., pN) is as follows. Api ≦ Bi • When cyclic permutation (p1, ..., pN) is decomposed into cycles, it is decomposed into two or more cycles. First, take (p1, ..., pN) so that Ap1≤Ap2≤ ... ≤ApN. If Api ≤ Bi (i = 1, ..., N) does not hold at this time, there is no (p1, ..., pN) that satisfies the first condition, so the answer is No. Consider the case where Api ≤ Bi (i = 1, ..., N). If (p1, ..., pN) satisfies the second condition, the answer is Yes is. Therefore, it is sufficient to consider the case where (p1, ..., pN) consists of one cycle when it is decomposed into cycles. Here, if Bi <Api + 1 (i = 1, ..., N−1), there is only (p1, ..., pN) cyclic permutations that satisfy the first condition. The answer is no. On the other hand, if there is i such that Bi ≧ Api + 1, the cyclic permutation of (p1, ..., pi−1, pi + 1, pi, pi + 2, ..., pN) The answer is yes. All of this is done, so you can ask for an answer. The time complexity is O (NlogN) because it sorts.

D: Shortest Path on a Line You can see that d1 ≦ d2 ≦ .... ≦ dN, where di is the length of the shortest path from vertex 1 to vertex i. Therefore, even if a zero-length edge is added from vertex i + 1 to vertex i for each i, the length of the shortest path from vertex 1 to each vertex does not change. In the following, it is assumed that all these edges are included in the graph. Considering the edge added at the i-th time, if you add an edge of length Ci from vertex Li to vertex Ri, the other edges do not affect the shortest path. This is for a vertex s, t with Li ≦ s <t ≦ Ri, there is a zero-length path from s to Li, there is a side of length Ci from Li to Ri, and length 0 from Ri to t Since there is a path, we can see that there is a path of length Ci from s to t. From the above, it can be seen that the shortest path from vertex 1 to each vertex can be found by considering only N + M−1 edges. Therefore, the Dijkstra method can be used to solve with a time complexity of O ((N + M) logN).

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится
Solution to D using segment tree:

Observation: If you can move to point $$$i$$$ using cost $$$c$$$, you can also move to any point $$$j \lt i$$$ using cost $$$\le c$$$.

Therefore, we can sort the intervals by left-coordinate and apply each interval one at a time. Here, "applying" an interval $$$(L,R,C)$$$ means compute/store the optimum cost $$$c(L)$$$ to reach $$$L$$$, then set $$$c(R) = \min(c(R), c(L) + C)$$$. We know that by the time we reach $$$L$$$, we've already found its optimum cost, because we've already processed all intervals that could be used to reach $$$L$$$ (because we sorted them). Because of the observation above, we can compute $$$c(L)$$$ once we reach $$$L$$$ by taking $$$min(c(L), c(L+1), \ldots, c(n))$$$, and it's sufficient to store $$$c(L) + C$$$ to $$$c(R)$$$ specifically, instead of all indices between $$$L$$$ and $$$R$$$.

Runtime: $$$\mathcal{O}(N + M \log N)$$$

Code (L and R are 0-indexed here)
»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please help me to find why my solution does not work for problem C? I'm sorting by B and building a segment tree on A, and then for every Ai > Bi i search for some Bk >= Ai and Ak <= Bi and swap them, if there is no such Bk i try to find the Bj with the smallest Aj such that j > i and Bj >= Ai and Aj <= Bi.

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

Will test cases be posted?

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

Similar problems:

D and BZOJ 3073(pay to access)

both segment tree optimizing vertexes connecting