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

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

We will hold AtCoder Beginner Contest 165.

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

We are looking forward to your participation!

UPD:

In Problem E, the constraints says N <= 100000, but it turned out that the inputs are made under the condition N <= 200000.

It was revealed that only 6 people were affected by the defect of the problem E constraint, and 4 among them were rated competitors. As the impact is very minor, contestants excluding the four are going be rated, and the affected four will also be rated after rejudging to get AC on their submissions.

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

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

2 ABC this weekend, what a time to be alive! Thanks a lot AtCoder team for making this quarantine more fun!

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

Did the start time just got extended by 5 minutes?

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

website crashed ?

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

site is not loading?

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

RIP

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

Site down?

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

Again 502 Bad Gateway :(

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

504 Gateway Time-out:(

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

Postponed for 5 minutes.

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

Start time extended by 10 minutes.

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

    Its good that they acted quickly otherwise this contest also could be unrated :D

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

extended by more 5 min :(

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

Will they just postpone the contest by increments of 5 minutes until enough people go away and there is less load on their servers??

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

delayed due to inadequacy in problem

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

“The start will be delayed for 10 minutes due to an inadequacy discovered in the problem. I'm sorry.“

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

Here we go

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

C is too hard for C, imo.

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

    easy

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

    Solved E, but didn't C...

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

      10! algorithm would work

      take a look at the constraints

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

        it would be (n+m-1)C(m-1), so worst case 19C10

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

          How could you get this formula?I saw same question in one educational round but i don't know proof behind this formula?

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

            there's a n*m size rectangle, at the beginning, you are at the bottom-left corner, now that formula is the number of ways to get to the right side of the rectangle only go right or top.

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

            You have M distinct numbers you can give each number some frequency and frequency of each number can be between [0, N] (N = length of sequence), since you have to make sequence increasing so for any fix combination of numbers and frequencies there will be only one increasing sequence. So now the problem is reduced to find the number of solutions of equation f1+f2+f3+..+fm = N, where fi is frequency of ith number in the sequence.

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

      Solved F but not C and E.

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

        same. F was easy, if you know O(nlogn) solution for finding LIS.

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

        I tried solving F using coordinate compression and range-max segment tree. But i kept getting WA :( . Been trying to figure out the error, but I wasn't able to. Here is my submission WA solution

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

          It also happened to me.

          lets denote some variable: max_val=maximum compressed value

          prev_val=query(pos[u],pos[u])[value of the index of pos[u] , before line 45]

          1) in line 45:

          update(pos[u], val) -> update(pos[u],max(val,prev_val))

          2) in line 46:

          ans[u] = val -> ans[u] = query(0,max_val)

          3) in line 52:

          update(pos[u], 0) -> update(pos[u],prev_val)

          I suppose this works fine...

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

            Thanks a lot. Realized that for considering the LIS for a path from 1 to k, I take the answer as dp(k), instead of max(dp(i)) for i from 1 to k.

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

    +1. Solved rest but couldnt do this.

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

    It was too hard for me too. I thought number of combinations will be too large. But turns out there can be at max 92378 for n=10 and m=10. So brute force works.

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

How to solve C !

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

    just try all the state.

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

      Though I doubted whether it will get TLE in the beginning...

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

      How does this work, I came to the conclusion that there are $$$10^{10}/2$$$ possible arrays to check. To much.

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

        No you are wrong ,There are much fewer arrays!! You can write a dfs to count them.

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

        There are 92378 possible arrays for N = 10, M = 10 that have A[i]>=A[i-1] only.

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

          Well, thanks for explanation.

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

          how did you got this ?

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

            Either go with a brute solution and find using code or use P&C and we can say sum of gaps between consecutive numbers is at max m-1 and number of gaps are n-1, so g1+g2+g3... gn-1 + k = m-1, so number of whole number solutions of this equation are m-1+n-1Cn-1

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

        actually the number of array is 10 choose 10 with repetition so that means it is 19 choose 10 which is equal to 92378. I have solved it in the most crazy way. my submission

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

        we should only consider monotonically increasing sequence

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

        Combinatorial way to look at it.

        You need to find number of arrays $$$A = \{ A_1, A_2, ..., A_N \} $$$, such that $$$ 1 \le A_1 \le A_2 \le ... \le A_N \le M $$$.

        Let $$$ x_i $$$ be the number of occurences of $$$ i $$$ in the array. Then we require number of solutions to $$$ x_1 + x_2 + ... + x_M = N $$$, where $$$ x_i \ge 0 $$$.

        This, given by Stars and Bars, is simply $$$ {N+M-1} \choose {M-1} $$$ = $$$ {10+10-1} \choose {10-1} $$$ = $$$ 19 \choose 9 $$$ = $$$92378$$$.

        I usually use this website to do quick calculations for combinations, during contests.

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

      :)

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

    Backtracking

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

    You can write a recursive brute force, which will include all possible states we can go to.

    Consider we want to fill n places. We start from place_id = 1, and num = 1.

    Now we have 3 possible cases:

    • Don't include the current number at this place, so increment the 'num' by +1.
    • Include the number so now we need to fill next place, so increment 'place_id' by +1 and continue using the same number for further positions.
    • Include the number at the current position, but we don't want to use the same number for next pos, so increment both 'place_id' and 'num' by +1.

    If you are confused, you can take a look at my submission, though it isn't the cleanest. Submission

    I hope it helped.

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

