Submission #797819

#TimeUsernameProblemLanguageResultExecution timeMemory
797819amirhoseinfar1385Kangaroo (CEOI16_kangaroo)C++17
51 / 100
603 ms210888 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=200+10; int mod=1e9+7; long long dp[maxn][maxn][maxn][2],pd[maxn][maxn]; int n,s,e; int ww(long long a){ a%=mod; return a; } void calpd(){ pd[1][1]=1; pd[2][1]=0; pd[2][2]=1; for(int i=3;i<=n;i++){ if((i&1)==0){ for(int j=1;j<=i;j++){ pd[i][j]=pd[i][j-1]+pd[i-1][i-j+1]+pd[i-1][j-1]; pd[i][j]=ww(pd[i][j]); // cout<<i<<" "<<j<<" "<<pd[i][j]<<"\n"; } } else{ for(int j=2;j<=i;j++){ pd[i][j]=pd[i][j-1]+mod-pd[i-1][j-1]+pd[i-1][i-j+1]; pd[i][j]=ww(pd[i][j]); // cout<<i<<" "<<j<<" "<<pd[i][j]<<"\n"; } } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>s>>e; if(s>e){ swap(s,e); } calpd(); dp[0][0][0][0]=1; for(int sum=1;sum<=n;sum++){ for(int fn=1;fn<=sum;fn++){ for(int i=sum-fn;i>=0;i--){ int j=sum-fn-i; for(int k=0;k<2;k++){ dp[fn][i][j][k]=dp[fn-1][i+1][j][k]; if(k==0){ dp[fn][i][j][k]+=pd[j+i+fn][j+1]; // if(j>0){ // dp[fn][i][j][k]+=dp[j-1][1][fn+i-1][k]; // } dp[fn][i][j][k]+=dp[fn-1][i][j][k^1]; } else{ dp[fn][i][j][k]+=pd[fn+i+j][fn+i]; if(pd[fn+i+j][fn+i]!=dp[fn+i-1][0][j][0]){ cout<<"yekhoda "<<fn<<" "<<i<<" "<<j<<" "<<pd[fn+i+j][fn+i]<<" "<<dp[fn+i-1][0][j][0]<<"\n"; } // if(fn+i>=2){ // dp[fn][i][j][k]+=dp[fn+i-2][1][j][k^1]; // } dp[fn][i][j][k]+=mod-dp[fn-1][i][j][k^1]; } dp[fn][i][j][k]=ww(ww(dp[fn][i][j][k])); } } } } int res=ww(dp[e-s][s-1][n-e][0]+dp[e-s][s-1][n-e][1]); s++; res+=mod-ww(dp[e-s][s-1][n-e][0]+dp[e-s][s-1][n-e][1]); res=ww(res); cout<<res<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...