結果

問題 No.12 限定された素数
ユーザー こるこる
提出日時 2017-01-07 12:28:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 957 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 211,424 KB
最終ジャッジ日時 2023-08-22 16:00:38
合計ジャッジ時間 68,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,026 ms
206,904 KB
testcase_01 AC 4,150 ms
206,852 KB
testcase_02 AC 4,357 ms
206,760 KB
testcase_03 TLE -
testcase_04 AC 4,139 ms
206,960 KB
testcase_05 AC 4,627 ms
206,800 KB
testcase_06 AC 4,628 ms
206,768 KB
testcase_07 AC 4,842 ms
206,956 KB
testcase_08 AC 4,331 ms
206,804 KB
testcase_09 AC 4,260 ms
206,892 KB
testcase_10 AC 4,666 ms
206,804 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 AC 4,580 ms
206,760 KB
testcase_14 AC 4,117 ms
206,796 KB
testcase_15 AC 4,295 ms
206,796 KB
testcase_16 TLE -
testcase_17 AC 4,360 ms
206,964 KB
testcase_18 AC 4,144 ms
206,896 KB
testcase_19 AC 3,921 ms
206,916 KB
testcase_20 AC 4,199 ms
206,944 KB
testcase_21 AC 4,265 ms
206,960 KB
testcase_22 AC 4,241 ms
206,764 KB
testcase_23 AC 4,144 ms
206,836 KB
testcase_24 AC 4,245 ms
206,908 KB
testcase_25 AC 4,544 ms
206,968 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 range(len(s)):
        if not s[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 range(len(str(list[r]))):
                if str(list[r])[i] in a:
                    end_list[a.index(str(list[r])[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