結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;

	if(n == 1)
	{
		cout << "B\n";
		return ;
	}

	string s2 = s.substr(0, 2);
	if(s2 == "AB")
	{
		cout << "BB";
		int idx = 2;
		while(idx < n && s[idx] == 'A')
		{
			cout << s[idx];
			idx++;
		}
		while(idx < n && s[idx] == 'B')
		{
			cout << 'A';
			idx++;
		}
		cout << s.substr(idx) << "\n";
	}
	else if(s2 == "BA" || s2 == "AA")
	{
		cout << "BB";
		int idx = 2;
		while(idx < n && s[idx] == 'B')
		{
			cout << "A";
			idx++;
		}
		cout << s.substr(idx) << "\n";
	}
	else if(s2 == "BB")
	{
		cout << "BB" << s.substr(2) << "\n";
	}
}

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

	int t = 1;
	cin >> t;
	while(t--)
		solve();
}

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("trapv")
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// shuffle(a.begin(), a.end(), rng);
// uniform_int_distribution<long long>(l, r)(rng); // [l, r]
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
0