Honestly, I think it is not very wise to give such C and D in abc contest.

I am sure there a thousends(?) of possible participants not submitting any solution because scared by a hard C and a D full of corner cases.

Dont get me wrong, I think these are nice problems, but simply misplaced.

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

    I can solve D by math with no corner cases. https://atcoder.jp/contests/abc165/submissions/12609383 Can not solve C. E. F.

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

      D was just to take x as min(b-1,n).

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

      F was easy with segment tree i think

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

        Are you serious ?Why you used segment tree for E?

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

          sorry my bad, F

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

            I think F by set will be more easy

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

      Would you please simulate your math formula!

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

        you need to maximize, but if you observe for any x >= b, float[x/b] will always be greater than 0, and then you multiply it with A, but float[Ax/b] can atmost be equal to that. Thus its always optimal to make float[x/b] = 0, so that you answer is float[Ax/b]. To make that equal to 0, just take max x < b, but since x <= N, x = min(n, b-1). Then return the answer.

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

      Explanation for D; If x increased by B, value not change, so we only consider x in range 0 — min(b-1,n); So The second part of the function becomes zero and the first part becomes maximum.

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

    Is C very hard?just try all the state!

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

The English Commentary for Problem C and D is here

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

    D with binary search... Wait. what? How? What does your check function do? The function isn't strictly increasing nor decreasing as far as I understand..

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

      it's not increasing nor decreasing... however if you notice function is increasing in intervals of b. eg. from x = 0,1,2,..b — 1 f(x) is increasing at x = b f(x) again drops and starts increasing same as for previous x

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

        Exactly, since it drops at B, you can't binary search on interval (0,n). If you are Bsearching on interval (0,B-1), that isn't required, since it is increasing from 0 to B-1...so B-1 is going to give you maximum.

        Also, I am not sure if this Bsearch on (O,N) will work always. Since it is repeating maybe that is why it worked.

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

    Please provide proof of your construction in D

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

Can someone give a hint on E and F?

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

