QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227866#5532. KangarooCamillus51 924ms144328kbC++203.1kb2023-10-28 01:18:352023-10-28 01:18:36

Judging History

你现在查看的是最新测评结果

  • [2023-10-28 01:18:36]
  • 评测
  • 测评结果:51
  • 用时:924ms
  • 内存:144328kb
  • [2023-10-28 01:18:35]
  • 提交

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);
mint recB(int l, int i, int j);

map<tuple<int, int, int>, mint> savedA;

tuple<int, int, int> gett(int l, int i, int j) {
    if (i == 0) {
        return tuple(l, j, 0);
    } else {
        return tuple(l, i, 1);
    }
}

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(gett(l, i, j))) {
        return savedA[gett(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[gett(l, i, j)] = res;
    }

    return savedA[gett(l, i, j)] = recA(l, i - 1, j) - recB(l - 1, i - 1, j - 1);
}

map<tuple<int, int, int>, mint> savedB;

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(gett(l, i, j))) {
        return savedB[gett(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[gett(l, i, j)] = 0;
    }

    return savedB[gett(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: 3424kb

input:

7 3 6

output:

14

result:

ok 1 number(s): "14"

Subtask #2:

score: 30
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 30
Accepted
time: 1ms
memory: 3660kb

input:

39 36 32

output:

964903316

result:

ok 1 number(s): "964903316"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

26 1 26

output:

955348527

result:

ok 1 number(s): "955348527"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3432kb

input:

40 11 33

output:

695661890

result:

ok 1 number(s): "695661890"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

39 39 38

output:

717149364

result:

ok 1 number(s): "717149364"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

40 10 25

output:

912929610

result:

ok 1 number(s): "912929610"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

37 25 23

output:

250748685

result:

ok 1 number(s): "250748685"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3468kb

input:

39 2 38

output:

624060592

result:

ok 1 number(s): "624060592"

Test #9:

score: 0
Accepted
time: 1ms
memory: 3436kb

input:

40 18 22

output:

739993796

result:

ok 1 number(s): "739993796"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

40 11 35


output:

135213497

result:

ok 1 number(s): "135213497"

Subtask #3:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 15
Accepted
time: 4ms
memory: 4972kb

input:

199 100 70

output:

914653136

result:

ok 1 number(s): "914653136"

Test #12:

score: 0
Accepted
time: 6ms
memory: 4524kb

input:

187 3 40

output:

928785584

result:

ok 1 number(s): "928785584"

Test #13:

score: 0
Accepted
time: 18ms
memory: 7088kb

input:

199 198 197

output:

38412688

result:

ok 1 number(s): "38412688"

Test #14:

score: 0
Accepted
time: 7ms
memory: 4764kb

input:

200 40 140

output:

367088143

result:

ok 1 number(s): "367088143"

Test #15:

score: 0
Accepted
time: 7ms
memory: 4664kb

input:

199 111 3

output:

870834793

result:

ok 1 number(s): "870834793"

Test #16:

score: 0
Accepted
time: 4ms
memory: 5020kb

input:

200 133 73

output:

343127012

result:

ok 1 number(s): "343127012"

Test #17:

score: 0
Accepted
time: 5ms
memory: 4380kb

input:

178 15 163

output:

160852284

result:

ok 1 number(s): "160852284"

Test #18:

score: 0
Accepted
time: 7ms
memory: 4932kb

input:

197 43 79

output:

332057544

result:

ok 1 number(s): "332057544"

Test #19:

score: 0
Accepted
time: 7ms
memory: 4904kb

input:

200 33 79

output:

742545318

result:

ok 1 number(s): "742545318"

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #20:

score: 49
Accepted
time: 89ms
memory: 18892kb

input:

658 169 438

output:

206087110

result:

ok 1 number(s): "206087110"

Test #21:

score: 0
Accepted
time: 97ms
memory: 21444kb

input:

700 207 509

output:

478311263

result:

ok 1 number(s): "478311263"

Test #22:

score: 0
Accepted
time: 106ms
memory: 22500kb

input:

755 139 507

output:

103783948

result:

ok 1 number(s): "103783948"

Test #23:

score: 0
Accepted
time: 924ms
memory: 144328kb

input:

2000 500 1500

output:

123410309

result:

ok 1 number(s): "123410309"

Test #24:

score: -49
Time Limit Exceeded

input:

2000 1000 1001

output:


result: