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>
#define eb emplace_back
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define clr(ar) memset(ar, 0, sizeof(ar))
#define fastio ios::sync_with_stdio(false);cin.tie(NULL)
#define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef set<ll> si;
typedef multiset<ll> msi;
typedef map<ll,ll> mii;
const ll INF=1e9;
const ll MOD=1000000007;
ll dp[2001][2001];
int main()
{
fastio;
ll t;
ll i,j,k;
ll n,cs,cf;
cin>>n>>cs>>cf;
dp[1][1]=1;
for(i=2;i<=n;i++){
for(j=1;j<i;j++){
if(i==cs) dp[i][j+1]+=dp[i-1][j],dp[i][j]+=dp[i-1][j];
else if(i==cf) dp[i][j+1]+=dp[i-1][j],dp[i][j]+=dp[i-1][j];
else if(i>cs and i<cf) dp[i][j+1]+=dp[i-1][j]*j, dp[i][j]+=dp[i-1][j]*(2*j-1), dp[i][j-1]+=dp[i-1][j]*(j-1);
else if(i>cf) dp[i][j+1]+=dp[i-1][j]*(j-1), dp[i][j]+=dp[i-1][j]*(2*j-2), dp[i][j-1]+=dp[i-1][j]*(j-1);
else dp[i][j+1]+=dp[i-1][j]*(j+1), dp[i][j]+=dp[i-1][j]*(2*j), dp[i][j-1]+=dp[i-1][j]*(j-1);
dp[i][j-1]%=MOD, dp[i][j]%=MOD, dp[i][j+1]%=MOD;
}
}
cout<<dp[n][1]<<endl;
}
Compilation message (stderr)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:26:8: warning: unused variable 't' [-Wunused-variable]
26 | ll t;
| ^
kangaroo.cpp:27:12: warning: unused variable 'k' [-Wunused-variable]
27 | ll i,j,k;
| ^
# | 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... |