結果

問題 No.3395 Range Flipping Game
コンテスト
ユーザー GGanari
提出日時 2025-12-02 14:37:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,573 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 198,324 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-02 14:37:39
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define long long long
#define INF 1000000001
#define LNF 10000000011000000001
#define MOD 998244353
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--)
    {
        int n;
        cin >> n;
        string s;
        cin >> s;

        reverse(all(s));
        while(!s.empty() && s.back() == 'B')
        {
            s.pop_back();
            cout << 'B';
        }
        reverse(all(s));
        int cnt = 0;
        int pre = 'A';
        vector<int> arr;
        n = s.size();

        for(int i = 0; i<n; i++)
        {
            if(s[i] != pre)
            {
                arr.push_back(cnt);
                pre = s[i];
                cnt = 0;
            }
            cnt++;
        }
        arr.push_back(cnt);

        if(arr[0] == 1)
        {
            s[0] = 'B';
            bool end = false;
            for(int i = 2; i<n; i++)
            {
                if(s[i] == 'B')
                    end = true;
                if(end && s[i] == 'A')
                    break;
                s[i] = 'A';
            }
        }
        if(arr[0] == 2)
        {
            s[0] = 'B';
            s[1] = 'B';
            for(int i = 2; i<n; i++)
            {
                if(s[i] == 'A')
                    break;
                s[i] = 'A';
            }
        }
        if(arr[0] >= 3)
        {
            s[0] = 'B';
            s[1] = 'B';
        }
        cout << s << "\n";
    }
    return 0;
}

0