# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861962 | maks007 | parentrises (BOI18_parentrises) | C++14 | 1066 ms | 11252 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;
#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;
for(int i = 0; i < n; i ++) {
if(str[i] == ')') {
if(st.size() == 0) {
nope.push_back(i);
continue;
}
cnt[i] ++;
st.pop();
}else {
st.push(i);
cnt[i] ++;
}
}
while(st.size() != 0) nope.push_back(st.top()), st.pop();
for(auto i : nope) {
if(str[i] == '(') {
for(int j = i + 1; j < str.size(); j ++) {
if(str[j] == ')' && cnt[j] <= 1) {
cnt[j] ++;
cnt[i] = 5;
break;
}
}
if(cnt[i] == 5) continue;
cout << "impossible\n";
goto end;
}else {
for(int j = 0; j < i; j ++) {
if(str[j] == '(' && cnt[j] <= 1) {
cnt[j] ++;
cnt[i] = 5;
break;
}
}
if(cnt[i] == 5) continue;
cout << "impossible\n";
goto 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;
}
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... |