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

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

We will hold AtCoder Regular Contest 176.

The point values will be 400-400-700-700-800-1000.

We are looking forward to your participation!

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

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

Hoping for the best ARC Round!

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

Good luck to all who are competing!

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

As a writer,I hope everyone who participates in this contest will enjoy it. Good luck!

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

Good Luck!Hope C!

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

I didn't get the question right

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

A was kinda tricky if you don't get the point :( I spent 30+ min on it :(

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

    what was the idea?

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

    can u please explain the solution of A. I am unable to get (b[i] — a[i] + n) % n , i cant understand it even after looking at the editorial

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

      Maybe you can look at the following cases:

      One of the ways of n=6,m=1,(a,b)=[(1,3)]:
      ooxooo
      oooxoo
      ooooxo
      ooooox
      xooooo
      oxoooo
      ---
      One of the ways of n=6,m=2,(a,b)=[(1,3),(5,4)]:
      ooxooy
      yooxoo
      oyooxo
      ooyoox
      xooyoo
      oxooyo
      

      Where x and y means $$$1$$$ and o means $$$0$$$. You can divide them into $$$n$$$ sets that in each set, the elements has a same $$$(b_i-a_i)\bmod n$$$.

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

Yet another pure math contest. I suck at math, so dislike.

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

can B be solved using bitmasks? I don't know about it but i reduced it to a point like this where quotient is

$$$ q = \frac {1000000....00_2} {111...1000...000_2} $$$

but I was unable to solve it as I'm not good enough in bitmasks and stuff

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

what is the idea behind A?

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

    The idea of the editorial is that:

    First, let's try solve the problem without the given m value-1 cells.

    How to solve m = 1? If you fill all cells on the antidiagonal with 1, then the sum of any row or column will be 1. No two cells on the antidiagonal are on the same row or column, and each row and each column are contributed by exactly one cell on the antidiagonal. (Assuming 0-based coordinate system is used) Cell v[i][j] on the antidiagonal are those where i + j = n-1. This solves the problem for m = 1.

    What if m = 2? First fill the antidiagonal with 1. Then, you can "shift" the antidiagonal by 1 to the left and fill this new "antidiagonal" with 1. This new "antidiagonal" covers all cells v[i][j] where i + j = n-2 and v[n-1][n-1], or equivalently all elements v[i][j] where (i + j) mod n = n-2.

    Applying to an arbitrary m, you just need to pick m such "antidiagonal"s and fill cells on them with 1.

    How to solve the original problem where m value-1 cells are given? You just need to fill the "antidiagonal" of those m cells first. Some of them might belong to the same "antidiagonal". Then you can fill any rest "antidiagonal"s as needed.

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

Does B have no testcase with $$$n = m-1$$$ and $$$k=m-1$$$? I realised this condition a few seconds after submitting, but to my surprise, my code got AC.

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

Data of problem A is weak. As a result of me and my friends' verification, there is not a single piece of data that is $$$M \ne N < 2M$$$. And this is the evidence.

For example, this code which I submitted during the contest must be wrong. It gives completely wrong answer with this input.

# Input
3 2
1 1
2 2

# My Output (Wrong)
6
1 1
1 2
2 1
2 2
3 3
3 3

I sent a clarification an hour ago, and I'll update as soon as possible when I see any response. I hope that I can write up a code that will allow me to get Accepted after the data is strengthened.

And I LOVE problem B. Very beautiful problem!

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

can anyone explain question b solution i did not understand

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

My First ARC got a 0pts but Rating+26, seems like it does need so many brainstroming instead of a number of algorithms at ahead problems.

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

Problem B is really a clever problem. I think I will never notice the case k=m-1 until I read the editorials. Hats off to the problem writers!

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

