結果
問題 |
No.171 スワップ文字列(Med)
|
ユーザー |
![]() |
提出日時 | 2015-03-24 22:27:01 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,074 bytes |
コンパイル時間 | 2,164 ms |
コンパイル使用メモリ | 77,928 KB |
実行使用メモリ | 46,580 KB |
最終ジャッジ日時 | 2024-06-29 00:34:37 |
合計ジャッジ時間 | 5,094 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 TLE * 1 -- * 6 |
ソースコード
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; } } ans %= 573; if (ans == 0) { ans += 573; } System.out.println(ans - 1); } }