結果
| 問題 |
No.958 たぷりすたべる (回文)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:42:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,141 bytes |
| コンパイル時間 | 317 ms |
| コンパイル使用メモリ | 82,552 KB |
| 実行使用メモリ | 83,116 KB |
| 最終ジャッジ日時 | 2025-06-12 18:42:59 |
| 合計ジャッジ時間 | 5,343 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 TLE * 1 -- * 50 |
ソースコード
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
N = int(data[idx])
idx += 1
K = int(data[idx])
idx += 1
Q = int(data[idx])
idx += 1
S = data[idx]
idx += 1
queries = list(map(int, data[idx:idx+Q]))
is_palindrome = S == S[::-1]
if is_palindrome:
for A in queries:
x = A
r_boundary = min(x - 1, K * N - x)
print(2 * r_boundary + 1)
else:
N_val = N
r_infinite = [0] * N_val
for pos in range(N_val):
r = 0
while True:
left = (pos - (r + 1)) % N_val
right = (pos + (r + 1)) % N_val
if S[left] == S[right]:
r += 1
else:
break
r_infinite[pos] = r
for A in queries:
x = A
pos_in_S = (x - 1) % N_val
r = r_infinite[pos_in_S]
r_boundary = min(x - 1, K * N_val - x)
ans = 2 * min(r, r_boundary) + 1
print(ans)
if __name__ == '__main__':
main()
gew1fw