結果
問題 | No.3015 アンチローリングハッシュ |
ユーザー | はむ吉🐹 |
提出日時 | 2016-04-12 21:47:20 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,020 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,388 KB |
実行使用メモリ | 91,536 KB |
最終ジャッジ日時 | 2024-04-15 00:44:52 |
合計ジャッジ時間 | 4,395 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
65,408 KB |
testcase_01 | AC | 55 ms
65,536 KB |
testcase_02 | AC | 56 ms
65,536 KB |
testcase_03 | AC | 57 ms
65,536 KB |
testcase_04 | AC | 59 ms
65,792 KB |
testcase_05 | RE | - |
testcase_06 | AC | 103 ms
79,104 KB |
testcase_07 | AC | 71 ms
71,064 KB |
testcase_08 | AC | 138 ms
82,944 KB |
testcase_09 | AC | 133 ms
81,792 KB |
testcase_10 | AC | 193 ms
85,760 KB |
testcase_11 | AC | 250 ms
91,400 KB |
testcase_12 | AC | 162 ms
84,920 KB |
testcase_13 | AC | 180 ms
83,200 KB |
testcase_14 | AC | 141 ms
81,112 KB |
testcase_15 | AC | 73 ms
73,688 KB |
testcase_16 | AC | 248 ms
90,876 KB |
testcase_17 | AC | 139 ms
82,100 KB |
testcase_18 | AC | 209 ms
91,480 KB |
testcase_19 | AC | 196 ms
88,572 KB |
testcase_20 | AC | 203 ms
91,536 KB |
testcase_21 | AC | 182 ms
85,824 KB |
testcase_22 | AC | 100 ms
79,396 KB |
ソースコード
#!/usr/bin/env pypy3 # -*- coding: utf-8 -*- import itertools import random import string MAX_L = 4 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 generate_random_pair(digits): s = "" t = "" while s == t: s = generate_random_string(digits) t = generate_random_string(digits) return s, t def birthday_attack(a, b, digits=MAX_L): candidates = {generate_random_string(digits) for _ in range(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()