結果

問題 No.12 限定された素数
ユーザー chocoruskchocorusk
提出日時 2020-09-07 23:02:28
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 514 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 155,576 KB
最終ジャッジ日時 2023-08-19 17:16:33
合計ジャッジ時間 15,181 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 459 ms
155,308 KB
testcase_01 AC 459 ms
155,308 KB
testcase_02 AC 461 ms
155,384 KB
testcase_03 AC 463 ms
155,360 KB
testcase_04 AC 466 ms
155,248 KB
testcase_05 AC 459 ms
155,344 KB
testcase_06 AC 460 ms
155,576 KB
testcase_07 AC 461 ms
155,128 KB
testcase_08 AC 457 ms
155,268 KB
testcase_09 AC 458 ms
155,436 KB
testcase_10 AC 458 ms
155,216 KB
testcase_11 AC 451 ms
155,384 KB
testcase_12 AC 458 ms
155,136 KB
testcase_13 AC 455 ms
155,376 KB
testcase_14 AC 455 ms
155,364 KB
testcase_15 AC 461 ms
155,228 KB
testcase_16 AC 448 ms
155,400 KB
testcase_17 AC 468 ms
155,216 KB
testcase_18 AC 446 ms
155,260 KB
testcase_19 AC 514 ms
155,328 KB
testcase_20 AC 462 ms
155,276 KB
testcase_21 AC 458 ms
155,084 KB
testcase_22 AC 455 ms
155,376 KB
testcase_23 AC 451 ms
155,324 KB
testcase_24 AC 453 ms
155,088 KB
testcase_25 AC 470 ms
155,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_sieve(n):
    isprime=[True]*(n+1)
    isprime[0]=False
    isprime[1]=False
    for i in range(2, n+1):
        if isprime[i]:
            for j in range(2*i, n+1, i):
                isprime[j]=False
    return isprime
n=int(input())
a=list(map(int, input().split()))
b=0
for x in a:
    b^=(1<<x)
isprime=prime_sieve(5000000)
def digit(x):
    if not isprime[x]:
        return 0
    b=0
    while x>0:
        b|=(1<<(x%10))
        x//=10
    return b
d=[digit(i) for i in range(5000001)]
pr=0
s=0
ans=-1
for i, x in enumerate(d):
    if (x|b)==b:
        s|=x
        continue
    if s==b:
        ans=max(ans, i-pr-2)
    pr=i
    s=0
if s==b:
    ans=max(ans, 4999999-pr)
print(ans)
0