Submission #63005

#TimeUsernameProblemLanguageResultExecution timeMemory
63005hamzqq9parentrises (BOI18_parentrises)C++14
50 / 100
62 ms1332 KiB
#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 fill_r(int bas,int son) { int op=0; int tot=son-bas+1; for(int i=bas;i<=son;i++) op+=(s[i]=='('); if(op>tot-op) { int putG=op-(tot-op); int putB=putG; for(int i=son;i>=bas;i--) { if(s[i]==')' && putG) { --putG; col[i]='G'; } else if(s[i]==')') { col[i]='R'; } if(s[i]=='(' && putB) { --putB; col[i]='B'; } else if(s[i]=='(') { col[i]='R'; } } } else { int putG=(tot-op)-op; int putB=putG; for(int i=bas;i<=son;i++) { if(s[i]=='(' && putG) { --putG; col[i]='G'; } else if(s[i]=='(') { col[i]='R'; } if(s[i]==')' && putB) { --putB; col[i]='B'; } else if(s[i]==')') { col[i]='R'; } } } } void create(int now) { int cur_op=0; for(int i=now;i<=n;i++) { if(s[i]=='(' && cur_op<0) { fill_r(now,i-1); create(i); return ; } if(s[i]=='(') cur_op++; else cur_op--; } fill_r(now,n); } void print() { for(int i=1;i<=n;i++) printf("%c",col[i]); puts(""); } void find_ans() { if(!check()) { printf("impossible\n"); return ; } create(1); 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 (stderr)

parentrises.cpp: In function 'void solve1()':
parentrises.cpp:189:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s+1);
   ~~~~~^~~~~~~~~~
parentrises.cpp: In function 'void solve2()':
parentrises.cpp:242:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
parentrises.cpp: In function 'int main()':
parentrises.cpp:254:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&p,&t);
  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...