This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int mod=1e9+7;
int pd[maxn][maxn],res[maxn][maxn][2];
int n,s,e;
inline int ww(long long a){
if(a>=mod){
a-=mod;
}
return a;
}
inline 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]=ww(ww(pd[i][j-1]+pd[i-1][i-j+1])+pd[i-1][j-1]);
}
}
else{
for(int j=2;j<=i;j++){
pd[i][j]=ww(ww(pd[i][j-1]+mod-pd[i-1][j-1])+pd[i-1][i-j+1]);
}
}
}
}
int caldp(int fn,int i,int j,int k){
int 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=ww(mainres);
mainres+=caldp(fn-1,i,j,k^1);
mainres=ww(mainres);
}
else{
mainres+=pd[fn+i+j][fn+i];
mainres=ww(mainres);
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |