Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)Problem C Problem Link
I read the editorial it used brute force approach
Is it possible to do this question using math? (without checking for 10^4 possible passwords)
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)Problem C Problem Link
I read the editorial it used brute force approach
Is it possible to do this question using math? (without checking for 10^4 possible passwords)
Name |
---|
Yes you can solve this problem with combinatorics.
If the pins were of unique elements, you would solve it with basic combinatorics. But since that's not the case, you should still iterate over the elements to subtract those overlaps, considering many cases.
Still, that's my opinion, I am very interested if some, not complicated formula exists for this.
you can use combinatorics:
if an element is fixed ('o') you can use polynomial: $$$exp(x) - 1 = \frac{x}{1!} + \frac{x^2}{2!} + ... $$$
in other case ('?'): $$$exp(x) = 1 + \frac{x}{1!} + \frac{x^2}{2!} + ... $$$
The answer consists first of multiplying all these polynomials and answering the coefficient 4 multiplied by 4!
Using the fact that $$$exp(x) ^ c = exp(c * x)$$$ you have 6 cases for each number of characters 'o'.
code
answer $$$= \sum\limits_{i=0}^b (-1)^i \binom{b}{i} (a + b - i)^4$$$
where a = #'?' and b = #'o'.
In general you need to calculate the coefficients of $$$(x - 1)^k$$$, which can be achieved in $$$O(k)$$$.