結果
| 問題 |
No.515 典型LCP
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:59:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,739 bytes |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 81,676 KB |
| 実行使用メモリ | 140,792 KB |
| 最終ジャッジ日時 | 2025-06-12 20:03:05 |
| 合計ジャッジ時間 | 4,830 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 TLE * 10 |
ソースコード
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
N = int(data[idx])
idx += 1
strings = []
for _ in range(N):
strings.append(data[idx])
idx += 1
base1 = 911382629
mod1 = 10**18 + 3
base2 = 3571428571
mod2 = 10**18 + 7
hash_list = []
len_list = []
for s in strings:
l = len(s)
len_list.append(l)
current1 = 0
current2 = 0
prefix = [(0, 0)]
for c in s:
current1 = (current1 * base1 + ord(c)) % mod1
current2 = (current2 * base2 + ord(c)) % mod2
prefix.append((current1, current2))
hash_list.append(prefix)
M = int(data[idx])
x = int(data[idx + 1])
d = int(data[idx + 2])
idx += 3
n = N
sum_total = 0
for _ in range(M):
x_val = x
denominator = n - 1
i = (x_val // denominator) + 1
j = (x_val % denominator) + 1
if i > j:
i, j = j, i
else:
j += 1
a = i - 1
b = j - 1
ha = hash_list[a]
hb = hash_list[b]
len_a = len_list[a]
len_b = len_list[b]
min_len = min(len_a, len_b)
low = 0
high = min_len
lcp = 0
while low <= high:
mid = (low + high) // 2
if ha[mid][0] == hb[mid][0] and ha[mid][1] == hb[mid][1]:
lcp = mid
low = mid + 1
else:
high = mid - 1
sum_total += lcp
x = (x + d) % (n * (n - 1))
print(sum_total)
if __name__ == '__main__':
main()
gew1fw