結果
| 問題 | No.3395 Range Flipping Game |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-11 22:14:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 1,739 bytes |
| 記録 | |
| コンパイル時間 | 3,919 ms |
| コンパイル使用メモリ | 255,888 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-11 22:14:26 |
| 合計ジャッジ時間 | 7,153 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
}
} io_setup;
using mint = atcoder::modint998244353;
void solve() {
int n;
string s;
cin >> n >> s;
vector<pair<char, int>> vp;
vp.push_back({s[0], 0});
for (char c : s) {
if (vp.back().first == c) vp.back().second++;
else vp.push_back({c, 1});
}
if (vp.size() == 1) {
if (vp.front().first == 'A' && n > 2) {
cout << "BB" << string(n - 2, 'A') << '\n';
} else {
cout << string(n, 'B') << '\n';
}
return;
}
if (vp.front().first == 'A') {
if (vp.front().second == 1) {
if (vp[1].second > 1) {
vp.front().first = 'B';
vp.front().second = 2;
vp[1].first = 'A';
vp[1].second--;
} else {
if (vp.size() >= 4) {
vp[3].first = 'A';
}
vp.front().first = 'B';
}
} else if (vp.front().second == 2) {
vp.front().first = 'B';
vp[1].first = 'A';
} else {
vp.front().second -= 2;
vp.insert(vp.begin(), {'B', 2});
}
} else {
if (vp.front().second == 1) {
if (vp[1].second == 1) {
if (vp.size() == 2) {
vp[1].first = 'B';
} else {
vp[2].first = 'A';
vp[1].first = 'B';
}
} else {
vp[1].second--;
vp.front().second++;
}
}
}
for (auto [c, k] : vp) cout << string(k, c);
cout << '\n';
}
int main() {
int t = 1;
cin >> t;
while (t--) solve();
}