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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1e9+7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, s, e; cin >> n >> s >> e; s--, e--;
vector<vector<ll>> dp(n, vector<ll>(n+1, 0));
dp[0][1] = 1;
for(int i = 1; i < n; i++) for(int j = 1; j <= i+1; j++) {
int c = 0;
c+=(s < i);
c+=(e < i);
if(j > 1) dp[i][j]+=dp[i-1][j-1], dp[i][j]%=md;
if(i == s || i == e){
if(c == 0) dp[i][j]+=(dp[i-1][j]*j)%md, dp[i][j]%=md;
else if(i == n-1 && j == 1) dp[i][j]+=dp[i-1][j], dp[i][j]%=md;
else if(j != 1) dp[i][j]+=(dp[i-1][j]*(j-1))%md, dp[i][j]%=md;
}
else if(j+1 <= i){
if(c == 0) dp[i][j]+=(dp[i-1][j+1]*j*(j+1))%md, dp[i][j]%=md;
else if(c == 1) dp[i][j]+=(dp[i-1][j+1]*j*j)%md, dp[i][j]%=md;
else if(i == n-1 && j == 1) dp[i][j]+=dp[i-1][j+1], dp[i][j]%=md;
else if(j != 1) dp[i][j]+=(dp[i-1][j+1]*(j*(j-1)+1))%md, dp[i][j]%=md;
}
}
cout << dp[n-1][1] << "\n";
}
# | 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... |