# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647810 | raresmihai | parentrises (BOI18_parentrises) | C++17 | 1 ms | 340 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 <iostream>
#define MAXL 1000000
using namespace std;
struct paranthesis{
bool type;
int pos;
};
int posOfOpen[MAXL], posOfOpenSize;
paranthesis bad[MAXL + 2];
int badSize;
char ans[MAXL];
int goodOpen[MAXL], goodOpenSize;
int goodClosed[MAXL], goodClosedSize;
int bs1(int val) {
int st, dr, mij;
st = -1;
dr = goodClosedSize - 1;
while ( dr - st > 1 ) {
mij = (dr + st) / 2;
if ( goodClosed[mij] < val )
st = mij;
else
dr = mij;
}
return dr;
}
int bs2(int val) {
int st, dr, mij;
st = 0;
dr = goodOpenSize;
while ( dr - st > 1 ) {
mij = (st + dr) / 2;
if ( goodOpen[mij] > val )
dr = mij;
else
st = mij;
}
return st;
}
int main() {
int c, t, i, pos;
char ch;
bool good;
scanf("%d", &c);
if ( c == 1 ) {
scanf("%d ", &t);
while ( t-- ) {
posOfOpenSize = goodClosedSize = goodOpenSize = 0;
badSize = 1;
ch = fgetc(stdin);
i = 0;
while ( ch == '(' || ch == ')' ) {
if ( ch == '(' ) {
posOfOpen[posOfOpenSize] = i;
posOfOpenSize++;
} else {
if ( posOfOpenSize ) {
posOfOpenSize--;
goodOpen[goodOpenSize] = posOfOpen[posOfOpenSize];
goodOpenSize++;
goodClosed[goodClosedSize] = i;
goodClosedSize++;
ans[i] = ans[posOfOpen[posOfOpenSize]] = 'R';
} else {
bad[badSize].pos = i;
bad[badSize].type = true;
badSize++;
}
}
i++;
ch = fgetc(stdin);
}
posOfOpenSize--;
while ( posOfOpenSize >= 0 ) {
bad[badSize].pos = posOfOpen[posOfOpenSize];
bad[badSize].type = false;
badSize++;
posOfOpenSize--;
}
good = true;
bad[badSize].pos = i + 1;
bad[0].pos = -1;
badSize--;
while ( badSize && good ) {
ans[bad[badSize].pos] = 'B';
if ( !bad[badSize].type ) {
pos = goodClosed[bs1(bad[badSize].pos)];
if ( pos > bad[badSize].pos && pos < bad[badSize + 1].pos ) {
ans[pos] = 'G';
} else {
good = false;
}
} else {
pos = goodOpen[bs2(bad[badSize].pos)];
if ( pos < bad[badSize].pos && bad[badSize - 1].pos < pos ) {
ans[pos] = 'G';
} else {
good = false;
}
}
badSize--;
}
if ( good ) {
for ( pos = 0; pos < i; pos++ ) {
fputc(ans[pos], stdout);
}
printf("\n");
} else {
printf("impossible\n");
}
}
}
return 0;
}
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... |