結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:21:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 89 ms / 5,000 ms |
コード長 | 1,760 bytes |
コンパイル時間 | 472 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 82,204 KB |
最終ジャッジ日時 | 2025-03-20 20:23:56 |
合計ジャッジ時間 | 3,571 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
from collections import defaultdictdef sieve(n):if n < 2:return []sieve_list = [True] * (n + 1)sieve_list[0], sieve_list[1] = False, Falsefor i in range(2, int(n ** 0.5) + 1):if sieve_list[i]:sieve_list[i*i : n+1 : i] = [False] * len(sieve_list[i*i : n+1 : i])primes = [i for i, is_prime in enumerate(sieve_list) if is_prime]return primesdef main():K = int(input())N = int(input())primes_all = sieve(N)primes_in_range = [p for p in primes_all if K <= p <= N]if not primes_in_range:print() # Should not happen as per problem statementreturnhash_list = [9 if p % 9 == 0 else p % 9 for p in primes_in_range]max_length = 0start_indices = []left = 0count = defaultdict(int)for right in range(len(hash_list)):current_hash = hash_list[right]# Move left pointer to ensure all hashes in window are uniquewhile count[current_hash] > 0:left_hash = hash_list[left]count[left_hash] -= 1if count[left_hash] == 0:del count[left_hash]left += 1count[current_hash] += 1current_len = right - left + 1if current_len > max_length:max_length = current_lenstart_indices = [left]elif current_len == max_length:start_indices.append(left)# Determine the maximum prime among the start indicesmax_prime = -1for idx in start_indices:current_p = primes_in_range[idx]if current_p > max_prime:max_prime = current_pprint(max_prime)if __name__ == "__main__":main()