結果

問題 No.170 スワップ文字列(Easy)
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-03-30 19:35:15
言語 Java19
(openjdk 21)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 1,136 bytes
コンパイル時間 3,504 ms
コンパイル使用メモリ 75,264 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2023-08-24 16:12:44
合計ジャッジ時間 7,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,676 KB
testcase_01 AC 115 ms
55,856 KB
testcase_02 AC 117 ms
55,536 KB
testcase_03 AC 117 ms
55,788 KB
testcase_04 AC 116 ms
55,676 KB
testcase_05 AC 120 ms
55,604 KB
testcase_06 AC 117 ms
55,972 KB
testcase_07 AC 117 ms
55,736 KB
testcase_08 AC 120 ms
55,632 KB
testcase_09 AC 121 ms
55,792 KB
testcase_10 AC 122 ms
55,408 KB
testcase_11 AC 121 ms
55,680 KB
testcase_12 AC 119 ms
55,988 KB
testcase_13 AC 118 ms
55,932 KB
testcase_14 AC 118 ms
55,576 KB
testcase_15 AC 117 ms
55,888 KB
testcase_16 AC 116 ms
55,972 KB
testcase_17 AC 117 ms
55,408 KB
testcase_18 AC 118 ms
56,340 KB
testcase_19 AC 116 ms
55,860 KB
testcase_20 AC 117 ms
56,072 KB
testcase_21 AC 117 ms
56,004 KB
testcase_22 AC 115 ms
56,044 KB
testcase_23 AC 115 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.170 スワップ文字列(Easy)


import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No170 {
    
    static final Scanner sc = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        String s = sc.next();
        int n = s.length();
        int[] cnt = new int[26];
        for (int i=0; i<n; i++) {
            cnt[s.charAt(i)-'A']++;
        }
        int[] fact = new int[n+1];
        fact[1] = 1;
        for (int i=2; i<=n; i++) {
            fact[i] = fact[i-1]*i;
        }

        int ans = fact[n];
        for (int i=0; i<26; i++) {
            if (cnt[i] > 1) {
                ans /= fact[cnt[i]];
            }
        }
        out.println(ans-1);
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        sc.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0