# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91017 | choikiwon | parentrises (BOI18_parentrises) | C++17 | 2 ms | 472 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;
const int mod = 1e9 + 7;
const int MN = 333;
string S, ans;
set<int> R[2], B[2], G[2];
void main2() {
cin >> S;
for(int i = 0; i < 2; i++) {
R[i].clear();
B[i].clear();
G[i].clear();
}
int rg = 0;
int bg = 0;
for(int i = 0; i < S.size(); i++) {
if(S[i] == '(') {
rg++;
R[1].insert(i);
}
else {
if(rg) {
rg--;
R[0].insert(i);
}
else if(bg) {
bg--;
B[0].insert(i);
}
else {
B[0].insert(i);
if(R[1].size()) {
int t = *R[1].begin();
R[1].erase(t);
G[1].insert(t);
}
else {
cout << "impossible\n";
return;
}
}
}
}
while(rg) {
int t = *R[1].rbegin();
R[1].erase(t);
rg--;
B[1].insert(t);
bg++;
}
while(bg) {
if(R[0].size()) {
int t = *R[0].rbegin();
R[0].erase(t);
G[0].insert(t);
bg--;
}
else {
cout << "impossible\n";
return;
}
}
ans.clear();
ans.resize(S.size());
for(int i = 0; i < 2; i++) {
for(auto it = R[i].begin(); it != R[i].end(); it++) {
ans[*it] = 'R';
}
for(auto it = B[i].begin(); it != B[i].end(); it++) {
ans[*it] = 'B';
}
for(auto it = G[i].begin(); it != G[i].end(); it++) {
ans[*it] = 'G';
}
}
cout << ans << endl;
}
void main3() {
}
int P, TC;
int main() {
std::ios::sync_with_stdio(false);
cin >> P >> TC;
if(P == 1) {
while(TC--) main2();
}
if(P == 2) {
while(TC--) main3();
}
}
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... |