結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <cstdlib>
#include <math.h>
using namespace std;

using ll = long long;


int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        string s;
        cin >> s;
        if(n==1){
            cout << "B" << endl;
            continue;
        }
        if(n==2){
            cout << "BB" << endl;
            continue;
        }
        if(s.substr(0,2)=="AA" || s.substr(0,2)=="BA"){
            for(int i=2;i<n;i++){
                if(s[i]=='B')s[i]='A';
                else break;
            }
        }else if(s.substr(0,2)=="AB"){
            bool ok=false;
            for(int i=2;i<n;i++){
                if(s[i]=='B'){
                    s[i]='A';
                    ok=true;
                }
                else if(ok)break;
            }
        }
        s[0]='B';
        s[1]='B';
        cout << s << endl;
    }
    return 0;
}
0