This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |