#include "bits/stdc++.h"
using namespace std;
string str;
// vector <int> rgb, ans;
// int f, ans2;
// void do_1() {
// if(rgb.size() == str.size()) {
// int balb = 0, balr = 0;
// for(int i = 0; i < str.size(); i ++) {
// if(str[i] == '(') {
// if(rgb[i] == 0) balb ++;
// else if(rgb[i] == 1) balr ++;
// else balb ++, balr ++;
// }else {
// if(rgb[i] == 0) balb --;
// else if(rgb[i] == 1) balr --;
// else balb --, balr --;
// if(min(balb, balr) < 0) goto end;
// }
// }
// if(balr == 0 && balb == 0) {
// ans = rgb;
// f = 1;
// }
// return;
// end:;
// return;
// }
// for(int i = 0; i < 3; i ++) {
// rgb.push_back(i);
// do_1();
// rgb.pop_back();
// if(f) return;
// }
// }
// void do_2(int &n) {
// if(rgb.size() == n) {
// int balb = 0, balr = 0;
// for(int i = 0; i < rgb.size(); i ++) {
// if(rgb[i] == 10) {
// balb ++;
// }else if(rgb[i] == 11) {
// balb --;
// }else if(rgb[i] == 20) {
// balr ++;
// }else if(rgb[i] == 21) {
// balr --;
// }else if(rgb[i] == 30) {
// balb ++, balr ++;
// }else {
// balb --, balr --;
// }
// if(balb < 0 || balr < 0) goto end;
// }
// if(balb > 0 || balr > 0) return;
// // cout << balr << " " << balb << "\n";
// // for(auto i : rgb) cout << i << " ";
// // cout << "\n";
// ans2 ++;
// return;
// end:;
// return;
// }
// for(int i = 1; i <= 3; i ++) {
// for(int j = 0; j < 2; j ++) {
// int val = i * 10 + j;
// // cout << val << " ";
// rgb.push_back(val);
// do_2(n);
// rgb.pop_back();
// }
// }
// }
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T, q;
cin >> T >> q;
while(q --) {
if(T == 1) {
cin >> str;
// f = 0;
// do_1();
// if(!f) {
// cout << "impossible\n";
// continue;
// }
// for(auto i : ans) {
// if(i == 0) cout << "B";
// else if(i == 1) cout << "R";
// else cout << "G";
// }
// cout << "\n";
int open, close;
open = close = 0;
string ans = "";
for(int i = 0; i < str.size(); i ++) {
if(str[i] == '(') {
// open ++;
if(open * 2 == close) {
for(int j = 0; j < open; j ++) ans += 'G';
for(int j = 0; j < close/2; j ++) ans += 'R';
for(int j = 0; j < close/2; j ++) ans += 'B';
close = 0, open = 1;
}else if(close * 2 == open) {
for(int j = 0; j < open/2; j ++) ans += 'R';
for(int j = 0; j < open/2; j ++) ans += 'B';
for(int j = 0; j < close; j ++) ans += 'G';
close = 0, open = 1;
}else if(open == close) {
for(int j = 0; j < close + open; j ++) ans += 'G';
close = 0, open = 1;
}else if(close == 0) open ++;
else {
cout << "impossible\n";
goto end;
}
}else {
close ++;
}
}
if(open * 2 == close) {
for(int j = 0; j < open; j ++) ans += 'G';
for(int j = 0; j < close/2; j ++) ans += 'R';
for(int j = 0; j < close/2; j ++) ans += 'B';
close = 0, open = 1;
}else if(close * 2 == open) {
for(int j = 0; j < open/2; j ++) ans += 'R';
for(int j = 0; j < open/2; j ++) ans += 'B';
for(int j = 0; j < close; j ++) ans += 'G';
close = 0, open = 1;
}else if(open == close) {
for(int j = 0; j < close + open; j ++) ans += 'G';
close = 0, open = 1;
}else {
cout << "impossible\n";
goto end;
}
cout << ans << "\n";
continue;
end:;
}else {
// int n;
// cin >> n;
// ans2 = 0;
// // n*=2;
// do_2(n);
// cout << ans2 << "\n";
}
}
return 0;
}
Compilation message
parentrises.cpp: In function 'int main()':
parentrises.cpp:102:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int i = 0; i < str.size(); i ++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |