Submission #205309

#TimeUsernameProblemLanguageResultExecution timeMemory
205309TadijaSebezBowling (BOI15_bow)C++11
100 / 100
341 ms1016 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=11; const int M=305; int score[N]; ll dp[M][N][N],tmp[M][N][N]; void Clear(){ for(int i=0;i<M;++i) for(int j=0;j<N;++j) for(int k=0;k<N;++k) tmp[i][j][k]=dp[i][j][k],dp[i][j][k]=0; } void Print(int n){ for(int i=0;i<M;++i) for(int j=0;j<N;++j) for(int k=0;k<N;++k) if(dp[i][j][k]) printf("%i %i %i %i %lld\n",n,i,j,k,dp[i][j][k]); } void Solve(){ int n; string str; scanf("%i",&n); cin>>str; for(int i=1;i<=n;i++)scanf("%i",&score[i]); Clear(); for(int i=0;i<M;++i)if(i==score[n] || score[n]==-1){ string now="";now+=str[n*2-2];now+=str[n*2-1];now+=str[n*2]; //Case 1 xxx if((now[0]=='?' || now[0]=='x') && (now[1]=='?' || now[1]=='x') && (now[2]=='?' || now[2]=='x')){ if(i>=30)dp[i-30][10][10]++; } //Case 2 xxA if((now[0]=='?' || now[0]=='x') && (now[1]=='?' || now[1]=='x')){ for(int A=0;A<10;++A)if(now[2]=='?' || now[2]=='0'+A){ if(i>=20+A)dp[i-20-A][10][10]++; } } //Case 3 xA/ if((now[0]=='?' || now[0]=='x') && (now[2]=='?' || now[2]=='/')){ for(int A=0;A<10;++A)if(now[1]=='?' || now[1]=='0'+A){ if(i>=20)dp[i-20][10][A]++; } } //Case 4 xAB if(now[0]=='?' || now[0]=='x'){ for(int A=0;A<10;++A)if(now[1]=='?' || now[1]=='0'+A) for(int B=0;B<10-A;++B)if(now[2]=='?' || now[2]=='0'+B){ if(i>=10+A+B)dp[i-10-A-B][10][A]++; } } //Case 5 A/x if((now[1]=='?' || now[1]=='/') && (now[2]=='?' || now[2]=='x')){ for(int A=0;A<10;++A)if(now[0]=='?' || now[0]=='0'+A){ if(i>=20)dp[i-20][A][10-A]++; } } //Case 6 A/B if(now[1]=='?' || now[1]=='/'){ for(int A=0;A<10;++A)if(now[0]=='?' || now[0]=='0'+A) for(int B=0;B<10;++B)if(now[2]=='?' || now[2]=='0'+B){ if(i>=10+B)dp[i-10-B][A][10-A]++; } } //Case 7 AB- if(now[2]=='-' || now[2]=='?'){ for(int A=0;A<10;++A)if(now[0]=='?' || now[0]=='0'+A) for(int B=0;B<10-A;++B)if(now[1]=='?' || now[1]=='0'+B){ if(i>=A+B)dp[i-A-B][A][B]++; } } } //Print(n); for(int j=n-1;j>=1;--j){ Clear(); string now="";now+=str[j*2-2];now+=str[j*2-1]; for(int i=0;i<M;++i)if(score[j]==i || score[j]==-1){ for(int F=0;F<N;++F)for(int S=0;S<N;++S)if(tmp[i][F][S]){ //Case 1 x- if((now[0]=='?' || now[0]=='x') && (now[1]=='?' || now[1]=='-')){ if(i>=10+F+S)dp[i-10-F-S][10][F]+=tmp[i][F][S]; } //Case 2 A/ if(now[1]=='?' || now[1]=='/'){ for(int A=0;A<10;++A)if(now[0]=='?' || now[0]=='0'+A){ if(i>=10+F)dp[i-10-F][A][10-A]+=tmp[i][F][S]; } } //Case 3 AB for(int A=0;A<10;++A)if(now[0]=='?' || now[0]=='0'+A) for(int B=0;B<10-A;++B)if(now[1]=='?' || now[1]=='0'+B){ if(i>=A+B)dp[i-A-B][A][B]+=tmp[i][F][S]; } } } //Print(j); } ll ans=0; for(int F=0;F<N;++F)for(int S=0;S<N;++S)ans+=dp[0][F][S]; printf("%lld\n",ans); } int main(){ int t;scanf("%i",&t); while(t--)Solve(); return 0; }

Compilation message (stderr)

bow.cpp: In function 'void Solve()':
bow.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
bow.cpp:26:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++)scanf("%i",&score[i]);
                       ~~~~~^~~~~~~~~~~~~~~~
bow.cpp: In function 'int main()':
bow.cpp:104:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int t;scanf("%i",&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...