# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63036 | 2018-07-31T11:44:12 Z | hamzqq9 | parentrises (BOI18_parentrises) | C++14 | 86 ms | 4652 KB |
#include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define ppb pop_back #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<ii,int> #define sz(x) (x.size()) #define orta ((bas+son)>>1) #define all(x) x.begin(),x.end() #define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" " #define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar() #define pw(x) (1<<(x)) #define inf 1000500000 #define MOD 1000000007 #define N 305 #define LOG 20 using namespace std; int p,t,x,n; int cnt[2][N][N],res[N]; char s[1000006],col[1000006]; bool check() { int lastbal=0,allbal=0; for(int i=1;i<=n;i++) { if(s[i]=='(') { allbal++; lastbal++; } else { lastbal=max(0,lastbal-2); } if(2*allbal<(i-allbal)) return false; } return (lastbal==0); } void print() { for(int i=1;i<=n;i++) printf("%c",col[i]); puts(""); } void dec() { stack<int> pos; int tot=0; for(int i=n;i>=1;i--) { if(s[i]==')') { tot++; } else { if(tot) { tot--; pos.push(i); } else { int a=pos.top(); pos.pop(); col[a]='B'; col[i]='R'; } } } } void inc() { stack<int> pos; int tot=0; for(int i=1;i<=n;i++) { if(s[i]=='(') { tot++; col[i]='G'; } else { if(!tot) { int a=pos.top(); pos.pop(); col[a]='R'; col[i]='B'; } else { tot--; col[i]='G'; pos.push(i); } } } } void find_ans() { if(!check()) { printf("impossible\n"); return ; } inc(); dec(); print(); } void solve1() { while(t--) { scanf("%s",s+1); n=strlen(s+1); find_ans(); } } void dp() { cnt[1][0][0]=1; for(int i=0;i<N;i++) { for(int j=0;j<=i;j++) { for(int k=0;k<=j;k++) { if(j*2<i-j) cnt[1][j][k]=0; cnt[0][j][k]=cnt[1][j][k]; if(k==0) res[i]=(res[i]+cnt[0][j][k])%MOD; } } memset(cnt[1],0,sizeof(cnt[1])); for(int j=0;j<=i;j++) { for(int k=0;k<=j;k++) { cnt[1][j+1][k+1]=(cnt[1][j+1][k+1]+cnt[0][j][k])%MOD; cnt[1][j][max(0,k-2)]=(cnt[1][j][max(0,k-2)]+cnt[0][j][k])%MOD; } } } } void solve2() { dp(); while(t--) { scanf("%d",&x); printf("%d\n",res[x]); } } int main() { // freopen("input.txt","r",stdin); scanf("%d %d",&p,&t); if(p==1) solve1(); else solve2(); }
Compilation message
# | 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 | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 540 KB | Output is correct |
2 | Correct | 2 ms | 540 KB | Output is correct |
3 | Correct | 2 ms | 540 KB | Output is correct |
4 | Correct | 3 ms | 540 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 540 KB | Output is correct |
2 | Correct | 2 ms | 540 KB | Output is correct |
3 | Correct | 2 ms | 540 KB | Output is correct |
4 | Correct | 3 ms | 540 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 580 KB | Output is correct |
7 | Correct | 2 ms | 620 KB | Output is correct |
8 | Correct | 2 ms | 620 KB | Output is correct |
9 | Correct | 2 ms | 620 KB | Output is correct |
10 | Correct | 2 ms | 620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 540 KB | Output is correct |
2 | Correct | 2 ms | 540 KB | Output is correct |
3 | Correct | 2 ms | 540 KB | Output is correct |
4 | Correct | 3 ms | 540 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 580 KB | Output is correct |
7 | Correct | 2 ms | 620 KB | Output is correct |
8 | Correct | 2 ms | 620 KB | Output is correct |
9 | Correct | 2 ms | 620 KB | Output is correct |
10 | Correct | 2 ms | 620 KB | Output is correct |
11 | Correct | 3 ms | 620 KB | Output is correct |
12 | Correct | 3 ms | 620 KB | Output is correct |
13 | Correct | 2 ms | 636 KB | Output is correct |
14 | Correct | 3 ms | 652 KB | Output is correct |
15 | Correct | 4 ms | 652 KB | Output is correct |
16 | Correct | 6 ms | 668 KB | Output is correct |
17 | Correct | 10 ms | 1052 KB | Output is correct |
18 | Correct | 8 ms | 1052 KB | Output is correct |
19 | Correct | 8 ms | 1052 KB | Output is correct |
20 | Correct | 12 ms | 1052 KB | Output is correct |
21 | Correct | 32 ms | 1436 KB | Output is correct |
22 | Correct | 82 ms | 4596 KB | Output is correct |
23 | Correct | 55 ms | 4596 KB | Output is correct |
24 | Correct | 86 ms | 4596 KB | Output is correct |
25 | Correct | 83 ms | 4652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 4652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 4652 KB | Output is correct |
2 | Correct | 41 ms | 4652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 4652 KB | Output is correct |
2 | Correct | 41 ms | 4652 KB | Output is correct |
3 | Correct | 39 ms | 4652 KB | Output is correct |