結果

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

ソースコード

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;

        int cnt = 0;
        int pre = s[0];
        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(s[0] == 'A')
        {
            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';
            }
        }
        else
        {
            if(arr[0] == 1)
            {
                if(arr.size() > 1)
                {
                    s[1] ='B';
                    if(arr[1] == 1)
                    {
                        for(int i = 2; i<n; i++)
                        {
                            if(s[i] == 'A')
                                break;
                            s[i] = 'A';
                        }
                    }
                }
            }
        }
        cout << s << "\n";
    }
    return 0;
}

0