結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#define rep1(a) for (int z = 0; z < a; z++)
#define rep2(i, a) for (ll i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define ALL(x) std::begin(x), std::end(x)
#define YN(x) cout << (x ? "Yes" : "No") << endl;
#define popc(x) __builtin_popcount(x)
#define cmp(x, l, r) ((l <= x) && (x <= r))
#define rrep(i, a) for (int i = (a)-1; i >= 0; i--)
#define ll long long
void solve() {
  int N;cin>>N;
  string S;cin>>S;
  if(N<3){
    rep(i,N)cout<<'B';
  }
  else{
    auto T=S.substr(0,3);
    if(T=="BBB")cout<<S;
    else if(T=="ABA"||T=="ABB"||T=="BAB"||T=="AAB"){
      cout<<"BBA";
      int f=1;
      rep(i,3,N){
        if(f&&S[i]=='B'){
          while(f&&i<N&&S[i]=='B'){
            cout<<'A';
            i++;
          }
          f=0;
        }
        if(T!="ABA")f=0;
        if(i<N)cout<<S[i];
      }
    }
    else{
      cout<<"BBA"<<S.substr(3);
    }
  }

  cout<<endl;


}
int main() {
  int T;
  cin >> T;
  // T=1;
  rep(T) solve();
}
0