結果

問題 No.12 限定された素数
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-23 23:48:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,181 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 193,276 KB
最終ジャッジ日時 2023-09-21 19:52:04
合計ジャッジ時間 18,046 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 607 ms
193,016 KB
testcase_01 AC 633 ms
192,824 KB
testcase_02 AC 574 ms
192,828 KB
testcase_03 AC 538 ms
192,268 KB
testcase_04 AC 582 ms
192,892 KB
testcase_05 AC 669 ms
192,968 KB
testcase_06 AC 625 ms
193,276 KB
testcase_07 AC 633 ms
192,988 KB
testcase_08 AC 644 ms
192,640 KB
testcase_09 AC 630 ms
192,796 KB
testcase_10 AC 651 ms
192,924 KB
testcase_11 WA -
testcase_12 AC 634 ms
192,976 KB
testcase_13 AC 639 ms
192,844 KB
testcase_14 AC 659 ms
192,768 KB
testcase_15 AC 676 ms
192,928 KB
testcase_16 AC 640 ms
192,736 KB
testcase_17 AC 567 ms
192,572 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 595 ms
193,044 KB
testcase_21 AC 636 ms
192,816 KB
testcase_22 AC 604 ms
193,112 KB
testcase_23 AC 607 ms
192,752 KB
testcase_24 AC 611 ms
193,060 KB
testcase_25 AC 711 ms
192,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = set(map(int, input().split()))

def primeList():
    isPrime = [True] * 5000001
    now = 0
    primeRange = [0] * 5000001
    primes = []
    for i in range(2, 5000001):
        if isPrime[i]:
            primes.append(i)
            now += 1
            k = i
            while k <= 5000000:
                isPrime[k] = False
                k += i
        primeRange[i] = now

    return list(primes), primeRange

primes, iToRange = primeList()
gapIndex = []
for i in range(5000000):
    if iToRange[i] != iToRange[i + 1]:
        gapIndex.append(i)

M = len(primes)
ans = 0
left = 0
while left < M:
    V = set()
    right = 0
    for i in range(left, M):
        nums = set(map(int, str(primes[i])))

        if nums.issubset(V):
            continue

        newV = V.union(nums)
        if len(newV & A) == len(newV):
            V = newV
        else:
            right = i
            break
    else:
        if V == A:
            ans = max(ans, 5000000 - left - 1)
            break

    if V == A:
        ans = max(ans, gapIndex[right] - gapIndex[left - 1] - 2)
    left = max(right + 1, left + 1)

if ans == 0:
    print(-1)
else:
    print(ans)
0