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 kMaxN = 1000;
bitset<kMaxN + 1> dp[kMaxN + 1][kMaxN + 1];
string SolveTest(string s) {
dp[0][0].set(0);
int id = 0;
for (auto ch : s) {
for (int i = 0; i <= id + 1; ++i) {
dp[id + 1][i].reset();
}
if (ch == '(') {
for (int i = 0; i <= id; ++i) {
dp[id + 1][i + 1] |= dp[id][i] << 1;
dp[id + 1][i + 1] |= dp[id][i];
dp[id + 1][i] |= dp[id][i] << 1;
}
} else {
for (int i = 1; i <= id; ++i) {
dp[id + 1][i - 1] |= dp[id][i] >> 1;
dp[id + 1][i - 1] |= dp[id][i];
dp[id + 1][i] |= dp[id][i] >> 1;
}
}
++id;
}
if (not dp[id][0].test(0)) {
return "impossible";
}
int x = 0, y = 0;
string result = "";
for (int i = id - 1; i >= 0; --i) {
const int sign = (s[i] == ')') ? +1 : -1;
if (x + sign >= 0 and dp[i][x + sign].test(y)) {
x += sign;
result += "R";
} else if (y + sign >= 0 and dp[i][x].test(y + sign)) {
y += sign;
result += "B";
} else {
x += sign;
y += sign;
result += "G";
}
}
reverse(result.begin(), result.end());
return result;
}
int main() {
int type, num_tests; cin >> type >> num_tests;
if (type == 2) {
return 0;
}
while (num_tests--> 0) {
string s; cin >> s;
cout << SolveTest(s) << '\n';
}
return 0;
}
# | 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... |