# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98573 | tdwn | parentrises (BOI18_parentrises) | C++17 | 225 ms | 7400 KiB |
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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
string code;
void solve() {
cin>>code;
string answ = code;
stack<int>s1, s2;
for(int i=0;i<code.length();i++) {
if(code[i] == '(') {
s1.push(i);
}
else {
if(s1.size() > 0) {
answ[s1.top()] = answ[i] = 'R';
s2.push(s1.top());
s1.pop();
}
else if(s2.size() > 0) {
answ[s2.top()] = 'G';
answ[i] = 'B';
s2.pop();
}
else {
cout<<"impossible\n";
return;
}
}
}
stack<int>t1, t2;
for(int i=code.length()-1;i>=0;i--) {
if(code[i] == ')') {
t1.push(i);
}
else {
if(answ[i] == 'R' || answ[i] == 'G') continue;
else {
if(t1.size() > 0) {
answ[i] = 'B';
answ[t1.top()] = 'G';
t1.pop();
}
else {
cout<<"impossible\n";
return;
}
}
}
}
cout<<answ<<"\n";
return;
}
int main() {
int P, T;
cin>>P;
cin>>T;
while(T--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | 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... |