結果
| 問題 | No.3395 Range Flipping Game |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-02 02:48:01 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 227 ms / 2,000 ms |
| コード長 | 1,799 bytes |
| コンパイル時間 | 3,120 ms |
| コンパイル使用メモリ | 282,452 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-12-02 02:48:08 |
| 合計ジャッジ時間 | 6,638 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int ttt;
cin>>ttt;
while(ttt--){
int n;
cin>>n;
string s;
cin>>s;
if(n<=2){
for(int i=0;i<n;i++)cout<<"B";
cout<<endl;
continue;
}
deque<pair<char,int>> rle;
for(int i=0;i<n;i++){
int l=i;
while(i<n&&s[i]==s[l])i++;
rle.push_back(make_pair(s[l],i-l));
i--;
}
if(rle[0].first=='A'){
if(rle[0].second==1){
if(rle[1].second==1){
if(rle.size()>=4){
rle[3].first='A';
}
rle[0].first='B';
}else{
if(rle.size()>=3){
rle[2].second+=rle[1].second-1;
rle[1].second=1;
}else{
rle.push_back(make_pair('A',rle[1].second-1));
rle[1].second=1;
}
rle[0].first='B';
}
}else if(rle[0].second==2){
rle[1].first='A';
rle[0].first='B';
}else{
rle[0].second-=2;
rle.push_front(make_pair('B',2));
}
}else{
if(rle[0].second==1){
if(rle[1].second==1){
rle[2].first='A';
rle[1].first='B';
}else{
rle[0].second++;
rle[1].second--;
}
}
}
for(auto [c,i]:rle){
while(i--)cout<<c;
}
cout<<endl;
}
return 0;
}