結果

問題 No.171 スワップ文字列(Med)
ユーザー uafr_cs
提出日時 2015-08-31 00:06:04
言語 Java
(openjdk 23)
結果
AC  
実行時間 165 ms / 1,000 ms
コード長 986 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 75,228 KB
実行使用メモリ 56,472 KB
最終ジャッジ日時 2024-07-18 15:46:53
合計ジャッジ時間 4,903 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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