# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255225 | Kastanda | parentrises (BOI18_parentrises) | C++11 | 70 ms | 7540 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.
// M
#include<bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, q, Sub;
char S[N];
void SolveSub1()
{
scanf("%d", &q);
for (; q; q --)
{
scanf("%s", S);
n = strlen(S);
vector < int > C(n, 0), Stk, OP;
for (int i = 0; i < n; i ++)
{
if (S[i] == '(')
Stk.push_back(i);
else if (Stk.size())
C[Stk.back()] = C[i] = 1, Stk.pop_back();
else
OP.push_back(i);
}
bool Fail = 0;
vector < int > Kts, PO;
for (int i = n - 1; ~ i; i --)
{
if (Stk.size())
{
if (Stk.back() == i)
{
if (!Kts.size())
{Fail = 1; break;}
C[Kts.back()] += 2;
Kts.pop_back();
C[Stk.back()] += 2;
Stk.pop_back();
continue;
}
if (S[i] == '(')
continue;
Kts.push_back(i);
}
else
{
if (OP.size() && OP.back() == i)
{
PO.push_back(OP.back());
OP.pop_back();
continue;
}
if (S[i] == ')')
continue;
if (PO.size())
{
C[PO.back()] += 2;
PO.pop_back();
C[i] += 2;
}
}
}
if (PO.size() || OP.size() || Stk.size())
Fail = 1;
fill(S, S + n, 0);
if (Fail)
printf("impossible\n");
else
{
for (int i = 0; i < n; i ++)
printf("%c", "RBG"[C[i] - 1]);
printf("\n");
}
}
exit(0);
}
int main()
{
scanf("%d", &Sub);
if (Sub == 1)
SolveSub1();
}
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... |