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

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

We will hold AtCoder Beginner Contest 152.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

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

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

Note — Contest starts 10 mins before the usual time.

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

Hope that there is no question which is available on any other platform. PS:- F of last contest :(

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

How to do F?

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

Commentary:

  • A: Implementation.
  • B: Implementation. The easiest approach is actually building both strings and using your language's built-in lexicographic comparison.
  • C: If we read the elements of $$$P$$$ left-to-right and maintain the "minimum so far," the answer is equal to the number of times that minimum is updated.
  • D: $$$N \leq 2\cdot10^5$$$, so we can iterate over all numbers in $$$[1, N]$$$ and build a map $$$(f, d) \rightarrow \textrm{number of integers starting with } f \textrm{ and ending with }d$$$. The map has at most $$$100$$$ elements. We can iterate over all possibilities for the pair $$$(A, B)$$$ in quadratic fashion.
  • E: Let $$$L = A_1B_1 = A_2B_2 = \dots = A_NB_N$$$. Each $$$A_i$$$ must divide $$$L$$$. $$$\sum_i B_i$$$ is minimized when $$$L = \textrm{LCM}(A)$$$. We need to compute $$$\textrm{LCM}(A)$$$ modulo $$$10^9 + 7$$$. If prime $$$p$$$ has multiplicity $$$m_i$$$ in entry $$$A_i$$$, it has multiplicity $$$\max_i m_i$$$ in $$$\textrm{LCM}(A)$$$. We can factor each element of $$$A$$$ using a pre-computed sieve and maintain an array with the maximum multiplicity for each prime. Finally, we compute and print $$$\sum_i \frac{L}{A_i}$$$.
  • F: The main idea is inclusion-exclusion. Let $$$R$$$ be the set of all restrictions and for any $$$r \subseteq R$$$ let $$$f(r)$$$ be the number of edge-colorings which violate all of the restrictions in $$$r$$$. Violating a restriction $$$(u_i, v_i)$$$ means that each edge on the path from $$$u_i$$$ to $$$v_i$$$ is colored white. Hence if $$$g(r) = $$$ the number of edges in the union of all paths in $$$r$$$, $$$f(r) = 2^{N - 1 - g(r)}$$$. $$$g$$$ can be computed efficiently if we prepare bitmasks for each $$$(u_i, v_i)$$$ indicating which edges occur on the path from $$$u_i$$$ to $$$v_i$$$ (note $$$N \leq 50$$$, so we can use 64-bit integers for this purpose). Our final answer, the number of colorings which violate no restrictions, is $$$\sum_{r} -1^{|r|} f(r)$$$.
»
5 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

why am i getting WA in some cases in E? lcm(a1,a2,a3...an)*(1/a1+1/a2+1/a3+....+1/an) was the ans right?

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

How to deal with large numbers in E ?

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

Explain D please

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

    Define f(a,b) as number of integers less than or equal to n such that the first digit is a and the last digit is b. Observe that the solution is f(a,b)*f(b,a) over all possibilities. there are 81 possibilities (as leading 0's are not allowed) like so)

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

    why no code in D, E, and F?

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

      Unfortunately usually there are no sample code attached for the latter problems. You can see any submissions here anyway. (You can use filter in order to show only AC codes for a specific problems, and even filter by the programming languages.)

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

can we see others solution after contest in atcoder?

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

I did not get how to solve D, can someone explain?

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

    First, fix an integer $$$A$$$ where $$$1 \leq A \leq N$$$. Assume that the first digit of $$$A$$$ is $$$i$$$ and the last digit is $$$j$$$. How many $$$B$$$s are there that satisfies the given condition? The necessary and sufficient condition is that the first digit of $$$B$$$ is $$$j$$$ and the last digit is $$$i$$$. So, in order to count them, you can iterate the integers from $$$1$$$ to $$$N$$$, and check whether each of them satisfies the conditions written above or not.

    Then what to do next? Since $$$N$$$ can be up to $$$2 \times 10^5$$$, the total loops can be up to $$$4 \times 10^10$$$, so it won't finish in time. This means that you are wasting time for something, typically doing the same calculation over and over again. Now focus on this step mentioned above:

    you can iterate the integers from $$$1$$$ to $$$N$$$, and check whether each of them satisfies the conditions written above (= whether its first digit is $$$j$$$ and the last digit is $$$i$$$) or not

    Instead of performing the step for every $$$A$$$, you can count "the number of integers such that the first digit is $$$j$$$ and the last digit is $$$i$$$" (Let this number be $$$c_{ji}$$$ by looping through from $$$1$$$ to $$$N$$$ only once. So, you could solve this problem.

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

For F is O(n*m*2^m) under TL?

https://atcoder.jp/contests/abc152/submissions/9614620

or i am not considering complexity correctly?

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

    m<=min(20,n*(n-1)/2)

    so if n==50, m could be as large as 50*(50-1)/2=1225. It's hard to imagine that n*m*2^m could be under TL...

    but since you got AC, the m in testcases should be much smaller than the problem stated.

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

      ok, since there are only n-1 edges and constraints combination results in edges combination, the distinct number of results of constraints combinations is bounded to the number of edges combinations, which is 2^(n-1). But 2^(n-1) still looks very large.

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

    Actually it could be O(n*m+2^m).

    First, precompute all edges for each constraint and save as bitmask. (n<=50, so it's doable). This part is O(n*m).

    Then enumerate constraint combinations. Through the way just do bitmask or operation. With each combinations mask, __builtin_popcountll(...) could be used to figure out how much 1s in the long long mask, which let me get rid of O(n) loop, and it's said to be O(1). This part is O(2^m) in total.

    My submission if you interested

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

for F did anyone understand the tutorial's solution?

Also if i have a tree with nodes <= 10^5 and some M paths how can i know the total number of edges covered?

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

    O_E what u didn't get in editorial?i don't think it can be solved for large constraints

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

      i didn't understand how it uses LCA and cumulative sums

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

        I'll try my best to explain it.

        suppose you want to all edges b/w u-->v

        so path will be like u---->lca(u,v)----->v.

        in this way determine number of all paths which are white.

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

        You can use LCA since any path from u to v can be decomposed into a path from u to lca(u,v) and another path from v to lca(u,v) which makes our lives easier when we use prefix sums.

        Using prefix sums is similar to updating a range in array [l,r] when you arr[l]++ and arr[r+1]-- in this way the prefix sum of every index equals to the number of update ranges that has start<= index and end >=index, similarly when it comes to trees, if you want to say that the path from u to v (where u is an ancestor of v) is used, you can do arr[u]-- , arr[v]++, and then for each node let arr[node] = summation of all values of its subtree, if arr[node] is positive, this means the edge parent[node] to the node is used because this can happen if there is at least one path that start in one of the subtree's nodes and end in an ancestor of that node.

        You can check my submission if it's not clear.

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

can someone explain atcoder beginner 152 problem c? https://atcoder.jp/contests/abc152/tasks/abc152_c

because according to question it is given as P[i]<=P[j], but in Sample Input1 it is P[j]>P[i]. Please correct me if I understood the question wrong?

My submission link: https://atcoder.jp/contests/abc152/submissions/12066847

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

    I believe you had misunderstood the condition part, for any integer j(1<=j<=i), Pi<=Pj. Any integer here means that all the integers j in the range[1,i] that satisfy the condition, you should edit code as below, but it actually runs TLE:

    int total = 0;
    for(int i=0; i<n; i++){
        int count = 1;
        for(int j=0; j<=i; j++){
            if(arr[j]<arr[i]){
                count = 0; //violates the condition
                break;
            }
        }
        total += count;
    }
    

    You should solve it using min as the editorial shows. Notice that if the all the previous elements Pj>=Pi, Pi is the minimum value for the array from position 1 to position i. We just check how many i s satisfy this condition.

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

Can someone explain why this gets Compilation error ? Link

it run with my IDE but in atcoder website gets compilation error