結果
問題 |
No.8015 アンチローリングハッシュ
|
ユーザー |
![]() |
提出日時 | 2018-01-30 09:57:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 467 ms / 2,000 ms |
コード長 | 845 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 110,872 KB |
最終ジャッジ日時 | 2024-12-29 21:26:39 |
合計ジャッジ時間 | 6,259 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
#!/usr/bin/env pypy3 # -*- coding: utf-8 -*- import itertools import random import string MAX_L = 5 def compute_hash(s, a, b): h = 0 n = len(s) for i, c in enumerate(s): h += ((ord(c) % b) * pow(a, n - 1 - i, b)) % b h %= b return h def generate_random_string(digits, source=string.ascii_lowercase): return "".join(random.choice(source) for _ in range(digits)) def birthday_attack(a, b, digits=MAX_L): candidates = {generate_random_string(digits) for _ in range(2 * b)} f = lambda x: compute_hash(x, a, b) for s, t in itertools.combinations(candidates, r=2): if f(s) == f(t): return s, t else: assert False def main(): a, b = map(int, input().split()) s, t = birthday_attack(a, b) print(s) print(t) if __name__ == '__main__': main()