問題一覧 > 通常問題

No.170 Swap String (Easy)

レベル : / AI推定難易度 : 151 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 444
作問者 : なお
お気に入りにしたユーザー ProblemId : 409 / 自分の提出
問題文最終更新日: 2026-06-25 01:10:16
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 93 (順位表) の他の問題:

Problem Statement

A string $S$ of at most $8$ characters is given as input.
Among the characters forming this string $S$, you may perform the operation "swap any $2$ adjacent characters" any number of times.
Find the number of distinct strings that can be made.

However, a string identical to the input string $S$ is not counted.

Input

S

The string $S$ is given on the $1$st line. $( 1 \leq |S| \leq 8 ) $
The string $S$ consists only of uppercase letters ('A'–'Z').

Output

Output the number of distinct strings that can be made by the operation in the problem statement (excluding the input string $S$ itself),
as an integer.

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, since the input string itself is not counted, $5$ distinct strings excluding "ABC" can be made.

Sample 2
Input
DDDDDD
Output
0

No matter how many times you swap, no string other than "DDDDDD" can be made.
Since the input string itself is not counted, the answer is $0$ distinct strings, excluding "DDDDDD".

Sample 3
Input
XYZYX
Output
29

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。