結果

問題 No.170 スワップ文字列(Easy)
ユーザー htensaihtensai
提出日時 2019-11-27 09:18:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 2,508 ms
コンパイル使用メモリ 79,472 KB
実行使用メモリ 41,420 KB
最終ジャッジ日時 2024-04-25 07:59:33
合計ジャッジ時間 7,153 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,100 KB
testcase_01 AC 130 ms
40,804 KB
testcase_02 AC 128 ms
41,160 KB
testcase_03 AC 128 ms
41,292 KB
testcase_04 AC 127 ms
41,152 KB
testcase_05 AC 134 ms
41,124 KB
testcase_06 AC 117 ms
40,052 KB
testcase_07 AC 113 ms
40,052 KB
testcase_08 AC 131 ms
41,268 KB
testcase_09 AC 132 ms
40,836 KB
testcase_10 AC 129 ms
41,132 KB
testcase_11 AC 127 ms
40,968 KB
testcase_12 AC 128 ms
41,420 KB
testcase_13 AC 130 ms
41,060 KB
testcase_14 AC 128 ms
41,172 KB
testcase_15 AC 127 ms
40,960 KB
testcase_16 AC 128 ms
41,084 KB
testcase_17 AC 125 ms
40,908 KB
testcase_18 AC 126 ms
41,208 KB
testcase_19 AC 125 ms
41,208 KB
testcase_20 AC 130 ms
41,232 KB
testcase_21 AC 127 ms
41,408 KB
testcase_22 AC 131 ms
40,804 KB
testcase_23 AC 129 ms
41,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		HashMap<Character, Integer> map = new HashMap<>();
		for (char c : arr) {
		    if (map.containsKey(c)) {
		        map.put(c, map.get(c) + 1);
		    } else {
		        map.put(c, 1);
		    }
		}
		long base = kaijo(arr.length);
		for (int x : map.values()) {
		    base /= kaijo(x);
		}
		System.out.println(base - 1);
	}
	
	static long kaijo(long x) {
	    if (x <= 1) {
	        return 1;
	    } else {
	        return x * kaijo(x - 1);
	    }
	}
}
0