# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64193 | Just_Solve_The_Problem | parentrises (BOI18_parentrises) | C++17 | 3 ms | 580 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 pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int b[N];
vector < int > stk;
int a[N];
void solve1() {
string s;
cin >> s;
b[0] = ((s[0] == '(') ? 1 : -1);
a[0] = 1;
for (int i = 1; i < sz(s); i++) {
b[i] = b[i - 1] + ((s[i] == '(') ? 1 : -1);
a[i] = 1;
}
int cur = 0;
stk.clear();
for (int i = 0; i < sz(s); i++) {
if (s[i] == ')') stk.pb(i);
if (b[i] + cur < 0) {
// cout << i << ' ' << b[i] + cur << ' ' << sz(stk) << endl;
while (b[i] + cur < 0 && sz(stk) > 1) {
a[stk.back()] = 0;
stk.pop_back();
a[stk.back()] = 2;
stk.pop_back();
cur++;
}
if (b[i] + cur < 0) {
puts("impossible");
return ;
}
}
}
stk.clear();
for (int i = 0; i < sz(s); i++) {
if (s[i] == '(')
stk.pb(i);
}
int b1 = b[sz(s) - 1] + cur;
while (b1 > 0 && sz(stk) > 1) {
b1--;
a[stk.back()] = 0;
stk.pop_back();
a[stk.back()] = 2;
stk.pop_back();
}
if (b1 > 0) {
puts("impossible");
}
for (int i = 0; i < sz(s); i++) {
if (a[i] == 0) printf("R");
else if (a[i] == 1) printf("G");
else printf("B");
}
puts("");
}
void solve2() {
int n;
scanf("%d", &n);
}
main() {
int p;
scanf("%d", &p);
int test;
scanf("%d", &test);
if (p == 1) {
while (test--)
solve1();
} else {
while (test--)
solve2();
}
}
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... |