結果
問題 | No.12 限定された素数 |
ユーザー | taisuke |
提出日時 | 2023-02-22 17:13:44 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,342 bytes |
コンパイル時間 | 113 ms |
コンパイル使用メモリ | 11,052 KB |
実行使用メモリ | 41,928 KB |
最終ジャッジ日時 | 2023-09-30 00:44:55 |
合計ジャッジ時間 | 43,177 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,567 ms
41,792 KB |
testcase_01 | AC | 1,522 ms
41,808 KB |
testcase_02 | AC | 1,542 ms
41,720 KB |
testcase_03 | AC | 1,469 ms
41,712 KB |
testcase_04 | AC | 1,537 ms
41,808 KB |
testcase_05 | AC | 1,525 ms
41,744 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 1,532 ms
41,704 KB |
testcase_09 | AC | 1,548 ms
41,720 KB |
testcase_10 | AC | 1,562 ms
41,720 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 1,552 ms
41,736 KB |
testcase_18 | AC | 1,530 ms
41,740 KB |
testcase_19 | AC | 1,536 ms
41,748 KB |
testcase_20 | AC | 1,538 ms
41,784 KB |
testcase_21 | AC | 1,546 ms
41,884 KB |
testcase_22 | AC | 1,531 ms
41,732 KB |
testcase_23 | AC | 1,545 ms
41,776 KB |
testcase_24 | AC | 1,557 ms
41,752 KB |
testcase_25 | WA | - |
ソースコード
def Eratosthenes(n): sieve = [True] * ((n + 1) // 2) for i in range(1, (int(n ** 0.5) + 1) // 2): if sieve[i]: for j in range(i * 3 + 1, (n + 1) // 2, i * 2 + 1): sieve[j] = False res = [i * 2 + 1 for i, s in enumerate(sieve) if s] res[0] = 2 return res def check(nums, used, n): cnt = [0, 0] for i in range(10): if used[i] > 0: cnt[nums[i]] += 1 if cnt[0] > 0: return -1 if cnt[1] < n: return 0 return 1 def getDigits(x): ret = [] while x > 0: ret.append(x % 10) x //= 10 return ret n = int(input()) a = list(map(int, input().split())) MAX = 5000000 prime = Eratosthenes(MAX) nums = [0] * 10 for i in a: nums[i] = 1 used = [0] * 10 idx = 0 l = 1 k = 1 ans = -1 prime.append(MAX) state = 0 pre = 0 while idx < len(prime) - 1: d = [] while state != -1: pre = state k = prime[idx] d.clear() d = getDigits(k) for i in d: used[i] += 1 state = check(nums, used, n) idx += 1 if idx >= len(prime) - 1: pre = state break if pre == 1: ans = max(ans, k - 1 - l) else: l = k + 1 used = [0] * 10 state = 0 if pre == 1: ans = max(ans, MAX - l) print(ans)