Submission #797825

#TimeUsernameProblemLanguageResultExecution timeMemory
797825amirhoseinfar1385Kangaroo (CEOI16_kangaroo)C++17
100 / 100
814 ms85876 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=2000+10; int mod=1e9+7; long long 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"; } } } } map<pair<pair<int,int>,int>,int>mp; long long caldp(int fn,int i,int j,int k){ long long res=0; if(fn==0){ if(i==0&&j==0&&k==0){ return 1; } return 0; } if(mp.count(make_pair(make_pair(fn,i),k))!=0){ return mp[make_pair(make_pair(fn,i),k)]; } res+=caldp(fn-1,i+1,j,k); if(k==0){ res+=pd[j+i+fn][j+1]; res+=caldp(fn-1,i,j,k^1); } else{ res+=pd[fn+i+j][fn+i]; res+=mod-caldp(fn-1,i,j,k^1); } res=ww(ww(res)); mp[make_pair(make_pair(fn,i),k)]=res; return res; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>s>>e; if(s>e){ swap(s,e); } 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...