#include <iostream>
#include <fstream>
using namespace std;
const int nmax=1000005;
string s;
char ans[nmax];
int st1[nmax],st2[nmax];
int tip,cnt,u,t,i,u1,u2,p1;
int answ[]={0,0,1,2,2,6,12,18,43,86,148,326,652,1194,2531,5062,9578,19884,39768,76680,157236,314472,613440,1248198,2496396,4906266,9932707,19865414,39237478,79165646,158331292,};
int main()
{
//freopen("data.in","r",stdin);
cin>>tip;
if(tip==1)
{
cin>>t;
for(int cnt=1;cnt<=t;cnt++)
{
cin>>s;u1=u2=0;
bool ok=1;
for(i=0;i<s.size();i++)
{
if(s[i]=='(')
{
st1[++u1]=i;
st2[++u2]=i;
}
else
{
if(u1)
{
ans[st1[u1]]='R';
u1--;
ans[i]='R';
}
else
{
if(u2)
{
ans[st2[u2]]='G';
u2--;
ans[i]='B';
}
else ok=0;
}
}
}
p1=1;
for(i=0;i<s.size();i++)
if(s[i]==')')
{
if(p1<=u1&&st1[p1]<=i)
{
ans[st1[p1]]='B';
p1++;
ans[i]='G';
}
}
for(i=0;i<s.size();i++)
if(!ans[i])
ok=0;
if(p1<=u1||(!ok))
{
for(i=0;i<s.size();i++)
ans[i]=0;
cout<<"impossible\n";
continue;
}
cout<<ans<<'\n';
for(i=0;i<s.size();i++)
ans[i]=0;
}
}
else
{
cin>>t;
int x;
for(i=1;i<=t;i++)
{
cin>>x;
cout<<answ[x]<<'\n';
}
}
return 0;
}
Compilation message
parentrises.cpp: In function 'int main()':
parentrises.cpp:22:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<s.size();i++)
~^~~~~~~~~
parentrises.cpp:50:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<s.size();i++)
~^~~~~~~~~
parentrises.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<s.size();i++)
~^~~~~~~~~
parentrises.cpp:65:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<s.size();i++)
~^~~~~~~~~
parentrises.cpp:71:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<s.size();i++)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
472 KB |
Output is correct |
2 |
Correct |
3 ms |
548 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
472 KB |
Output is correct |
2 |
Correct |
3 ms |
548 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
472 KB |
Output is correct |
2 |
Correct |
3 ms |
548 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
6 ms |
620 KB |
Output is correct |
12 |
Correct |
3 ms |
692 KB |
Output is correct |
13 |
Correct |
3 ms |
692 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
5 ms |
692 KB |
Output is correct |
16 |
Correct |
28 ms |
692 KB |
Output is correct |
17 |
Correct |
8 ms |
1208 KB |
Output is correct |
18 |
Correct |
9 ms |
1208 KB |
Output is correct |
19 |
Correct |
8 ms |
1208 KB |
Output is correct |
20 |
Correct |
9 ms |
1288 KB |
Output is correct |
21 |
Correct |
160 ms |
1448 KB |
Output is correct |
22 |
Correct |
53 ms |
5748 KB |
Output is correct |
23 |
Correct |
47 ms |
5748 KB |
Output is correct |
24 |
Correct |
58 ms |
5748 KB |
Output is correct |
25 |
Correct |
58 ms |
5748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5748 KB |
Output is correct |
2 |
Correct |
3 ms |
5748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5748 KB |
Output is correct |
2 |
Correct |
3 ms |
5748 KB |
Output is correct |
3 |
Incorrect |
4 ms |
5748 KB |
Output isn't correct |