Stream_Cipher's blog

By Stream_Cipher, history, 3 years ago, In English

This is the original version of problem ,during the contest I tried to solve it using some combinatorics logic but i can't and for this version of problem we can just iterate over all possible PIN codes because constraints are small, yes i didn't able to get this logic during the contest, but i am curious to know the approach to solve this question if PIN size will be of 10 digits.

  • Vote: I like it
  • +7
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 5   Vote: I like it +1 Vote: I do not like it

I was curious about this too (and I am skeptical to think this is the only better way), but we can do pins of slightly larger size using bitmask dp:

Let dp[i][bm] = the # of "good" strings of length i where bm = the digits that are used (a 10 bit number where 1 in a bit position indicates that digit was used, 0 otherwise). Then we can see that the transitions are:

// we decide to use this digit in position i, and the digit is of type 'o' or '?'

dp[i + 1][bm | (1 << digit)] += dp[i][bm]

Then we use the string they gave us to precompute the "good" bitmasks (aka, if the string they gave us says that we need a digit in our string, then we only look at bitmasks with this bit on). This gives us a runtime of doing digits * 2^10 * 10 operations, which should be able to handle 10 digits.

https://atcoder.jp/contests/abc201/submissions/22653905 is my submission for this (using this idea), although I am willing to hear other (probably better) solutions