結果
問題 | No.515 典型LCP |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:09:45 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,610 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 102,444 KB |
最終ジャッジ日時 | 2025-03-20 21:10:42 |
合計ジャッジ時間 | 14,325 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 TLE * 2 |
ソースコード
base = 911382629mod = 10**18 + 3def main():import sysinput = sys.stdin.readdata = input().split()ptr = 0n = int(data[ptr])ptr += 1strings = []prefix_hashes = []for _ in range(n):s = data[ptr]ptr +=1m = len(s)h = [0] * (m + 1)for i in range(m):c = ord(s[i]) - ord('a') + 1h[i+1] = (h[i] * base + c) % modstrings.append(s)prefix_hashes.append(h)m_queries = int(data[ptr])x = int(data[ptr+1])d = int(data[ptr+2])ptr +=3sum_result = 0modulus = n * (n - 1)for _ in range(m_queries):current_x = xn_minus_1 = n - 1i_part = (current_x // n_minus_1) + 1j_part = (current_x % n_minus_1) + 1if i_part > j_part:i = j_partj = i_partelse:i = i_partj = j_part + 1a = i - 1b = j - 1len_a = len(strings[a])len_b = len(strings[b])min_len = min(len_a, len_b)ha = prefix_hashes[a]hb = prefix_hashes[b]low = 0high = min_lenbest = 0while low <= high:mid = (low + high) // 2if ha[mid] == hb[mid]:best = midlow = mid + 1else:high = mid - 1sum_result += bestx = (current_x + d) % modulusprint(sum_result)if __name__ == '__main__':main()