結果
問題 | No.12 限定された素数 |
ユーザー | しらっ亭 |
提出日時 | 2015-07-10 20:43:06 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 1,480 ms / 5,000 ms |
コード長 | 1,131 bytes |
コンパイル時間 | 126 ms |
コンパイル使用メモリ | 10,864 KB |
実行使用メモリ | 61,268 KB |
最終ジャッジ日時 | 2023-08-15 23:04:12 |
合計ジャッジ時間 | 40,427 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,462 ms
61,204 KB |
testcase_01 | AC | 1,415 ms
61,084 KB |
testcase_02 | AC | 1,433 ms
61,124 KB |
testcase_03 | AC | 1,362 ms
61,092 KB |
testcase_04 | AC | 1,432 ms
61,212 KB |
testcase_05 | AC | 1,428 ms
61,208 KB |
testcase_06 | AC | 1,472 ms
61,124 KB |
testcase_07 | AC | 1,397 ms
61,088 KB |
testcase_08 | AC | 1,480 ms
61,204 KB |
testcase_09 | AC | 1,471 ms
61,060 KB |
testcase_10 | AC | 1,473 ms
61,196 KB |
testcase_11 | AC | 1,398 ms
61,128 KB |
testcase_12 | AC | 1,422 ms
61,268 KB |
testcase_13 | AC | 1,418 ms
61,040 KB |
testcase_14 | AC | 1,462 ms
61,264 KB |
testcase_15 | AC | 1,446 ms
61,096 KB |
testcase_16 | AC | 1,406 ms
61,224 KB |
testcase_17 | AC | 1,445 ms
61,248 KB |
testcase_18 | AC | 1,459 ms
61,096 KB |
testcase_19 | AC | 1,447 ms
61,124 KB |
testcase_20 | AC | 1,424 ms
61,156 KB |
testcase_21 | AC | 1,479 ms
61,056 KB |
testcase_22 | AC | 1,418 ms
61,196 KB |
testcase_23 | AC | 1,439 ms
61,212 KB |
testcase_24 | AC | 1,443 ms
61,160 KB |
testcase_25 | AC | 1,433 ms
61,236 KB |
ソースコード
def mark(s, x): for i in range(x + x, len(s), x): s[i] = False def sieve(n): s = [True] * n for x in range(2, int(n**0.5) + 1): if s[x]: mark(s, x) return [i for i in range(n) if s[i] and i > 1] def solve(A): MAX = 5000000 P = sieve(MAX) B = sum(1 << a for a in A) b2 = {str(c): 1 << c for c in range(10)} M = [sum(b2[c] for c in set(str(p))) for p in P] l = r = ps = s = 0 ans = -1 while r < len(M): sb = s & B if s - sb: if ps == B: if r == len(M) - 1: r1 = MAX else: r1 = P[r - 1] - 1 if l == 0: l1 = 1 else: l1 = P[l - 1] + 1 ans = max(ans, r1 - l1) l = r s = 0 else: ps = s s = ps | M[r] r += 1 if ps and ans == -1: return 4999999 return ans def main(): input() A = list(map(int, input().split())) print(solve(A)) if __name__ == '__main__': main()