#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--;
num1--;
}
if(num1 == 0) break;
}
//process 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--;
color[i] = 3;
}
}
if(tem) {
cout << "impossible"<<endl;
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--;
color[i] = 3;
}
}
if(tem) {
cout << "impossible"<<endl;
return;
}
// print color
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;
return;
}
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 |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
2 ms |
516 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
532 KB |
Output is correct |
2 |
Correct |
2 ms |
532 KB |
Output is correct |
3 |
Correct |
2 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
532 KB |
Output is correct |
2 |
Correct |
2 ms |
532 KB |
Output is correct |
3 |
Correct |
2 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
532 KB |
Output is correct |
7 |
Correct |
2 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
532 KB |
Output is correct |
2 |
Correct |
2 ms |
532 KB |
Output is correct |
3 |
Correct |
2 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
532 KB |
Output is correct |
7 |
Correct |
2 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
3 ms |
736 KB |
Output is correct |
13 |
Correct |
3 ms |
736 KB |
Output is correct |
14 |
Correct |
3 ms |
736 KB |
Output is correct |
15 |
Correct |
4 ms |
736 KB |
Output is correct |
16 |
Correct |
24 ms |
856 KB |
Output is correct |
17 |
Correct |
12 ms |
1680 KB |
Output is correct |
18 |
Correct |
10 ms |
1680 KB |
Output is correct |
19 |
Correct |
13 ms |
1680 KB |
Output is correct |
20 |
Correct |
14 ms |
1740 KB |
Output is correct |
21 |
Correct |
203 ms |
1740 KB |
Output is correct |
22 |
Correct |
113 ms |
11544 KB |
Output is correct |
23 |
Correct |
78 ms |
11544 KB |
Output is correct |
24 |
Correct |
89 ms |
11544 KB |
Output is correct |
25 |
Correct |
111 ms |
11660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
11660 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
11660 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
11660 KB |
Unexpected end of file - int32 expected |