結果

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

ソースコード

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;
  queue<pair<char,int>>A;
  rep(i,N){
    int j=1;
    while(i+j<N&&S[i]==S[i+j]){
      j++;
    }
    // cout<<S[i]<<" "<<j<<endl;
    A.push({S[i],j});
    i+=j-1;
  }
  int f=0;
  while(A.size()){
    auto [c,x]=A.front();
    A.pop();
    if(f==1){
      rep(i,x)cout<<c;
      continue;
    }
    if(f==2&&c=='B'){
      cout<<"B";
      rep(i,x-1)cout<<"A";
      f=1;
      if(x==1)f=3;
      continue;
    }
    if(f==3){
      rep(i,x)cout<<'A';
      if(c=='B')f=1;
      continue;
    }
    
    if(c=='A'){
        if(x<3){
          rep(i,x)cout<<'B';
          f=2;
        }
        else{
          cout<<"BBA";
          rep(i,x-3)cout<<"A";
          f=1;
        }
    }
    else{
      rep(i,x)cout<<"B";
      if(x>1){
        f=1;
      }
    }
  }
  cout<<endl;


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