結果

問題 No.12 限定された素数
ユーザー こるこる
提出日時 2017-01-07 12:53:50
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 4,923 ms / 5,000 ms
コード長 902 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 209,640 KB
最終ジャッジ日時 2024-11-24 09:06:12
合計ジャッジ時間 120,624 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,107 ms
209,536 KB
testcase_01 AC 4,187 ms
209,412 KB
testcase_02 AC 4,152 ms
209,536 KB
testcase_03 AC 4,719 ms
209,408 KB
testcase_04 AC 4,194 ms
209,640 KB
testcase_05 AC 4,298 ms
209,432 KB
testcase_06 AC 4,362 ms
209,408 KB
testcase_07 AC 4,496 ms
209,408 KB
testcase_08 AC 4,487 ms
209,368 KB
testcase_09 AC 4,290 ms
209,500 KB
testcase_10 AC 4,221 ms
209,384 KB
testcase_11 AC 4,923 ms
209,408 KB
testcase_12 AC 4,571 ms
209,408 KB
testcase_13 AC 4,397 ms
209,464 KB
testcase_14 AC 4,229 ms
209,408 KB
testcase_15 AC 4,305 ms
209,408 KB
testcase_16 AC 4,896 ms
209,392 KB
testcase_17 AC 3,979 ms
209,408 KB
testcase_18 AC 4,035 ms
209,520 KB
testcase_19 AC 4,171 ms
209,408 KB
testcase_20 AC 4,240 ms
209,484 KB
testcase_21 AC 4,191 ms
209,280 KB
testcase_22 AC 4,244 ms
209,456 KB
testcase_23 AC 4,171 ms
209,320 KB
testcase_24 AC 4,128 ms
209,512 KB
testcase_25 AC 4,365 ms
209,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=[str(i)[0] for i in input().split()]
maxi=5000000
e=list(range(maxi+1))
e[1]=0
i=2
while i**2<=maxi:
    j=i+i
    while j<=maxi:
        e[j]=0
        j+=i
    i+=1
    while e[i]==0:
        i+=1
list=[]
for i in e:
    if i!=0: list.append(i)

sum_max=0
end_flag=False
def check(num):
    s=str(num)
    for i in s:
        if not i in a:
            return False
    return True


l=0
end_list=[0]*n
for r in range(len(list)):
    if check(list[r]):
        if sum(end_list)!=n:
            for i in str(list[r]):
                if i in a:
                    end_list[a.index(i)]=1
        if sum(end_list)==n:
            end_flag=True
            r_index= maxi if r==len(list)-1 else list[r+1]-1
            l_index= 1 if l==0 else list[l-1]+1
            sum_max=max(sum_max,(r_index-l_index))
    else:
        end_list=[0]*n
        l=r+1
print(sum_max if end_flag else -1)
0