結果
| 問題 |
No.774 tatyamと素数大富豪
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-31 08:45:01 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,491 bytes |
| コンパイル時間 | 1,799 ms |
| コンパイル使用メモリ | 78,600 KB |
| 実行使用メモリ | 83,260 KB |
| 最終ジャッジ日時 | 2024-11-17 17:01:09 |
| 合計ジャッジ時間 | 14,398 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 9 WA * 2 TLE * 3 |
ソースコード
import java.util.*;
public class Main {
static int[] arr;
static int n;
static boolean[] used;
static TreeSet<Long> numbers = new TreeSet<>();
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);
for (long x : numbers) {
x *= -1;
if (isPrime(x)) {
System.out.println(x);
return;
}
}
System.out.println(-1);
}
static void make(int count, long value, boolean[] used) {
if (count > n) {
numbers.add(-value);
return;
}
for (int i = n - 1; i >= 0; i--) {
if (!used[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;
}
}
htensai