ScarletS's blog

By ScarletS, history, 4 years ago, In English

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
  • Vote: I like it
  • +62
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it +20 Vote: I do not like it

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$$$

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it
    Spoiler
»
4 years ago, # |
  Vote: I like it +7 Vote: I do not like it

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

Spoiler
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 ?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      No worries. Thanks for the reference :) I understand the logic now.