# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839188 | guagua0407 | Kangaroo (CEOI16_kangaroo) | C++17 | 1 ms | 468 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=2005;
const int mod=1e9+7;
ll dp[mxn][mxn];
int cnt=0;
int main() {_
int n,st,en;
cin>>n>>st>>en;
if(st>en) swap(st,en);
dp[1][1]=1;
if(1==st) cnt++;
for(int i=1;i<n;i++){
if(i+1==st){
// new
for(int j=1;j<=i;j++){
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
}
// continue
for(int j=1;j<=i;j++){
dp[i+1][j]=(dp[i+1][j]+dp[i][j]*j)%mod;
}
cnt++;
}
else if(i+1==en){
// new
for(int j=1;j<=i;j++){
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
}
// continue
for(int j=1;j<=i;j++){
dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(j-1+(i==n-1 and j==1)))%mod;
}
cnt++;
}
else{
// new
for(int j=1;j<=i;j++){
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
}
// combine
for(int j=1;j<=i;j++){
dp[i+1][j-1]=(dp[i+1][j-1]+dp[i][j]*(j*(j-1)-(j-1)*cnt+(cnt==2)))%mod;
}
}
}
cout<<dp[n][1]<<'\n';
return 0;
}
//maybe its multiset not set
Compilation message (stderr)
# | 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... |