結果

問題 No.3395 Range Flipping Game
コンテスト
ユーザー otoshigo
提出日時 2025-12-02 18:08:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 2,938 ms
コンパイル使用メモリ 279,124 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-02 18:08:13
合計ジャッジ時間 5,457 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define TT template <typename T>
template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }

struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
        srand(time(NULL));
    }
} io_setup;

void solve() {
    int N;
    string S;
    cin >> N >> S;
    int l = 0;
    while (l < N && S[l] == 'B') l++;
    if (l == N) {
        cout << S << endl;
        return;
    }
    int r = l;
    while (r < N && S[r] == 'A') r++;
    if (l >= 2) {
        cout << S << endl;
    } else if (l == 1) {
        S[1] = 'B';
        cout << S << endl;
    } else if (r - l >= 2) {
        rep(i, l, l + 2) S[i] = 'B';
        cout << S << endl;
    } else {
        int n = r + 1;
        while (n < N && S[n] == 'A') n++;
        while (n < N && S[n] == 'B') {
            S[n] = 'A';
            n++;
        }
        rep(i, l, r) S[i] = 'B';
        cout << S << endl;
    }
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}
0