結果
問題 | No.774 tatyamと素数大富豪 |
ユーザー | neko_the_shadow |
提出日時 | 2019-02-21 11:48:46 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,249 bytes |
コンパイル時間 | 2,377 ms |
コンパイル使用メモリ | 86,520 KB |
実行使用メモリ | 135,536 KB |
最終ジャッジ日時 | 2024-04-28 16:22:48 |
合計ジャッジ時間 | 32,782 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 142 ms
53,856 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 266 ms
54,784 KB |
testcase_04 | AC | 170 ms
41,908 KB |
testcase_05 | AC | 261 ms
44,864 KB |
testcase_06 | AC | 137 ms
41,056 KB |
testcase_07 | AC | 140 ms
41,224 KB |
testcase_08 | AC | 138 ms
41,556 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | AC | 1,785 ms
130,016 KB |
testcase_14 | AC | 586 ms
69,632 KB |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
ソースコード
import java.math.BigInteger; import java.util.ArrayDeque; import java.util.Deque; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int n = stdin.nextInt(); String[] a = new String[n]; IntStream.range(0, n).forEach(i -> a[i] = stdin.next()); Deque<String> strs = new ArrayDeque<>(); Deque<Integer> bits = new ArrayDeque<>(); strs.addLast(""); bits.addLast(0); BigInteger answer = new BigInteger("-1"); while (!strs.isEmpty()) { String str = strs.pollFirst(); int bit = bits.pollFirst(); if (bit == (1 << n) - 1) { BigInteger val = new BigInteger(str); if (val.isProbablePrime(1)) answer = answer.max(val); } else { for (int i = 0; i < n; i++) { if ((bit & (1 << i)) != 0) continue; strs.addLast(str + a[i]); bits.addLast(bit | (1 << i)); } } } System.out.println(answer); } }