제출 #797826

#제출 시각아이디문제언어결과실행 시간메모리
797826amirhoseinfar1385캥거루 (CEOI16_kangaroo)C++17
100 / 100
91 ms86484 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=2000+10; int mod=1e9+7; long long pd[maxn][maxn],res[maxn][maxn][2]; 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"; } } } } long long caldp(int fn,int i,int j,int k){ long long mainres=0; if(fn==0){ if(i==0&&j==0&&k==0){ return 1; } return 0; } if(res[fn][i][k]!=-1){ return res[fn][i][k]; } mainres+=caldp(fn-1,i+1,j,k); if(k==0){ mainres+=pd[j+i+fn][j+1]; mainres+=caldp(fn-1,i,j,k^1); } else{ mainres+=pd[fn+i+j][fn+i]; mainres+=mod-caldp(fn-1,i,j,k^1); } mainres=ww(mainres); res[fn][i][k]=mainres; return mainres; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>s>>e; if(s>e){ swap(s,e); } for(int i=0;i<maxn;i++){ for(int j=0;j<maxn;j++){ for(int h=0;h<2;h++){ res[i][j][h]=-1; } } } calpd(); int res=ww(caldp(e-s,s-1,n-e,0)+caldp(e-s,s-1,n-e,1)); s++; res+=mod-ww(caldp(e-s,s-1,n-e,0)+caldp(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...