atcoder#AGC019E. [AGC019E] Shuffle and Swap
[AGC019E] Shuffle and Swap
Score : points
Problem Statement
You have two strings and of the same length consisting of and . The number of 's in and is equal.
You've decided to transform using the following algorithm:
- Let , , ..., be the indices of 's in .
- Let , , ..., be the indices of 's in .
- Replace and with their random permutations, chosen independently and uniformly.
- For each from to , in order, swap and .
Let be the probability that strings and become equal after the procedure above.
Let . Clearly, is an integer.
Find modulo .
Constraints
- and consist of and .
- and contain the same number of 's.
- and contain at least one .
Partial Score
- points will be awarded for passing the testset satisfying .
Input
Input is given from Standard Input in the following format:
Output
Print the value of modulo .
1010
1100
3
After the first two steps, and . There are possible scenarios after shuffling and :
- , . Initially, . After swap(, ), . After swap(, ), .
- , . Initially, . After swap(, ), . After swap(, ), .
- , . Initially, . After swap(, ), . After swap(, ), .
- , . Initially, . After swap(, ), . After swap(, ), .
Out of scenarios, of them result in . Therefore, / , and .
01001
01001
4
No swap ever changes , so we'll always have .
101010
010101
36
Every possible sequence of three swaps puts the 's in into the right places.
1101011011110
0111101011101
932171449