No.171 Swap String (Med)
Problem Statement
A string $S$ of at most $1000$ characters is given as input.
When you may perform the operation "swap any $2$ adjacent characters" on the characters forming this string $S$ any number of times,
find the number of distinct strings that can be made, $\mod 573$.
However, the string identical to the input string $S$ is not counted.
Note that $573$ is not a prime number.
Input
S
The string $S$ is given on the $1$st line. $( 1 \leq |S| \leq 1000 ) $
The string $S$ consists only of uppercase letters ('A'–'Z').
Output
Output, as an integer, the remainder when the number of distinct strings that can be made by the operation in the problem statement (excluding the input string $S$ itself) is divided by $573$.
Sample
Sample 1
Input
ABC
Output
5
The strings that can be made by swapping $2$ adjacent characters of the string "ABC" some number of times are the following $6$.
ABC ACB
BAC BCA
CAB CBA
However, the input string itself is not counted, so excluding "ABC", $5$ kinds can be made.
Sample 2
Input
DDDDDD
Output
0
No matter how many times you swap, nothing other than "DDDDDD" can be made.
The input string itself is not counted, so excluding "DDDDDD", the answer is $0$ kinds.
Sample 3
Input
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Output
551
$403291461126605635583999999$ kinds of strings can be made.
Do not forget the $\mod 573$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。