結果

問題 No.3395 Range Flipping Game
コンテスト
ユーザー hirakuuuu
提出日時 2025-12-19 23:20:21
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 1,515 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,120 ms
コンパイル使用メモリ 335,004 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-19 23:20:32
合計ジャッジ時間 9,239 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i >= n; i--)
#define inr(l, x, r) (l <= x && x < r)
#define ll long long
#define ld long double

// using mint = modint1000000007;
// using mint = modint998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1e18;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        string s; cin >> s;
        if(n == 1){
            cout << 'B' << endl;
            continue;
        }

        if(s.substr(0, 2) == "AA"){
            int l = 1, r = 2;
            while(r < n && s[r] == 'B') r++;
            rep(i, l, r) s[i] = 'A'+('B'-s[i]);
        }else if(s.substr(0, 2) == "AB"){
            int l = 2;
            while(l < n && s[l] == 'A') l++;
            int r = l;
            while(r < n && s[r] == 'B') r++;
            rep(i, l, r) s[i] = 'A'+('B'-s[i]);
        }else if(s.substr(0, 2) == "BA"){
            int l = 0, r = 2;
            while(r < n && s[r] == 'B') r++;
            rep(i, l, r) s[i] = 'A'+('B'-s[i]);
        }else{
            s[0] = 'A';
        }

        int l = 0;
        while(l < n && s[l] == 'B') l++;
        int r = l;
        while(r < n && s[r] == 'A') r++;
        rep(i, l, r) s[i] = 'B';
        cout << s << endl;
    }

    return 0;
}
0