This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#include <prettyprint.hpp>
#endif
#include<bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lg2(x) __lg(x)
#define rem_dupl(x) sort(all(x)); x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> ii;
#define x first
#define y second
//mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());
const db eps = 1e-9;
const int maxn = (int)2e3 + 5;
const ll mod = (int)1e9 + 7; // 998244353
ll mul(ll a, ll b){
return a * b % mod;
}
ll add(ll a, ll b){
return (a + b)%mod;
}
ll dp[maxn][maxn];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(0);
int n, s, t;
cin >> n >> s >> t;
dp[1][1] = 1;
for(int i = 1; i < n; i++)
for(int j = 1; j <= i; j++){
if(i + 1 == s or i + 1 == t){
dp[i+1][j] = add(dp[i + 1][j], dp[i][j]);
dp[i+1][j+1] = add(dp[i + 1][j + 1], dp[i][j]);
continue;
}
dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1));
dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j + 1 - (int)(i >= s) - (int)(i >= t)));
}
cout << dp[n][1];
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... |