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 <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
bool good(const std::string &str) {
int bal = 0;
for(auto ch : str) {
bal += ch == '(' ? 1 : -1;
if(bal < 0) return false;
}
return bal == 0;
}
void solve1() {
int t;
std::cin >> t;
while(t--) {
std::string str;
std::cin >> str;
int n = (int) str.size();
std::vector<int> pos[2];
std::vector<int> col(n, 3);
int bst = 0, sum = 0;
for(int i = 0; i < n; i++) {
pos[str[i] == '('].push_back(i);
sum += str[i] == '(' ? 1 : -1;
bst = std::min(bst, sum);
}
int bal = (int) pos[1].size() - (int) pos[0].size();
if(bst < 0) {
bal -= bst;
bst = -bst;
for(int i = 0; i < 2*bst && i < (int) pos[0].size(); i++) {
col[pos[0][i]] = i % 2 == 0 ? 1 : 2;
}
}
if(bal > 0) {
for(int i = 0; i < 2*bal && i < (int) pos[1].size(); i++) {
col[pos[1][(int) pos[1].size() - i - 1]] = i % 2 == 0 ? 1 : 2;
}
}
std::string haha[2];
for(int i = 0; i < n; i++) {
if(col[i] & 1) haha[0] += str[i];
if(col[i] & 2) haha[1] += str[i];
}
if(good(haha[0]) && good(haha[1])) {
for(int i = 0; i < n; i++) {
char ch;
if(col[i] == 3) {
ch = 'G';
} else if(col[i] == 1) {
ch = 'R';
} else {
ch = 'B';
}
std::cout << ch;
}
std::cout << '\n';
} else {
std::cout << "impossible\n";
}
}
}
void solve2() {
}
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
int P;
std::cin >> P;
if(P == 1) {
solve1();
} else {
solve2();
}
}
# | 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... |