#include "bits/stdc++.h"
using namespace std;
#define int long long
pair <int,int> mn(pair <int,int> a, pair <int,int> b) {
if(max(a.first, a.second) < max(b.first, b.second) ) return a;
return b;
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
int q;
cin >> q;
while(q --) {
string str;
cin >> str;
int n = str.size();
stack <int> st;
vector <int> cnt(n, 0), nope;
set <int> close, open;
for(int i = 0; i < n; i ++) {
if(str[i] == ')') {
if(st.size() == 0) {
if(open.size()) {
cnt[i] = 5;
cnt[*open.begin()] ++;
open.erase(open.begin());
continue;
}
cout << "impossible\n";
goto end;
}
cnt[i] ++;
st.pop();
close.insert(i);
}else {
st.push(i);
cnt[i] ++;
open.insert(i);
}
}
while(st.size()) {
nope.push_back(st.top());
st.pop();
}
sort(nope.rbegin(), nope.rend());
for(auto i : nope) {
if(close.size() == 0) {
cout << "impossible\n";
goto end;
}
if(i > *--close.end()) {
cout << "impossibe\n";
goto end;
}
cnt[i] = 5;
cnt[*--close.end()] ++;
close.erase(--close.end());
}
for(auto i : cnt) {
if(i == 2) cout << "G";
else if(i == 1) cout << "R";
else cout << "B";
assert(i > 0);
}
cout << "\n";
continue;
end:;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "impossible" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "impossible" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "impossible" found |
2 |
Halted |
0 ms |
0 KB |
- |