結果

問題 No.171 スワップ文字列(Med)
ユーザー kenkooookenkoooo
提出日時 2015-03-24 22:25:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 74,632 KB
実行使用メモリ 60,816 KB
最終ジャッジ日時 2023-09-11 09:58:32
合計ジャッジ時間 5,166 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
60,356 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
		char[] input = scanner.next().toCharArray();
		scanner.close();

		int[] alphabets = new int[26];
		for (int i = 0; i < input.length; i++) {
			alphabets[(int) input[i] - 'A']++;
		}

		long ans = 1;
		PriorityQueue<Integer> multiply = new PriorityQueue<>();
		for (int i = 1; i <= input.length; i++) {
			multiply.add(i);
		}
		PriorityQueue<Integer> divders = new PriorityQueue<>();
		for (int i = 0; i < alphabets.length; i++) {
			for (int j = 1; j <= alphabets[i]; j++) {
				divders.add(j);
			}
		}

		while (!multiply.isEmpty() || !divders.isEmpty()) {
			if (!divders.isEmpty() && ans % divders.peek() == 0) {
				ans /= divders.poll();
			}
			if (!multiply.isEmpty() && ans < Integer.MAX_VALUE) {
				ans *= multiply.poll();
			}
			if (ans > Integer.MAX_VALUE) {
				ans %= 573;
			}
		}

		if (ans == 0) {
			ans += 573;
		}

		System.out.println(ans - 1);

	}
}
0