結果

問題 No.3014 多項式ハッシュに関する教育的な問題
ユーザー ちーぴんちーぴん
提出日時 2023-10-01 15:33:22
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 517 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 849,488 KB
最終ジャッジ日時 2023-10-01 15:33:30
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)
import string
P = int(input())
B = int(input())

def hash(S):
    res = 0
    for s in S:
        res = (res * B + s) % P
    return res

D1 = {'': 0}
D2 = {}

def dfs(s):
    v = (D1[s[:-1]] + ord(s[-1])) % P
    D1[s] = v
    if v in D2:
        print(s)
        print(D2[v])
        exit()
    else:
        D2[v] = s
    if len(s) == 10**5:
        return
    for c in string.ascii_lowercase:
        dfs(s+c)

for c in string.ascii_lowercase:
    dfs(c)
0