#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
char output[nmax];
stack<int> idle;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int p,t;
cin>>p>>t;
if(p==1)
{
string s;
for(int i=1;i<=t;i++)
{
cin>>s;
int SZ=s.size();
for(int j=0;j<SZ;j++)
output[j]=-1;
stack<int> open=idle;
for(int j=0;j<SZ;j++)
{
if(s[j]=='(')open.push(j);
else
{
if(open.size())
{
output[open.top()]='R';
output[j]='R';
open.pop();
}
}
}
bool ok=1;
open=idle;
for(int j=0;j<SZ;j++)
{
if(s[j]=='(')open.push(j);
else
{
if(output[j]==-1)
{
if(open.size()==0)ok=0;
else
{
output[j]='B';
output[open.top()]='G';
open.pop();
}
}
}
}
open=idle;
for(int j=SZ-1;j>=0;j--)
{
if(s[j]==')')open.push(j);
else
{
if(output[j]==-1)
{
if(open.size()==0)ok=0;
else
{
output[j]='B';
output[open.top()]='G';
open.pop();
}
}
}
}
if(ok)
{
for(int j=0;j<SZ;j++)cout<<output[j];
cout<<endl;
}
else cout<<"impossible"<<endl;
}
}
else
{
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
32 ms |
560 KB |
Output is correct |
17 |
Correct |
9 ms |
1016 KB |
Output is correct |
18 |
Correct |
7 ms |
632 KB |
Output is correct |
19 |
Correct |
8 ms |
760 KB |
Output is correct |
20 |
Correct |
8 ms |
1016 KB |
Output is correct |
21 |
Correct |
238 ms |
2232 KB |
Output is correct |
22 |
Correct |
64 ms |
6292 KB |
Output is correct |
23 |
Correct |
47 ms |
2480 KB |
Output is correct |
24 |
Correct |
57 ms |
3692 KB |
Output is correct |
25 |
Correct |
64 ms |
6420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Unexpected end of file - int32 expected |