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;
void solve1() {
string s;
cin >> s;
int n = s.size();
string a(n, 'G');
int b0 = 0, b1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
a[i] = 'G';
b0++, b1++;
} else {
if (b0 >= b1) {
a[i] = 'R';
b0--;
} else {
a[i] = 'B';
b1--;
}
}
if (b0 < 0 || b1 < 0) {
cout << "impossible\n";
return;
}
}
for (int i = n - 1; i >= 0 && (b0 || b1); i--) {
if (s[i] == '(') {
if (b0 >= b1)
a[i] = 'B', b0--;
else
a[i] = 'R', b1--;
} else {
if (b0 > 0 && a[i] == 'B')
a[i] = 'G', b0--;
else if (b1 > 0 && a[i] == 'R')
a[i] = 'G', b1--;
}
assert(b0 >= 0 && b1 >= 0);
}
if (b0 || b1)
cout << "impossible\n";
else
cout << a << "\n";
}
void solve2() {}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int p, t;
cin >> p >> t;
while (t--) {
if (p == 1)
solve1();
else
solve2();
}
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... |