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;
const int mod = 1e9 + 7;
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int mul(int x, int y) {
return (long long) (x * y) % mod;
}
int sub(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
const int N = 2005;
int a, b, dif, dp[N][N], ft[N][N];
bool was[N][N];
long long Solve(int n, int id) {
if (was[n][id]) {
return dp[n][id];
}
was[n][id] = true;
if (id == 1) {
return dp[n][id] = ft[n][n - dif];
}
else if (id == 2) {
return dp[n][id] = add(ft[n][n - dif], ft[n - 1][n - 1 - dif]);
} else {
return dp[n][id] = sub(sub(mul(2, Solve(n, id - 1)), Solve(n, id - 2)), Solve(n - 2, id - 2));
}
}
void Precalc(int n) {
ft[2][2] = 1; // pocetni slucaj
for (int i = 3; i <= n; i++) {
if (i % 2 == 1) {
int sum = 0;
for (int j = 2; j < n; j++) {
sum = add(sum, ft[i - 1][j]);
}
ft[i][2] = add(ft[i][2], sum);
}
for (int j = 3; j <= i; j++) {
if (i % 2 == 1) {
ft[i][j] = sub(ft[i][j - 1], ft[i - 1][j - 1]);
} else {
ft[i][j] = add(ft[i][j - 1], ft[i - 1][j - 1]);
}
}
}
}
long long resi(int n) {
Precalc(n);
return Solve(n, a);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n >> a >> b;
if (a > b) {
swap(a, b);
}
dif = n - b;
cout << resi(n) << '\n';
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... |