結果

問題 No.171 スワップ文字列(Med)
ユーザー uafr_csuafr_cs
提出日時 2015-08-31 00:06:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 1,000 ms
コード長 986 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 73,004 KB
実行使用メモリ 59,844 KB
最終ジャッジ日時 2023-09-25 19:58:02
合計ジャッジ時間 4,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,248 KB
testcase_01 AC 119 ms
56,208 KB
testcase_02 AC 150 ms
56,032 KB
testcase_03 AC 120 ms
55,616 KB
testcase_04 AC 119 ms
56,120 KB
testcase_05 AC 126 ms
56,108 KB
testcase_06 AC 147 ms
56,304 KB
testcase_07 AC 150 ms
59,844 KB
testcase_08 AC 151 ms
57,648 KB
testcase_09 AC 149 ms
58,768 KB
testcase_10 AC 118 ms
55,636 KB
testcase_11 AC 118 ms
56,156 KB
testcase_12 AC 117 ms
55,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static final int SIZE = 26;
	
	public static BigInteger fact(int b){
		BigInteger ret = BigInteger.ONE;
		
		for(int i = 1; i <= b; i++){
			ret = ret.multiply(BigInteger.valueOf(i));
		}
		
		return ret;
	}
	
	/* 573 = 3 * 191 なので, mod 3 と mod 191 の結果から, mod 573 の結果を中国剰余定理で合成すればいい. */
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final char[] inputs = sc.next().toCharArray();
		
		int[] counter = new int[SIZE];
		for(final char c : inputs){
			counter[c - 'A']++;
		}
		
		BigInteger answer = fact(inputs.length);
		for(int i = 0; i < SIZE; i++){
			if(counter[i] == 0){ continue; }
			
			answer = answer.divide(fact(counter[i]));
		}
		answer = answer.subtract(BigInteger.ONE);
		
		System.out.println(answer.mod(BigInteger.valueOf(573)));
	}
	
}
0