#include<bits/stdc++.h>
using namespace std;
#define _ int v, int tl, int tr, int l, int r
#define tm (tl+tr >> 1)
#define sol v+v,tl,tm,l,r
#define sag v+v+1,tm+1,tr,l,r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pp pair<int,int>
const int mod = 1e9 + 7;
const int N = 1e6 + 6;
int V[N],v,zz,ww,n,i,p,ok;
char s[N],ans[N];
int MM[301][301];
int g(int n, int k){
if(k < 0) return 0;
if(n == 0) return !k;
int &r = MM[n][k];
if(r != -1) return r;
return r = (g(n-1,k+1) + g(n-1,k-1)) % mod;
}
int M[301][301];
int f(int i, int k){
int t = i-k;
if(t&1) return 0;
t >>= 1;
if(t+k > t+t) return 0;
if(!i) return !k;
if(k<0) return 0;
int &r = M[i][k];
if(r != -1) return r;
r = 0;
for(int j=i-1; j>=0 ; j--)
r = (r + 1LL * f(j,k-1) * g(i-j-1,0)) % mod;
return r;
}
int T[301],asd,j;
int main(){
scanf("%d%d",&zz,&ww);
if(zz == 2){
memset(M,-1,sizeof M);
memset(MM,-1,sizeof MM);
for(i=0;i<301;i++)
for(j=0;j<=i;j++)
T[i] = (T[i] + f(i,j)) % mod;
for(;ww--;){
scanf("%d",&n);
asd = 0;
for(i=0;i<=n;i++)
for(j=n-i; j>=0 ;j--)
asd = (asd + 1LL*T[i]*T[j]%mod*g(n-i-j,0)) % mod;
printf("%d\n", asd);
}
return 0;
}
for(;ww--;){
scanf(" %s",s+1);
n = strlen(s+1);
p = v = 0;
ok = 1;
for(i=1;i<=n;i++) ans[i] = 'G';
ans[n+1] = 0;
for(i=1;i<=n;i++){
p += s[i] == ')' ? 1 : -1;
if(s[i] == ')') V[++v] = i;
if(p > 0){
ans[ V[v--] ] = 'B';
ans[ V[v--] ] = 'R';
p = 0;
if(v == -1) { ok=0; break; }
}
}
p = v = 0;
for(i=n; i ;i--){
p += s[i] == '(' ? 1 : -1;
if(s[i] == '(') V[++v] = i;
if(p > 0){
ans[ V[v--] ] = 'B';
ans[ V[v--] ] = 'R';
p = 0;
if(v == -1) { ok=0; break; }
}
}
puts(ok ? ans+1 : "impossible");
}
return 0;
}
Compilation message
parentrises.cpp: In function 'int main()':
parentrises.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&zz,&ww);
~~~~~^~~~~~~~~~~~~~~~
parentrises.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
parentrises.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s",s+1);
~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
2 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
2 ms |
676 KB |
Output is correct |
6 |
Correct |
3 ms |
676 KB |
Output is correct |
7 |
Correct |
3 ms |
676 KB |
Output is correct |
8 |
Correct |
3 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
676 KB |
Output is correct |
10 |
Correct |
3 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
2 ms |
676 KB |
Output is correct |
6 |
Correct |
3 ms |
676 KB |
Output is correct |
7 |
Correct |
3 ms |
676 KB |
Output is correct |
8 |
Correct |
3 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
676 KB |
Output is correct |
10 |
Correct |
3 ms |
744 KB |
Output is correct |
11 |
Correct |
3 ms |
744 KB |
Output is correct |
12 |
Correct |
2 ms |
744 KB |
Output is correct |
13 |
Correct |
3 ms |
744 KB |
Output is correct |
14 |
Correct |
3 ms |
744 KB |
Output is correct |
15 |
Correct |
3 ms |
744 KB |
Output is correct |
16 |
Correct |
6 ms |
744 KB |
Output is correct |
17 |
Correct |
6 ms |
1052 KB |
Output is correct |
18 |
Correct |
5 ms |
1052 KB |
Output is correct |
19 |
Correct |
4 ms |
1052 KB |
Output is correct |
20 |
Correct |
6 ms |
1056 KB |
Output is correct |
21 |
Correct |
25 ms |
1308 KB |
Output is correct |
22 |
Correct |
27 ms |
5544 KB |
Output is correct |
23 |
Correct |
15 ms |
5544 KB |
Output is correct |
24 |
Correct |
26 ms |
5544 KB |
Output is correct |
25 |
Correct |
27 ms |
5544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
5544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
5544 KB |
Output is correct |
2 |
Correct |
19 ms |
5544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
5544 KB |
Output is correct |
2 |
Correct |
19 ms |
5544 KB |
Output is correct |
3 |
Correct |
64 ms |
5544 KB |
Output is correct |