結果

問題 No.12 限定された素数
ユーザー ytftytft
提出日時 2022-11-02 23:24:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 642 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 118,684 KB
最終ジャッジ日時 2023-09-24 10:28:31
合計ジャッジ時間 41,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,164 ms
117,300 KB
testcase_01 AC 3,794 ms
118,104 KB
testcase_02 WA -
testcase_03 AC 2,543 ms
116,772 KB
testcase_04 AC 3,697 ms
117,544 KB
testcase_05 AC 3,340 ms
118,464 KB
testcase_06 AC 3,702 ms
117,384 KB
testcase_07 AC 3,531 ms
117,452 KB
testcase_08 AC 3,323 ms
118,028 KB
testcase_09 AC 4,057 ms
117,544 KB
testcase_10 AC 3,388 ms
118,564 KB
testcase_11 AC 3,470 ms
117,536 KB
testcase_12 AC 3,713 ms
118,000 KB
testcase_13 AC 3,524 ms
117,708 KB
testcase_14 AC 3,295 ms
118,684 KB
testcase_15 AC 3,526 ms
117,680 KB
testcase_16 AC 3,724 ms
118,524 KB
testcase_17 WA -
testcase_18 AC 3,539 ms
117,648 KB
testcase_19 AC 3,402 ms
117,688 KB
testcase_20 AC 3,475 ms
118,084 KB
testcase_21 AC 3,567 ms
118,072 KB
testcase_22 AC 3,460 ms
117,544 KB
testcase_23 AC 3,278 ms
117,188 KB
testcase_24 AC 3,717 ms
117,872 KB
testcase_25 AC 3,554 ms
118,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
rang=5*10**6
isPrime=[1 for i in range(rang+1)]
isPrime[1]=0
for i in range(2,rang+1):
	if isPrime[i]:
		for j in range(i*2,rang+1,i):
			isPrime[j]=0
N=int(input())
A=list(map(int,input().split()))
target=[0 for i in range(10)]
used=[0 for i in range(10)]
for i in A:
	target[i]=1
K,ans=1,0
for L in range(1,rang+1):
	for i in str(L):
		if isPrime[L]:
			used[int(i)]+=1
	while K<L and any([used[i]>0 and target[i]==0 for i in range(10)]):
		if isPrime[K]:
			for i in str(K):
				used[int(i)]-=1
		K+=1
	if all([(used[i]==0)^target[i] for i in range(10)]):
		ans=max(ans,L-K)
print(ans)
0