# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861790 | maks007 | parentrises (BOI18_parentrises) | C++14 | 1055 ms | 428 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"
using namespace std;
string str;
vector <int> rgb, ans;
int f;
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;
}
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T, q;
cin >> T >> q;
while(q --) {
cin >> str;
if(T == 1) {
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";
}else {
// cout << ans;
}
}
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... |