#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
typedef pair<int,pair<int,int> > tri;
int P, T;
int color[1000050];
int br[1000050];
void solve(string S){
int n = S.length();
memset(color, 0, n * sizeof(color[0]));
for(int i = 0; i < n; i++){
if(S[i] == '(') br[i] = 0;
else br[i] = 1;
}
//process for first ppl
int num1 = 0, tem = 0;
for(int i = 0; i < n; i++){
if(br[i] == 0) tem ++;
else if(br[i] == 1 && tem){
num1++;
tem--;
color[i] = 1;
}
}
tem = 0;
for(int i = n-1; i >= 0; i--){
if(br[i] == 1) tem ++;
if(br[i] == 0 && tem){
color[i] = 1;
tem--;
}
// if(tem == num1) break;
}
/* tem = 0;
for(int i = n-1; i >= 0; i--){
if(br[i] == 1){
color[i] = 1;
tem++;
}
if(tem == num1) break;
}*/
//process for second ppl
tem = 0;
for(int i = 0; i < n; i++){
if(br[i] == 0 && !color[i]){
tem++;
color[i] = 2;
}
else if(br[i] == 1 && tem){
tem--;
if(color[i]) color[i] = 3;
//else color[i] = 2;
}
}
if(tem) {
cout << "impossible";
return;
}
tem = 0;
for(int i = n-1; i >= 0; i--){
if(br[i] == 1 && !color[i]){
tem++;
color[i] = 2;
}
else if(br[i] == 0 && tem){
tem--;
if(color[i]) color[i] = 3;
//else color[i] = 2;
}
}
if(tem) {
cout << "impossible";
return;
}
// print color
for(int i = 0; i < n; i++){
if(!color[i]) {
cout << "impossible";
return;
}
}
for(int i = 0; i < n; i++){
if(color[i] == 1)cout << "R";
else if(color[i] == 2) cout << "B";
else cout << "G";
}
cout<<endl;
}
int main()
{
//ios_base::sync_with_stdio(0); cin.tie(0);
cin >> P;
if(P==1){
string S;
cin >> T;
while(T--){
cin >> S;
solve(S);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
508 KB |
Output is correct |
3 |
Incorrect |
2 ms |
556 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Unexpected end of file - int32 expected |