62382023-11-08 12:44:30Error42Tömbök előállításacpp17Runtime error 35/1001.23s521888 KiB
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

template <ll M>
struct modular {
    ll val;

    // n >= 0
    modular(const ll n) {
        if (n < M)
            val = n;
        else if (n < 2 * M)
            val = n - M;
        else
            val = n % M;
    }

    [[nodiscard]] modular operator +(const modular& rhs) const {
        return val + rhs.val;
    }

    [[nodiscard]] modular operator -(const modular& rhs) const {
        return val + M - rhs.val;
    }

    [[nodiscard]] modular operator *(const modular& rhs) const {
        return val * rhs.val;
    }

    // p >= 0
    [[nodiscard]] modular pow(const ll& p) const {
        if (p == 0)
            return 1;

        if (p % 2 == 0)
            return (*this * *this).pow(p / 2);
        else
            return *this * pow(p - 1);
    }

    [[nodiscard]] modular inv() const {
        return pow(M - 2);
    }

    [[nodiscard]] modular operator /(const modular& rhs) const {
        return *this * rhs.inv();
    }

    modular& operator +=(const modular& rhs) {
        return *this = *this + rhs;
    }

    modular& operator -=(const modular& rhs) {
        return *this = *this - rhs;
    }

    modular& operator *=(const modular& rhs) {
        return *this = *this * rhs;
    }

    modular& operator /=(const modular& rhs) {
        return *this = *this / rhs;
    }

    explicit operator ll() const {
        return val;
    }
};

template <ll M>
ostream& operator<<(ostream& os, const modular<M>& modular) {
    cout << modular.val;
    return os;
}

using mod = modular<1'000'000'007>;

ll n, m, l, r, k;

vector<mod> identity;

vector<mod> combine(vector<mod> const& a, vector<mod> const& b) {
    vector<mod> ret(m, 0);
    
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            int k = (i + j) % m;

            ret[k] += a[i] * b[j];
        }
    }

    return ret;
}

vector<mod> calc(int const n) {
    if (n == 1)
        return identity;
    else if (n % 2 == 1)
        return combine(calc(n - 1), identity);
    else {
        auto const half = calc(n / 2);
        return combine(half, half);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m >> l >> r >> k;

    identity.assign(m, 0);

    for (int i = 0; i < m; i++) {
        identity[i] += (r - i + m) / m;
        identity[i] -= (l - 1 - i + m) / m;
    }

    auto const ans = calc(n);

    cout << ans[k] << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2052 KiB
3Accepted3ms2272 KiB
subtask210/10
4Accepted3ms2452 KiB
5Accepted3ms2816 KiB
6Accepted3ms2868 KiB
subtask310/10
7Accepted2ms2952 KiB
8Accepted3ms3076 KiB
9Accepted2ms3160 KiB
10Accepted3ms3296 KiB
11Accepted2ms3384 KiB
12Accepted2ms3388 KiB
13Accepted3ms3572 KiB
subtask47/7
14Accepted3ms3776 KiB
15Accepted3ms3904 KiB
16Accepted3ms4120 KiB
17Accepted3ms4336 KiB
18Accepted2ms4432 KiB
19Accepted2ms4440 KiB
20Accepted3ms4656 KiB
subtask58/8
21Accepted79ms4760 KiB
22Accepted39ms4968 KiB
23Accepted50ms5064 KiB
24Accepted32ms4904 KiB
25Accepted17ms4908 KiB
26Accepted9ms4808 KiB
27Accepted57ms5092 KiB
28Accepted12ms5076 KiB
29Accepted79ms5092 KiB
30Accepted79ms5116 KiB
subtask60/25
31Runtime error168ms521888 KiB
32Runtime error166ms521864 KiB
33Wrong answer6ms4964 KiB
34Wrong answer6ms5184 KiB
35Accepted6ms5196 KiB
36Wrong answer7ms5200 KiB
37Runtime error165ms521628 KiB
38Runtime error209ms521604 KiB
39Wrong answer9ms5216 KiB
40Wrong answer8ms5316 KiB
subtask70/40
41Runtime error209ms521580 KiB
42Runtime error167ms521548 KiB
43Runtime error211ms521524 KiB
44Wrong answer1.23s5300 KiB
45Runtime error167ms521564 KiB
46Wrong answer501ms5272 KiB
47Wrong answer773ms5336 KiB
48Wrong answer10ms5248 KiB
49Wrong answer796ms5312 KiB
50Runtime error209ms521532 KiB