#include "bits/stdc++.h"
using namespace std;
// vector <char> v[1000010];
string solve(string s) {
int n = s.size();
stack <int> p;
stack <int> q;
string ans;
for(int i = 0; i < n; i++) ans += '#';
for(int i = 0; i < n; i++) {
if(s[i] == ')') {
if(p.empty()) {
if(q.empty()) return "impossible";
else {
ans[q.top()] = 'G';
ans[i] = 'B';
q.pop();
}
} else {
ans[p.top()] = 'R';
ans[i] = 'R';
p.pop();
}
} else {
p.push(i);
q.push(i);
}
}
stack <int> thic;
for(int i = 0; i < n; i++) {
if(ans[i] == '#') {
thic.push(i);
} else if (s[i] == ')' && !thic.empty()) {
ans[thic.top()] = 'B';
ans[i] = 'G';
thic.pop();
}
}
if(thic.empty()) return ans;
else return "impossible";
}
int main(int argc, char const *argv[])
{
ios_base :: sync_with_stdio (false);
cin.tie(0);
int p;
cin >> p;
assert(p == 1);
int t;
cin >> t;
while(t--) {
string s;
cin >> s;
cout << solve(s) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
584 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
3 ms |
672 KB |
Output is correct |
5 |
Correct |
3 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
584 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
3 ms |
672 KB |
Output is correct |
5 |
Correct |
3 ms |
676 KB |
Output is correct |
6 |
Correct |
1 ms |
676 KB |
Output is correct |
7 |
Correct |
2 ms |
676 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
676 KB |
Output is correct |
10 |
Correct |
2 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
584 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
3 ms |
672 KB |
Output is correct |
5 |
Correct |
3 ms |
676 KB |
Output is correct |
6 |
Correct |
1 ms |
676 KB |
Output is correct |
7 |
Correct |
2 ms |
676 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
676 KB |
Output is correct |
10 |
Correct |
2 ms |
676 KB |
Output is correct |
11 |
Correct |
3 ms |
676 KB |
Output is correct |
12 |
Correct |
3 ms |
676 KB |
Output is correct |
13 |
Correct |
2 ms |
676 KB |
Output is correct |
14 |
Correct |
3 ms |
780 KB |
Output is correct |
15 |
Correct |
3 ms |
780 KB |
Output is correct |
16 |
Correct |
7 ms |
780 KB |
Output is correct |
17 |
Correct |
6 ms |
1200 KB |
Output is correct |
18 |
Correct |
4 ms |
1200 KB |
Output is correct |
19 |
Correct |
5 ms |
1200 KB |
Output is correct |
20 |
Correct |
5 ms |
1200 KB |
Output is correct |
21 |
Correct |
52 ms |
1456 KB |
Output is correct |
22 |
Correct |
33 ms |
5700 KB |
Output is correct |
23 |
Correct |
21 ms |
5700 KB |
Output is correct |
24 |
Correct |
26 ms |
5700 KB |
Output is correct |
25 |
Correct |
36 ms |
5708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5708 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5708 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5708 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |