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

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

A — ABC Preparation

Solution

B — Smartphone Addiction

Solution

C — Duodecim Ferra

Solution 1

D — Stamp

Solution

E — Sequence Matching

Solution

F — Range Xor Query

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

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

C can also be done using the Stars and Bars theorem,

We have $$$x_0 + x_1 + x_2 + \dots + x_{11} = n$$$ in C where $$$x_i$$$ are the lengths of the bars. This is just the number of positive integral solutions which is $$$n - 1 \choose 11$$$

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

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

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

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

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

Can you explain the dp[i][j] solution in Problem C a little more. How do the transitions come? I can't get that.

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

I did a $$$O(12*n)$$$ dp for C. Didn't notice the constraint was too small :/

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

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

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

For second solution of C actually you don't need python it also can be done with C++ like this.

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

    It's actually not necessary to check all the divisors like that. Instead, you can write a loop like this:

    // n choose k
    for (ll i = 1; i <= k; i++) {
        ans *= n - (i - 1);
        ans /= i;
    }
    

    The reason this works (without division issues) is because the intermediate result at the end of a loop iteration is $$$C(n, i)$$$, which we know is an integer.

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

In E, how does the dp definition and state transition ensure that we'll get two same length A' and B' after some operations for each subproblem ?

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

    Sorry for the late response, but this is a classical problem. We ensure that we get A' and B' of the same length, as previous states have equal lengths too. We either have two equal/unequal elements at the end (which goes back to $$$dp_{i-1,j-1}$$$ [+1 if unequal]), delete an element from A' (going back to $$$dp_{i-1,j}$$$), or delete an element from B' (going back to $$$dp_{i,j-1}$$$). You can read more about it on page 74 of CPH.