QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227759 | #5532. Kangaroo | Camillus | 6 | 1ms | 3544kb | C++20 | 2.7kb | 2023-10-27 22:40:15 | 2023-10-27 22:40:16 |
answer
#include <bits/stdc++.h>
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, int b = 0);
mint recB(int l, int i, int j, int b = 0);
map<tuple<int, int, int>, mint> savedA;
mint recA(int l, int i, int j, int b) {
if (i > j) {
if (l % 2 == 0) {
return recB(l, j, i, b ^ 1);
} else {
return recA(l, j, i, b ^ 1);
}
}
if (savedA.contains(tuple(l, i, b))) {
return savedA[tuple(l, i, b)];
}
if (l == 1) {
if (i == 0 && j == 0) {
return 1;
} else {
return 0;
}
}
if (i == j) {
return 0;
}
if (i == 0) {
mint res = 0;
for (int k = i + 1; k < l; k++) {
res = res + recB(l - 1, k - 1, j - 1, b);
}
return savedA[tuple(l, i, b)] = res;
}
return savedA[tuple(l, i, b)] = recA(l, i - 1, j, b) - recB(l - 1, i - 1, j - 1, b);
}
map<tuple<int, int, int>, mint> savedB;
mint recB(int l, int i, int j, int b) {
if (i > j) {
if (l % 2 == 0) {
return recA(l, j, i, b ^ 1);
} else {
return recB(l, j, i, b ^ 1);
}
}
if (savedB.contains(tuple(l, i, b))) {
return savedB[tuple(l, i, b)];
}
if (l == 1) {
if (i == 0 && j == 0) {
return 1;
} else {
return 0;
}
}
if (i == j) {
return 0;
}
if (i == 0) {
mint res = 0;
for (int k = 0; k < i; k++) {
res = res + recA(l - 1, k, j - 1, b);
}
return savedB[tuple(l, i, b)] = res;
}
return savedB[tuple(l, i, b)] = recB(l, i - 1, j, b) + recA(l - 1, i - 1, j - 1, b);
}
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;
}
详细
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 1ms
memory: 3424kb
input:
7 3 6
output:
14
result:
ok 1 number(s): "14"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 3544kb
input:
39 36 32
output:
27739315
result:
wrong answer 1st numbers differ - expected: '964903316', found: '27739315'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%