QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227867 | #5532. Kangaroo | Camillus | 6 | 0ms | 70376kb | C++20 | 3.6kb | 2023-10-28 01:23:45 | 2023-10-28 01:23:46 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct mint {
static constexpr int mod = 1'000'000'007;
int value = 0;
mint() = default;
mint(int value) : value(value) {}
};
mint operator+(const mint &A, const mint &B) {
int value = A.value + B.value;
if (value >= mint::mod) {
value -= mint::mod;
}
return mint(value);
}
mint operator-(const mint &A, const mint &B) {
int value = A.value + mint::mod - B.value;
if (value >= mint::mod) {
value -= mint::mod;
}
return mint(value);
}
mint operator*(const mint &A, const mint &B) {
return mint(1ll * A.value * B.value % mint::mod);
}
mint recA(int l, int i, int j);
mint recB(int l, int i, int j);
struct saved {
vector<vector<mint>> data0;
vector<vector<bool>> mark0;
vector<vector<mint>> data1;
vector<vector<bool>> mark1;
saved() {
data0 = vector<vector<mint>>(2024, vector<mint>(2024));
data1 = vector<vector<mint>>(2024, vector<mint>(2024));
mark0 = vector<vector<bool>>(2024, vector<bool>(2024));
mark1 = vector<vector<bool>>(2024, vector<bool>(2024));
}
bool contains(int l, int i, int j) const {
if (i == 0) {
return mark0[l][j];
} else {
return mark1[l][i];
}
};
mint& get(int l, int i, int j) {
if (i == 0) {
return data0[l][j];
} else {
return data1[l][i];
}
}
};
saved savedA;
saved savedB;
mint recA(int l, int i, int j) {
if (i > j) {
if (l % 2 == 0) {
return recB(l, j, i);
} else {
return recA(l, j, i);
}
}
if (savedA.contains(l, i, j)) {
return savedA.get(l, i, j);
}
if (l == 1) {
if (i == 0 && j == 0) {
return 1;
} else {
return 0;
}
}
if (i == j) {
return 0;
}
if (i == 0) {
mint res = 0;
if (l % 2 == 0) {
if (j == 1) {
for (int k = 0; k < j; k++) {
res = res + recA(l - 1, 0, k);
}
} else {
res = recA(l, 0, j - 1) + recA(l - 1, 0, j - 1);
}
} else {
if (j == 1) {
for (int k = j; k <= l - 2; k++) {
res = res + recA(l - 1, 0, k);
}
} else {
res = recA(l, 0, j - 1) - recA(l - 1, 0, j - 1);
}
}
return savedA.get(l, i, j) = res;
}
return savedA.get(l, i, j) = recA(l, i - 1, j) - recB(l - 1, i - 1, j - 1);
}
mint recB(int l, int i, int j) {
if (i > j) {
if (l % 2 == 0) {
return recA(l, j, i);
} else {
return recB(l, j, i);
}
}
if (savedB.contains(l, i, j)) {
return savedB.get(l, i, j);
}
if (l == 1) {
if (i == 0 && j == 0) {
return 1;
} else {
return 0;
}
}
if (i == j) {
return 0;
}
if (i == 0) {
return savedB.get(l, i, j) = 0;
}
return savedB.get(l, i, j) = recB(l, i - 1, j) + recA(l - 1, i - 1, j - 1);
}
signed main() {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, s, f;
cin >> n >> s >> f;
s--, f--;
cout << (recA(n, s, f) + recB(n, s, f)).value << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 0ms
memory: 70376kb
input:
7 3 6
output:
14
result:
ok 1 number(s): "14"
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #2:
score: 0
Time Limit Exceeded
input:
39 36 32
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%