Why is my ternary search failing on one test case for D? :((

https://atcoder.jp/contests/abc165/submissions/12647186

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

    Why you are using ternary search ... Its just simple math

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

      F

      I just assumed the function was unimodal and tried ternary search and it almost AC'd. Can you elaborate your solution?

      EDIT: unimodal not monotonic

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

        The function is repeating after every B values of X.

        Try to express X = qB + r and solve the equation. You will find that, function is max when r = (B-1). Also, in case, b — 1 > N, then N is your answer cause, from 0 to B-1 the answer is increasing.

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

    No need for ternary search, answer is monotonic with modulo value with B.

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

      When you know it is monotonic between 0 to B-1, when not just return B-1...

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

Problem statement of C was so confusing.Can anyone explain it?

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

    You are asked to create an array a, of size N. You should place values in that array from 1 up to M. The array should be not decreasing.

    Then you get those quadrupels. If you put at position a and b values, so that the difference is c, you get d points.

    Try to find an array with maximum possible points.

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

How to solve F ?

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

    Apply the O(nlogn) algorithm for LIS during the dfs while nullifying the changes made by a particular branch of a node when we visit its another branch.

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

    I maintained a segment tree for current root to node path for lis, and as i move down i make updates like in normal lis, and as i move up, i roll-back on the changes i did previously.

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

All the people complaining about C being too hard. Is it possible that they didn't notice the constraints that array is in increasing order A[1] <= A[2] <= A[3]..... <= A[N]? Because I skipped it initially and thought for several minutes that total case are $$$10^{10}$$$ which was outside the time limit.

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

    Same happened with me. How many possible combinations are possible ?

    a1 <= a2 <= ... <= an , (1<=ai<=m)

    Solved it, but I couldn't prove the time complexity.

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

      Observe, that if you pick set of numbers, there can be only one possible array, so you just need to count number to choose n elements from 1 to m, it is exactly $$$\binom{n+m-1}{n}\le 92378$$$

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

        There is a small mistake. I think the time complexity should be $$$C_{n+m-1}^{m-1}$$$.

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

    And... is 10^10 not outside the time limit?

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

    First i wrote a dp solution to count how many such arrays exists. Then used brute force.

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

    In fact there are only $$$C_{m+n-1}^n$$$

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

Solns/Approaches

  • A. Check every element

  • B. Observe that answer never exceeds 5000 (use log to check). We can loop until success.

  • C. Generate every possible combination. In python, we have combinations_with_replacement which generates exactly what we need

  • D. Observe that for $$$x < b$$$, $$$\lfloor x/b \rfloor$$$ is zero. We want to take $$$x = kb-1$$$. Also observe that taking $$$k > 1$$$ always make the answer worst. We take $$$x$$$ as $$$\min(n, b-1)$$$.

  • E. What we need is set of $$$(a, b)$$$s such that distance between $$$a, b$$$ never occurs twice. (Considering not only b-a, but we have to consider the other way. e.g, when $$$n = 10$$$, distance between $$$1$$$ and $$$10$$$ is 1 and 9. both should not appear again.)
    When $$$n$$$ is odd, take $$$(1, n), (2, n-1), \dots$$$. One can easily show that this is valid.
    When $$$n$$$ is even, take those values until we can't. (e.g, when $$$n = 10$$$, we take $$$(1, 10)$$$, $$$(2, 9)$$$ but not $$$(3, 8)$$$ since distance between $$$(3, 8)$$$ is 5 and 5 — repeated.) Then, discard one unused value and proceed. (e.g, after two takes, use $$$(3, 7)$$$ instead of $$$(3, 8)$$$, and $$$(4, 6)$$$.
    Submission : https://atcoder.jp/contests/abc165/submissions/12617571

  • F. Consider computing LIS length in $$$O(n \log n)$$$ time with DP and lower_bound. (without considering the actual values). When we do this, we discard what was in that spot (lower bound). Instead of doing this, keep those values by multiset or stuff like that. We traverse tree in DFS order, pushing values we meet in LIS-solving pattern but keeping values instead of throwing away. When we traversed all of it's subtrees, we erase value of the node from where we pushed. To do this we track the number of non-empty multisets and index we pushed each value in. Time complexity $$$O(n \log n)$$$.
    Submission : https://atcoder.jp/contests/abc165/submissions/12637543

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

    @gratus907 can you please tell how you came to conclusion for problem E?

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

      I thought it intuitively after some casework... and I tried to prove my thought (I mean, not rigorously, but like convincing enough to start writing code)
      As I've wrote, a case when two people meet twice is only when there exists $$$(a, b)$$$ and $$$(c, d)$$$ which $$$b-a$$$, $$$n+a-b$$$, $$$d-c$$$, $$$n+c-d$$$ has repetitions. Try some casework in $$$n = 8$$$, $$$n = 10$$$ to convince yourself with this statement :)

      I actually have nothing much to say as I did tons of caseworks on paper...:(

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

    You don't really need any multiset for problem F. Just change the value at lower_bound and remember what it was. After solving all subtrees and updating the answer just return the value to what it was. Submission

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

      Apparently yes.. I discussed this problem with my friend after the contest and he also said the same thing. I felt very dumb since he coded like 800 bytes while I coded more than 2000... lol
      I have no idea how I managed to think returning values by dfs tree and then thought something like "WOW I want vector<multiset<int>>" and started coding :(

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

I'm assuming some greedy strategy works for C. Can somebody please post their logic/solution? I filtered queries such that for each (a, b) indices pair — the optimal c for maximum d is known. For the array A[n], I set A[0] = 1. From here, I am confused about how to construct the rest of the array. I tried a couple of ways but there were always some cases not adhering to the rule.

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

    C was a pruned brute solution i think.

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

      Yeah. During the contest, I thought the time complexity would be too much. I wish I had checked it with a program though. For n = m = 10, there are about 48,000 possible sequences only.

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

It seems difficult orz

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

I think E is harder than F, as I'm not good at construction and pattern observing

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

Is this round a bit easier than before? I used to solve 4 or 5 problems but today I solved 6 within a short time. Well anyway the problems are still very good (like, you can solve D and E with about 300 bytes of code but you need to think a long while). BTW, I think C is a bit hard for C. Since DFS may be not very "beginner-friendly".

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

D one was way too easier than the C one

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

Check Same question ... I still missed it.. hard luck today.

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

F is an easier version of NA Southeast Regional 2019 problem G

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

Nice contest!

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

    This comment shouldn't be answered. This is a problem from an ongoing contest, Bubblecup.

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

From stars and bars trick we get for C only 92378 states are there i.e ncr(10+10-1,10-1)

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

A. Oh, constraints are really small, let's just iterate.
B. Hm, it's exponential growth, I think max answer is not too big. Let's write and see (turns out max answer was in samples, but I didn't notice).
C. Hm, seems like a lot of states, no idea, let's read D.
D. Hmm, let's write bruteforce and see. Oh, it's always zero for multiples, ok, let's take multiple-1 if we can.
C. Hmm, maybe there are not too many states? Let's write bruteforce and see. Oh, it's really small, dumb me. (It's just C(n + m — 1, n))

E and F are nice, but quite easy.

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

    How do you arrive at C(n + m — 1, n)? I had to count them by writing the dfs.

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

      The sum of gaps between consecutive numbers is less than equal to m-1, it's basic P&C afterwards.

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

      This is a classic stars and bars application.

      Note the condition that $$$1 \leq A_1 \leq A_2 \leq ... \leq A_n \leq M$$$. Thus, it is sufficient to count how many times each number from $$$1$$$ to $$$M$$$ appears in the sequence (because we would then only have one way to arrange these numbers---in nondecreasing order). So, now imagine a line with $$$N$$$ stars and $$$M-1$$$ bars. The stars before the 1st bar corresponds to the number of 1s, the stars between the 1st and 2nd bar correspond to the number of 2s, etc. For example, if m=4 and n=7, then *||****|** corresponds to one $$$1$$$, zero $$$2$$$s, four $$$3$$$s, and two $$$4$$$s. So, how many possible ways are there to arrange $$$M-1$$$ bars and $$$N$$$ stars in a line? There are $$$M+N-1$$$ "spaces", and of them we need to choose $$$N$$$ locations to be where we place the stars. We place the bars in all other locations.

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

Can someone explain the observation made in problem E.

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

in problem E: if i match 1 with n then 2 with n-1 and so on (m times) why is it wrong

I got WA with this approach in 9 test cases

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

Can anyone prove the running time complexity for the brute solution of C please?

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

    O(Q * 92378) because number of valid(non-decreasing arrays) arrays with n = 10 and m = 10 are 92378. You can calculate this with dp or with Combinatorics.

    Code for Counting with Dp
»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

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

May someone help me debug F: LIS on Tree? I have done using binary search and dynamic programming. I have used 0-indexed dp. My submission: https://atcoder.jp/contests/abc165/submissions/12674946

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

How does the checker work in E? chokudai

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

    For all the pairs given by the user check their difference both ways. Like 1 and 10 will have difference 1 and 9. These differences should be all different. So you can check in O(M).

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

I can't understand why my A solution fails Here's my code

k=int(input()) a,b=map(int,input().split()) if b-a+1>=k: print('OK') else: print('NG')

can anyone point out my mistake

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

why would I get WA for problem.E

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxn = 1005;
int main(){
    int n,m; cin >> n >> m;
    vector<pii> ans;
    int L = 1,R = n;
    while(m){
        if(L+n-R == R-L) L += 1;
        else{
            ans.push_back(pii(L,R));
            L++; R--; m--;
        }
    }
    for(int i = 0;i < sz(ans); ++i) 
        cout << ans[i].x << " " << ans[i].y << '\n';
    return 0;
}
»
4 года назад, # |
Rev. 2   Проголосовать: нравится +24 Проголосовать: не нравится

I believe the test files for the problem E were incorrect.
Instead of n <= 100000 , it should be m <= 100000 . If I write an assert statement for the value of n being less than or equal to 1e5, the verdict is RE, while for 2e5+2 it is AC.

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

Problem F:I have used LIS(nlogn) with B.F.S. but getting T.L.E......please help. https://atcoder.jp/contests/abc165/submissions/12695808

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

Here is my list of submissions.You can use that as reference.

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

Why are there different results when using GCC and Clang? There are 4 testcases that fail to pass, but my method has no problem. So I checked the official testcase and the input and output, and found that the final problem is that GCC and Clang have different results. I want to know why? ? ? ! ! ! here is my two submission:(the first is AC and the second is WA,but the code is exactly the same!) Your text to link here... Your text to link here...

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

    Rehappy, the defined arrays a,b,c,d should have length 51 if you intend to write into them at positions 1, ..., 50 — this causes your code to write outside of bounds of the arrays, causing undefined behavior (it can still theoretically work, but also the compilers decided to zero out all variables in your program, it would still be a valid thing to do according to C++ spec — the compiler is free to do anything it wants when you do out of bounds access).

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

For E detail explanation with examples and code check here

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

For E,can some one tell me why this is wrong: void solve() { cin>>n>>m; int now=1; for(int i=1;i<=m;i++) { cout<<now<<" "<<(n+now-i-1)%n+1<<endl; a[now]=1; a[(n+now-i-1)%n+1]=1; while(a[now])now=(n+now-1-1)%n+1; } return ; }