#include <bits/stdc++.h>
using namespace std;
string s;
int a[1000007],parc[1000007];
char c[1000007];
int main()
{
int p;
int t;
cin>>p>>t;
if(p==1)
{
while(t--)
{
cin>>s;
int n=s.size(),sum=0,bs=0,rs=0;
bool pr=false;
for(int i=0;i<n;i++) a[i]=s[i]=='('?1:-1;
for(int i=0;i<n;i++) sum+=a[i];
parc[n]=0;
for(int i=n-1;i>=0;i--) parc[i]=parc[i+1]+(1-a[i])/2;
for(int i=0;i<n;i++) if(a[i]==1 && sum<parc[i]) {sum++; s[i]='G';}
for(int i=n-1;i>=0;i--) if(a[i]==-1 && sum>0) {sum--; s[i]='G';}
for(int i=0;i<n;i++)
{
if(s[i]=='G') {bs+=a[i]; rs+=a[i];}
if(s[i]=='(')
{
if(bs<rs) {bs+=a[i]; s[i]='B';}
else {rs+=a[i]; s[i]='R';}
}
if(s[i]==')')
{
if(bs>rs) {bs+=a[i]; s[i]='B';}
else {rs+=a[i]; s[i]='R';}
}
if(bs<0 || rs<0) pr=true;
}
if(bs!=0 || rs!=0) pr=true;
if(pr) cout<<"impossible"<<endl;
else cout<<s<<endl;
}
}
else cout<<"JBG";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
612 KB |
Output is correct |
2 |
Correct |
2 ms |
612 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
652 KB |
Output is correct |
5 |
Correct |
2 ms |
652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
612 KB |
Output is correct |
2 |
Correct |
2 ms |
612 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
652 KB |
Output is correct |
5 |
Correct |
2 ms |
652 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
668 KB |
Output is correct |
8 |
Correct |
2 ms |
672 KB |
Output is correct |
9 |
Correct |
2 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
612 KB |
Output is correct |
2 |
Correct |
2 ms |
612 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
652 KB |
Output is correct |
5 |
Correct |
2 ms |
652 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
668 KB |
Output is correct |
8 |
Correct |
2 ms |
672 KB |
Output is correct |
9 |
Correct |
2 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
11 |
Correct |
3 ms |
880 KB |
Output is correct |
12 |
Correct |
3 ms |
948 KB |
Output is correct |
13 |
Correct |
2 ms |
948 KB |
Output is correct |
14 |
Correct |
3 ms |
948 KB |
Output is correct |
15 |
Correct |
3 ms |
948 KB |
Output is correct |
16 |
Correct |
22 ms |
1012 KB |
Output is correct |
17 |
Correct |
9 ms |
2144 KB |
Output is correct |
18 |
Correct |
7 ms |
2144 KB |
Output is correct |
19 |
Correct |
8 ms |
2144 KB |
Output is correct |
20 |
Correct |
8 ms |
2416 KB |
Output is correct |
21 |
Correct |
186 ms |
3200 KB |
Output is correct |
22 |
Correct |
72 ms |
13300 KB |
Output is correct |
23 |
Correct |
61 ms |
13300 KB |
Output is correct |
24 |
Correct |
65 ms |
13300 KB |
Output is correct |
25 |
Correct |
69 ms |
16260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16260 KB |
Expected integer, but "JBG" found |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16260 KB |
Expected integer, but "JBG" found |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16260 KB |
Expected integer, but "JBG" found |