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;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int N = 2002, MOD = 1e9+7;
int n, s, t, f[N][N][2][2];
void add(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int mul(int a, int b) {
return 1LL * a * b % MOD;
}
int main() {
setIO();
cin >> n >> s >> t;
f[0][0][0][0] = 1;
foru(i, 0, n-1)
foru(cc0, 0, i)
foru(cc1, 0, 1)
foru(cc2, 0, 1) {
int ret = f[i][cc0][cc1][cc2];
if (ret == 0) continue;
if (i+1 == s) {
add(f[i+1][cc0][1][cc2], ret);
if (cc0 > 0) add(f[i+1][cc0-1][1][cc2], mul(ret, cc0));
continue;
}
if (i+1 == t) {
add(f[i+1][cc0][cc1][1], ret);
if (cc0 > 0) add(f[i+1][cc0-1][cc1][1], mul(ret, cc0));
continue;
}
add(f[i+1][cc0+1][cc1][cc2], ret);
if (cc0 > 1) add(f[i+1][cc0-1][cc1][cc2], mul(mul(cc0, cc0-1), ret));
if (cc1 && cc0 > 0) add(f[i+1][cc0-1][cc1][cc2], mul(ret, cc0));
if (cc2 && cc0 > 0) add(f[i+1][cc0-1][cc1][cc2], mul(ret, cc0));
}
cout << f[n][0][1][1];
}
Compilation message (stderr)
kangaroo.cpp: In function 'void setIO()':
kangaroo.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |