結果
| 問題 |
No.3317 ワロングアンサーロングアンサーンスワロンガー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-31 22:34:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 440 ms / 2,000 ms |
| コード長 | 2,334 bytes |
| コンパイル時間 | 338 ms |
| コンパイル使用メモリ | 82,440 KB |
| 実行使用メモリ | 91,376 KB |
| 最終ジャッジ日時 | 2025-11-01 10:01:05 |
| 合計ジャッジ時間 | 16,365 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 63 |
ソースコード
def solve_nest(string, t, x):
while t > 0:
t -= 1
x0 = 5 * (2 ** t - 1) + 1
if x >= x0:
if string == "w":
if x >= 2 * x0:
y = x - 2 * x0
return "warong"[y + 2]
else:
x -= x0
string = "a"
else:
if x == x0:
return "n"
elif x == x0 + 1:
return "s"
else:
# x >= x0 + 2
if x >= 2 * x0 + 2:
y = x - 2 * x0 - 2
return "er"[y]
else:
x -= x0 + 2
string = "w"
return string
def solve2(N, S, t, x, begin_map):
b = list(begin_map.values())[0]
if x < b:
return S[x]
string = list(begin_map.keys())[0]
x -= b
t0 = 0
while 5 * (2 ** t0 - 1) + 1 <= x:
t0 += 1
t = t0
return solve_nest(string, t, x)
def solve1(N, S, t, x, wa_counts):
x0 = 5 * (2 ** t - 1) + 1
def f(y):
n = wa_counts[y]
return n * x0 - n + y
low = 0
high = N - 1
while high - low > 1:
mid = (high + low) // 2
if x >= f(mid):
low = mid
else:
high = mid
if x >= f(high):
v = high
else:
v = low
if S[v] not in ("w", "a"):
return S[v]
string = S[v]
x -= f(v)
return solve_nest(string, t, x)
def main():
N, Q = map(int, input().split())
S = input()
tx = []
for _ in range(Q):
t, x = map(int, input().split())
tx.append((t, x - 1))
# 最初のw or a を探す
begin_map = {}
for i in range(N):
if S[i] in ("w", "a"):
begin_map[S[i]] = i
break
wa_counts = [0] * N
c = 0
for i in range(N):
if i > 0:
if S[i - 1] in ("w", "a"):
c += 1
wa_counts[i] = c
answer = []
for t, x in tx:
if t <= 63:
ans = solve1(N, S, t, x, wa_counts)
else:
ans = solve2(N, S, t, x, begin_map)
answer.append(ans)
print("".join(answer))
if __name__ == "__main__":
main()
# main2()