# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
70000 | octopuses | parentrises (BOI18_parentrises) | C++17 | 53 ms | 9544 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.
//Giorgi Kldiashvili
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define M 1000000007ll
using namespace std;
const int N = 1000020;
int n, k;
int used[N];
bool f[N];
char ch[N];
void go1()
{
vector < int > c; c.clear();
scanf("%s", &ch);
n = strlen(ch);
for(int i = 0; i < n; ++ i)
used[i] = 0, f[i] = 0;
if(ch[0] == ')' || ch[n - 1] == '(')
{
printf("impossible\n");
return;
}
int now = 1;
for(int i = 1; i < n; ++ i)
{
if(ch[i] == ')')
c.push_back(i);
now += (ch[i] == ')')?-1:1;
if(now < 0)
{
if(c.size() <= 1)
{
printf("impossible\n");
return;
}
used[c.back()] = 1; c.pop_back();
used[c.back()] = 2; c.pop_back();
now = 0;
}
}
now = 1;
c.clear();
if(used[n - 1] == 2) now = 0;
for(int i = n - 2; i >= 0; -- i)
{
if(used[i] == 2) continue;
if(ch[i] == '(')
c.push_back(i);
now += (ch[i] == '(')?-1:1;
if(now < 0)
{
if(c.size() <= 1)
{
printf("impossible\n");
return;
}
used[c.back()] = 1; c.pop_back();
used[c.back()] = 2; c.pop_back();
now = 0;
}
}
for(int i = 0; i < n; ++ i)
{
if(used[i] == 0) putchar('G');
if(used[i] == 1) putchar('R');
if(used[i] == 2) putchar('B');
}
printf("\n");
}
int sub, T;
int main()
{
scanf("%d", &sub);
scanf("%d\n", &T);
if(sub == 1)
{
while(T --)
go1();
}
}
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... |