結果
問題 |
No.774 tatyamと素数大富豪
|
ユーザー |
![]() |
提出日時 | 2019-12-30 23:45:03 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,488 bytes |
コンパイル時間 | 2,105 ms |
コンパイル使用メモリ | 77,160 KB |
実行使用メモリ | 97,908 KB |
最終ジャッジ日時 | 2024-11-15 22:06:18 |
合計ジャッジ時間 | 30,963 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 4 WA * 2 TLE * 8 |
ソースコード
import java.util.*; public class Main { static int[] arr; static int n; static boolean[] used; static long max = -1; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); arr = new int[n]; used = new boolean[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } make(1, 0, used); System.out.println(max); } static void make(int count, long value, boolean[] used) { if (count > n) { if (isPrime(value)) { max = Math.max(max, value); } return; } int prev = 0; for (int i = 0; i < n; i++) { if (!used[i]) { if (prev == arr[i]) { continue; } prev = arr[i]; used[i] = true; long next; if (arr[i] >= 10) { next = value * 100 + arr[i]; } else { next = value * 10 + arr[i]; } make(count + 1, next, used); used[i] = false; } } } static boolean isPrime(long x) { if (x % 2 == 0) { return false; } for (int i = 3; i <= Math.sqrt(x); i += 2) { if (x % i == 0) { return false; } } return true; } }