結果

問題 No.6 使いものにならないハッシュ
ユーザー tnodinotnodino
提出日時 2022-01-30 15:16:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 82,140 KB
最終ジャッジ日時 2023-09-02 01:38:52
合計ジャッジ時間 5,780 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,876 KB
testcase_01 AC 84 ms
71,840 KB
testcase_02 AC 121 ms
82,140 KB
testcase_03 AC 109 ms
78,268 KB
testcase_04 AC 114 ms
78,408 KB
testcase_05 AC 112 ms
78,332 KB
testcase_06 AC 116 ms
79,208 KB
testcase_07 AC 110 ms
78,992 KB
testcase_08 AC 106 ms
79,096 KB
testcase_09 AC 112 ms
79,628 KB
testcase_10 AC 86 ms
71,832 KB
testcase_11 AC 111 ms
78,108 KB
testcase_12 AC 113 ms
79,640 KB
testcase_13 AC 104 ms
79,144 KB
testcase_14 AC 109 ms
79,248 KB
testcase_15 AC 114 ms
79,184 KB
testcase_16 AC 106 ms
79,264 KB
testcase_17 AC 113 ms
80,136 KB
testcase_18 AC 118 ms
81,348 KB
testcase_19 AC 116 ms
79,984 KB
testcase_20 AC 113 ms
79,600 KB
testcase_21 AC 106 ms
78,044 KB
testcase_22 AC 115 ms
79,732 KB
testcase_23 AC 114 ms
79,424 KB
testcase_24 AC 112 ms
79,668 KB
testcase_25 AC 110 ms
78,876 KB
testcase_26 AC 125 ms
80,680 KB
testcase_27 AC 113 ms
79,688 KB
testcase_28 AC 109 ms
78,580 KB
testcase_29 AC 116 ms
80,360 KB
testcase_30 AC 119 ms
80,380 KB
testcase_31 AC 112 ms
79,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
def SieveofEratosthenes(N):
    P = [0] * (N+1)
    P[0] = P[1] = -1
    for i in range(2,N+1):
        if P[i] == 0:
            k = i
            while k <= N:
                P[k] = i
                k += i
            P[i] = 0
    return P

def hash(N):
    if N in dic:
        return dic[N]
    x = N
    S = 0
    while x:
        S += x % 10
        x //= 10
    dic[N] = hash(S)
    return dic[N]

K = int(input())
N = int(input())
P = SieveofEratosthenes(N)
C = []
for i in range(K,N+1):
    if P[i] == 0:
        C.append(i)
dic = {}
for i in range(10):
    dic[i] = i
M = len(C)
F = []
for i in range(M):
    F.append(hash(C[i]))
dic = defaultdict(int)
Left = 0
Length = 0
ans = 0
for Right in range(M):
    dic[F[Right]] += 1
    while dic[F[Right]] >= 2:
        dic[F[Left]] -= 1
        Left += 1
    if Right - Left + 1 >= Length:
        Length = Right - Left + 1
        ans = C[Left]
print(ans)
0