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;
const int N = 505, M = 1e9 + 7;
int A[N][N][N], D[N][N][N];
void add(int& x, int y) { x += y; if (x >= M) x -= M; }
void sub(int& x, int y) { x -= y; if (x < 0) x += M; }
int sum(int x, int y) { x += y; if (x >= M) x -= M; return x; }
int dif(int x, int y) { x -= y; if (x < 0) x += M; return x; }
int n, s, t;
int main() {
cin.tie(0)->sync_with_stdio(0); cout.tie(0);
cin >> n >> s >> t;
if (s > t) swap(s, t);
A[2][1][2] = D[2][2][1] = 1;
for (int i = 3; i <= n; ++i) {
for (int s = 1; s <= i; ++s) {
for (int t = i; t; --t) {
if (s == t) continue;
if (s > t) {
A[i][s][t] = A[i][t][s];
D[i][s][t] = D[i][t][s];
continue;
}
if (s == 1) {
for (int j = s; j <= i - 1; ++j) {
add(A[i][s][t], D[i - 1][j][t - 1]);
}
for (int j = 1; j <= s - 1; ++j) {
add(D[i][s][t], A[i - 1][j][t - 1]);
}
} else {
A[i][s][t] = dif(A[i][s - 1][t], D[i - 1][s - 1][t - 1]);
D[i][s][t] = sum(D[i][s - 1][t], A[i - 1][s - 1][t - 1]);
}
// cerr << i << ' ' << s << ' ' << t << ' ' << A[i][s][t] << ' ' << D[i][s][t] << '\n';
}
}
}
cout << sum(A[n][s][t], D[n][s][t]);
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... |