結果

問題 No.170 スワップ文字列(Easy)
ユーザー shinwisteriashinwisteria
提出日時 2017-03-31 15:22:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 3,160 ms
コンパイル使用メモリ 73,504 KB
実行使用メモリ 56,636 KB
最終ジャッジ日時 2023-09-21 10:38:33
合計ジャッジ時間 6,963 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
56,108 KB
testcase_01 AC 112 ms
56,084 KB
testcase_02 AC 114 ms
55,972 KB
testcase_03 AC 115 ms
56,636 KB
testcase_04 AC 113 ms
55,820 KB
testcase_05 AC 113 ms
55,656 KB
testcase_06 AC 112 ms
56,096 KB
testcase_07 AC 112 ms
55,872 KB
testcase_08 AC 113 ms
56,436 KB
testcase_09 AC 112 ms
55,436 KB
testcase_10 AC 112 ms
56,128 KB
testcase_11 AC 112 ms
55,808 KB
testcase_12 AC 111 ms
55,468 KB
testcase_13 AC 110 ms
55,656 KB
testcase_14 AC 114 ms
55,448 KB
testcase_15 AC 112 ms
55,968 KB
testcase_16 AC 114 ms
55,888 KB
testcase_17 AC 112 ms
55,828 KB
testcase_18 AC 113 ms
55,764 KB
testcase_19 AC 112 ms
56,328 KB
testcase_20 AC 113 ms
56,624 KB
testcase_21 AC 109 ms
56,252 KB
testcase_22 AC 110 ms
55,784 KB
testcase_23 AC 109 ms
56,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeMap;

public class Swapstring {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		StringBuilder S = new StringBuilder(s.nextLine());
		s.close();
		TreeMap<Character,Integer> str = new TreeMap<>();
		for(int i = 0;i < S.length();i++){
			char c = S.charAt(i);
			if(str.containsKey(c)){
				str.put(c, str.get(c)+1);
			}else{
				str.put(c, 1);
			}
		}
		int p = 1;
		while(str.size() != 0){
			char k = str.firstKey();
			p *= seki(str.get(k));
			str.remove(k);
		}
		int all = seki(S.length());
		System.out.println(all/p - 1);

	}
	static int seki(int k){
		int p = 1;
		for(int i = 1;i <= k;i++){
			p *= i;
		}
		return p;
	}

}
0