結果

問題 No.6 使いものにならないハッシュ
ユーザー AAAR SalmonAAAR Salmon
提出日時 2021-05-22 17:52:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 670 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 78,336 KB
最終ジャッジ日時 2024-04-18 22:38:50
合計ジャッジ時間 3,984 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,096 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 83 ms
77,696 KB
testcase_03 WA -
testcase_04 AC 81 ms
75,648 KB
testcase_05 AC 94 ms
76,800 KB
testcase_06 WA -
testcase_07 AC 87 ms
77,184 KB
testcase_08 AC 88 ms
77,568 KB
testcase_09 WA -
testcase_10 AC 39 ms
52,096 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 91 ms
77,568 KB
testcase_20 AC 94 ms
77,440 KB
testcase_21 AC 68 ms
69,632 KB
testcase_22 WA -
testcase_23 AC 95 ms
77,952 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 97 ms
77,696 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stderr


def hash(n: int):
	res = n
	while res >= 10:
		n = res
		res = 0
		while n > 0:
			res += n % 10
			n //= 10
	return res

K = int(input())
N = int(input())

isprime = [True] * (N + 1)
isprime[0] = isprime[1] = False
for i in range(2, N + 1):
	if isprime[i]:
		for j in range(i * 2, N + 1, i):
			isprime[j] = False

maxlen = len = 0
bkt = [-1] * 10
ans = 0

for i in range(K, N + 1):
	if not isprime[i]:
		continue
	h = hash(i)
	if bkt[h] != -1:
		for j in range(10):
			rem = bkt[h]
			if 0 <= bkt[j] <= rem:
				bkt[j] = -1
				len -= 1
	bkt[h] = i
	len += 1
	if len >= maxlen:
		ans = min(v for v in bkt if v >= 0)
		maxlen = len

print(ans)
0