# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
263613 | 2020-08-13T21:59:40 Z | TadijaSebez | parentrises (BOI18_parentrises) | C++11 | 270 ms | 223736 KB |
#include <bits/stdc++.h> using namespace std; const int N=305; const int mod=1e9+7; int dp[N][N*2][N*2]; const int H=1000050; char s[H],ans[H]; int main(){ int t; scanf("%i",&t); if(t==1){ int q; scanf("%i",&q); while(q--){ scanf("%s",s+1); int n=strlen(s+1); for(int i=1;i<=n;i++)ans[i]='B'; int cnt=0; for(int i=1,bal=0;i<=n;i++){ if(s[i]=='(')bal++; else bal--; if(bal<0){ ans[i]='R'; cnt++; bal=0; } } for(int i=1;i<=n;i++){ if(cnt&&s[i]=='('){ ans[i]='G'; cnt--; } } cnt=0; for(int i=n,bal=0;i>=1;i--){ if(s[i]==')')bal++; else bal--; if(bal<0){ ans[i]='R'; cnt++; bal=0; } } for(int i=n;i>=1;i--){ if(cnt&&s[i]==')'){ ans[i]='G'; cnt--; } } bool ok=1; int b1=0,b2=0; for(int i=1;i<=n;i++){ if(s[i]=='('){ if(ans[i]=='G')b1++,b2++; else if(ans[i]=='B')b1++; else b2++; } else{ if(ans[i]=='G')b1--,b2--; else if(ans[i]=='B')b1--; else b2--; } if(b1<0||b2<0)ok=0; } if(b1!=0||b2!=0)ok=0; if(ok){ ans[n+1]=0; printf("%s\n",ans+1); }else printf("impossible\n"); } }else{ dp[0][0][0]=1; for(int i=0;i<N-1;i++){ for(int j=0;j<=2*i;j++){ for(int k=0;k<=2*i;k++){ dp[i+1][j+2][k+1]+=dp[i][j][k]; if(dp[i+1][j+2][k+1]>=mod)dp[i+1][j+2][k+1]-=mod; if(j>0){ dp[i+1][j-1][max(k-2,0)]+=dp[i][j][k]; if(dp[i+1][j-1][max(k-2,0)]>=mod)dp[i+1][j-1][max(k-2,0)]-=mod; } } } } int q; scanf("%i",&q); while(q--){ int n,ans=0; scanf("%i",&n); for(int j=0;j<=n*2;j++){ ans+=dp[n][j][0]; if(ans>=mod)ans-=mod; } printf("%i\n",ans); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 512 KB | Output is correct |
17 | Correct | 3 ms | 768 KB | Output is correct |
18 | Correct | 3 ms | 512 KB | Output is correct |
19 | Correct | 4 ms | 640 KB | Output is correct |
20 | Correct | 3 ms | 768 KB | Output is correct |
21 | Correct | 50 ms | 2168 KB | Output is correct |
22 | Correct | 34 ms | 4344 KB | Output is correct |
23 | Correct | 22 ms | 2176 KB | Output is correct |
24 | Correct | 29 ms | 3064 KB | Output is correct |
25 | Correct | 32 ms | 4220 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 223736 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 223736 KB | Output is correct |
2 | Correct | 269 ms | 223720 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 241 ms | 223736 KB | Output is correct |
2 | Correct | 269 ms | 223720 KB | Output is correct |
3 | Correct | 270 ms | 223736 KB | Output is correct |