結果
| 問題 | No.3395 Range Flipping Game |
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2025-12-02 20:27:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 155 ms / 2,000 ms |
| コード長 | 1,603 bytes |
| コンパイル時間 | 442 ms |
| コンパイル使用メモリ | 82,152 KB |
| 実行使用メモリ | 113,184 KB |
| 最終ジャッジ日時 | 2025-12-02 20:27:19 |
| 合計ジャッジ時間 | 5,218 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
"""
https://yukicoder.me/problems/no/3395
後手に AB で渡したい
AA,BA = 3文字目スタートで後は自由
AB = 完全自由
BB = そのまま
"""
import sys
from sys import stdin
TT = int(stdin.readline())
ANS = []
for loop in range(TT):
N = int(stdin.readline())
S = stdin.readline()[:-1]
if N == 1:
print ("B")
continue
elif N == 2:
print ("BB")
continue
elif S[:2] == "BB":
print (S)
continue
elif S[:2] == "AB":
state = 0
ans = [ "BB" ]
for i in range(2,N):
if state == 0:
if S[i] == "B":
state = 1
ans.append("A")
else:
ans.append(S[i])
elif state == 1:
if S[i] == "B":
ans.append("A")
else:
ans.append(S[i])
state = 2
else:
ans.append(S[i])
print ("".join(ans))
else:
state = 1
ans = ["BB"]
for i in range(2,N):
if state == 0:
if S[i] == "B":
state = 1
ans.append("A")
else:
ans.append(S[i])
elif state == 1:
if S[i] == "B":
ans.append("A")
else:
ans.append(S[i])
state = 2
else:
ans.append(S[i])
print ("".join(ans))
SPD_9X2