Data of problem C is also weak

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

    The Editorial of C says:

    If $$$v$$$ does not exist or $$$X_v<k$$$, the answer is immediately determined as $$$0$$$.

    and I forgot to check this case ($$$X_v < k$$$) during the contest, but my code got AC.

    There is an input for this case:

    Input:
    10 9
    1 2 10
    1 3 10
    1 4 10
    1 5 10
    1 6 9
    6 7 9
    6 8 9
    6 9 9
    6 10 9
    Output:
    0
    

    my code during contest will give $$$40320$$$.

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

      My code passed your case, but for this case:

      Input:
      5 3
      1 4 3
      4 5 4
      4 3 4
      Output:
      0
      

      my code will give 4.

      I'm not sure whether this is common.

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

        I hacked a lot people when I try to use their codes to check my wrong code. I'm so helpless. Who could help me?

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

Can someone explain the following code for problem A — 01 Matrix Again ?

import java.util.*;
public class Main {
   public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = scanner.nextInt() - 1;
            b[i] = scanner.nextInt() - 1;
        }

        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < m; i++) {
            set.add((b[i] - a[i] + n) % n);
        }
        for (int i = 0; i < n; i++) {
            if (set.size() == m) {
                break;
            }
            if (!set.contains(i)) {
                set.add(i);
            }
        }

        System.out.println(n * m);
        for (int p : set) {
            for (int i = 0; i < n; i++) {
                System.out.println((i + 1) + " " + ((i + p) % n + 1));
            }
        }
    }

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

    There are total of n^2 elements in matrix so each (i-j)%n will occur atmost n times.

    (you can draw the matrix of (i-j)%n for some n to see it youself)

    since element are occurring on separate row and col we can assign 1 to such element that will increase the sum by n. How many times we need to do this? m times

    So at last we just need to select m remainders out of n and assign 1 to those positions.

    since some pairs are already given, we can just use remainder of those.

    I hope it helps...

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

can someone explain me the problem problem D in it ,I cant understand how transition states are made.

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

    Consider solving the subproblem for k, where we convert all p[i] <= k to 0 and p[i] > k to 1. The subproblem is to calculate, after m swaps, the number of (p[i], p[i+1]) such that one of them is 0 and the other is 1. Let s0, s1, s2 represent the states of containing 0, 1, 2 ones in an adjacent pair (p[i], p[i+1]) respectively.

    Now, let's consider the transitions of a single swap:

    • s0 -> s0, or to say p[i] = 0 and p[i+1] = 0 before and after the swap. There are 3 scenarios:
      • The swap doesn't involve i and i+1. The number of elements except i and i+1 is n-2. The number of swaps of this kind is C(n-2, 2).
      • The swap is (i, j), where p[j] = 0 and j != i+1. There are k zeros in total. Since both p[i] and p[i+1] are zeros, the number of rest zeros is k-2, and thus the number of such swaps is k-2.
      • The swap is (i+1, j), ... Similar to the above case, there are (k-2) such swaps.
      • The swap is just (i, i+1). Ofc the count is 1.
      • In conclusion, the number of swaps turning s0 to s0 is C(n-2, 2) + 2*(k-2) + 1
    • s0 -> s1: The swap is (i, j) or (i+1, j), where p[j] = 1. Since the number of ones is (n-k), the number of such swaps is 2 * (n-k).
    • s0 -> s2: There's no way to turn 2 zeros to 2 ones in a single swap.

    Transitions starting from s2 is just symmetrical to the above transitions starting from s0:

    • s2 -> s2: C(n-2, 2) + 2*((n-k)-2) + 1
    • s2 -> s1: 2 * k
    • s2 -> s0: 0

    Transitions starting from s1 can be similarly deducted:

    • s1 -> s0: k-1
    • s1 -> s1: C(n-2, 2) + (k-1) + ((n-k)-1) + 1
    • s1 -> s2: (n-k)-1

    With the above transitions, you can construct a 3x3 matrix M, where M[a][b] = the number of ways for the sa -> sb transition in a single swap. Let MM = M^m. Then MM[a][b] = the number of ways for the sa -> sb transition in m swaps. Let S be the 3x1 matrix where S[a][0] = the number of sa states in the original permutation. Let T = MM * S. T[a][0] will be the sum of the number of sa states after all possible m swaps. The answer to the subproblem is T[1][0].