結果
| 問題 | No.3395 Range Flipping Game |
| コンテスト | |
| ユーザー |
hiromi_ayase
|
| 提出日時 | 2025-12-06 19:29:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 1,397 bytes |
| 記録 | |
| コンパイル時間 | 6,103 ms |
| コンパイル使用メモリ | 335,100 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-06 19:29:47 |
| 合計ジャッジ時間 | 7,939 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO \
ios::sync_with_stdio(false); \
cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;
int main() {
FAST_IO
int T;
cin >> T;
while (T--) {
int N;
string S;
cin >> N >> S;
if (N == 1) {
cout << "B" << "\n";
} else {
if (S[0] == 'B' && S[1] == 'B') {
// none
} else if (S[0] == 'B' && S[1] == 'A') {
S[1] = 'B';
int p = 2;
while (p < N && S[p] == 'B') {
S[p] = 'A';
p ++;
}
} else if (S[0] == 'A' && S[1] == 'A') {
S[0] = 'B';
S[1] = 'B';
int p = 2;
while (p < N && S[p] == 'B') {
S[p] = 'A';
p ++;
}
} else {
int s = -1, e = N;
for (int i = 2; i < N; i++) {
if (S[i] == 'B') {
if (s < 0) {
s = i;
}
}
if (s >= 0 && S[i] == 'A') {
e = i;
break;
}
}
if (s >= 0) {
for (int i = s; i < e; i++) {
S[i] = 'A';
}
}
S[0] = 'B';
}
cout << S << "\n";
}
}
// AAAABBBBAAAABBBB
}
hiromi_ayase