結果

問題 No.171 スワップ文字列(Med)
ユーザー GrenacheGrenache
提出日時 2016-05-27 22:54:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 1,000 ms
コード長 1,107 bytes
コンパイル時間 3,502 ms
コンパイル使用メモリ 77,828 KB
実行使用メモリ 48,268 KB
最終ジャッジ日時 2024-04-16 17:59:00
合計ジャッジ時間 5,988 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
41,292 KB
testcase_01 AC 128 ms
40,888 KB
testcase_02 AC 146 ms
42,428 KB
testcase_03 AC 126 ms
41,312 KB
testcase_04 AC 128 ms
41,264 KB
testcase_05 AC 139 ms
42,060 KB
testcase_06 AC 146 ms
43,704 KB
testcase_07 AC 157 ms
47,628 KB
testcase_08 AC 153 ms
47,756 KB
testcase_09 AC 151 ms
48,268 KB
testcase_10 AC 127 ms
40,912 KB
testcase_11 AC 131 ms
41,024 KB
testcase_12 AC 128 ms
41,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


public class Main_yukicoder171 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int[] a = new int[26];
        for (char c : s) {
        	a[c - 'A']++;
        }

        preCombi(n);
        int ret = 1;
        for (int e : a) {
//        	System.out.printf("%d %d\n", n, e);
        	ret = (int)(ret * combination(n, e) % MOD);
        	n -= e;
        }

        System.out.println((ret - 1 + MOD) % MOD);

        sc.close();
    }

	private static int MOD = 573;
	private static long[][] cache;

	private static void preCombi(int size) {
		cache = new long[size + 1][];
		for (int i = 0; i <= size; i++) {
			cache[i] = new long[i + 1];
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i) {
					cache[i][j] = 1;
				} else {
					cache[i][j] = (cache[i - 1][j] + cache[i - 1][j - 1]) % MOD;
				}
			}
		}
	}

	private static long combination(int n, int r) {
		r = Math.min(n - r, r);
		if (r < 0) {
			return 0;
		}

		return cache[n][r];
	}
}
0