結果
問題 | No.774 tatyamと素数大富豪 |
ユーザー |
👑 |
提出日時 | 2019-01-25 03:08:35 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,309 ms / 2,000 ms |
コード長 | 1,842 bytes |
コンパイル時間 | 3,532 ms |
コンパイル使用メモリ | 91,448 KB |
実行使用メモリ | 55,256 KB |
最終ジャッジ日時 | 2024-09-16 04:45:22 |
合計ジャッジ時間 | 11,937 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 14 |
ソースコード
import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.math.*; import java.util.*; import java.io.*; public class y774 { public static void main(String[] args) { new y774().run(); } Scanner in = new Scanner(System.in); void _out(Object...os) { System.out.println(deepToString(os)); } void _err(Object...os) { System.err.println(deepToString(os)); } int N; int[] A; int[] work; void run() { for (; in.hasNext(); ) { N = in.nextInt(); A = new int[N]; for (int i = 0; i < N; ++i) { A[i] = in.nextInt(); } sort(A); work = new int[N]; BigInteger ans = valueOf(-1); do { if (N >= 2 && (A[N - 1] % 2 == 0 || A[N - 1] % 5 == 0)) { continue; } String str = ""; for (int i = 0; i < N; ++i) { str += Integer.toString(A[i]); } BigInteger x = new BigInteger(str); if (ans.compareTo(x) < 0) { if (x.isProbablePrime(100)) { ans = x; } } } while (nextPermutation()); System.out.println(ans); } } boolean nextPermutation() { for (int i = N - 2; i >= 0; --i) { if (A[i] < A[i + 1]) { for (int j = N - 1; j > i; --j) { if (A[i] < A[j]) { int workLen = 0; work[workLen++] = A[j]; for (int k = N - 1; k > j; --k) { work[workLen++] = A[k]; } work[workLen++] = A[i]; for (int k = j - 1; k > i; --k) { work[workLen++] = A[k]; } for (int k = i; k < N; ++k) { A[k] = work[k - i]; } return true; } } } } return false; } }