結果

問題 No.170 スワップ文字列(Easy)
ユーザー atkrymatkrym
提出日時 2016-10-23 23:53:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 3,680 ms
コンパイル使用メモリ 72,516 KB
実行使用メモリ 56,620 KB
最終ジャッジ日時 2023-08-24 16:35:06
合計ジャッジ時間 6,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,760 KB
testcase_01 AC 118 ms
55,764 KB
testcase_02 AC 117 ms
56,296 KB
testcase_03 AC 118 ms
55,784 KB
testcase_04 AC 117 ms
55,772 KB
testcase_05 AC 116 ms
55,772 KB
testcase_06 AC 116 ms
56,380 KB
testcase_07 AC 117 ms
55,832 KB
testcase_08 AC 117 ms
55,368 KB
testcase_09 AC 118 ms
55,772 KB
testcase_10 AC 116 ms
54,340 KB
testcase_11 AC 117 ms
55,544 KB
testcase_12 AC 119 ms
56,096 KB
testcase_13 AC 118 ms
55,964 KB
testcase_14 AC 118 ms
55,508 KB
testcase_15 AC 117 ms
56,060 KB
testcase_16 AC 116 ms
56,272 KB
testcase_17 AC 118 ms
56,620 KB
testcase_18 AC 117 ms
56,244 KB
testcase_19 AC 116 ms
55,972 KB
testcase_20 AC 118 ms
56,056 KB
testcase_21 AC 117 ms
56,124 KB
testcase_22 AC 117 ms
55,940 KB
testcase_23 AC 119 ms
55,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        int l = s.length();
        Map<String, Integer> map = new HashMap<>();
 
        for (int i = 0;i < l;i++) {
            String tmp = s.substring(i, i+1);
            if (map.containsKey(tmp)) {
                map.put(tmp, map.get(tmp)+1);
            } else {
                map.put(tmp, 1);
            }
        }
        
        int ret = fact(l);
        
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            ret /= fact(entry.getValue());
        }
        
        System.out.println(ret-1);
    }

    private static int fact(int n) {
        int ret = 1;
        for (int i = 1;i <= n;i++) {
            ret *= i;
        }
        return ret;
    }
}
0