結果

問題 No.170 スワップ文字列(Easy)
ユーザー rn4rurn4ru
提出日時 2016-04-15 07:14:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 844 bytes
コンパイル時間 2,188 ms
コンパイル使用メモリ 75,188 KB
実行使用メモリ 56,456 KB
最終ジャッジ日時 2023-08-24 16:28:33
合計ジャッジ時間 6,199 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,524 KB
testcase_01 AC 119 ms
56,052 KB
testcase_02 AC 122 ms
55,948 KB
testcase_03 AC 117 ms
55,444 KB
testcase_04 AC 117 ms
55,452 KB
testcase_05 AC 117 ms
55,944 KB
testcase_06 AC 117 ms
55,900 KB
testcase_07 AC 119 ms
55,560 KB
testcase_08 AC 119 ms
56,116 KB
testcase_09 AC 119 ms
55,808 KB
testcase_10 AC 119 ms
55,936 KB
testcase_11 AC 118 ms
54,228 KB
testcase_12 AC 119 ms
56,076 KB
testcase_13 AC 120 ms
56,456 KB
testcase_14 AC 119 ms
55,752 KB
testcase_15 AC 119 ms
55,744 KB
testcase_16 AC 119 ms
56,192 KB
testcase_17 AC 118 ms
55,992 KB
testcase_18 AC 118 ms
56,084 KB
testcase_19 AC 118 ms
55,744 KB
testcase_20 AC 119 ms
55,868 KB
testcase_21 AC 122 ms
55,776 KB
testcase_22 AC 118 ms
55,796 KB
testcase_23 AC 119 ms
55,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.nextLine();
		System.out.println(new Solver().solve(S));
	}

}

class Solver {
	public String solve(String S) {
		int length = S.length();
		char[] cc = S.toCharArray();
		Map<Character, Integer> map = new HashMap<>();
		for (int i = 0; i < cc.length; i++) {
			if (map.containsKey(cc[i])) {
				int r = map.get(cc[i]);
				map.put(cc[i], r + 1);
			} else {
				map.put(cc[i], 1);
			}
		}
		int ans = factrial(length);
		for (int i : map.values()) {
			ans /= factrial(i);
		}
		return String.valueOf(ans - 1);
	}

	private int factrial(int length) {
		int ans = 1;
		for (int i = 1; i <= length; i++) {
			ans *= i;
		}
		return ans;
	}
}
0