6239 | 2023-11-08 12:46:21 | Error42 | Tömbök előállítása | cpp17 | Time limit exceeded 60/100 | 2.049s | 5556 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(ll 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";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2028 KiB | ||||
3 | Accepted | 3ms | 2240 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Accepted | 3ms | 2456 KiB | ||||
5 | Accepted | 2ms | 2552 KiB | ||||
6 | Accepted | 3ms | 2648 KiB | ||||
subtask3 | 10/10 | ||||||
7 | Accepted | 2ms | 2548 KiB | ||||
8 | Accepted | 3ms | 2660 KiB | ||||
9 | Accepted | 3ms | 2784 KiB | ||||
10 | Accepted | 3ms | 2920 KiB | ||||
11 | Accepted | 3ms | 3132 KiB | ||||
12 | Accepted | 3ms | 3240 KiB | ||||
13 | Accepted | 3ms | 3452 KiB | ||||
subtask4 | 7/7 | ||||||
14 | Accepted | 3ms | 3540 KiB | ||||
15 | Accepted | 3ms | 3592 KiB | ||||
16 | Accepted | 3ms | 3796 KiB | ||||
17 | Accepted | 3ms | 4012 KiB | ||||
18 | Accepted | 3ms | 4248 KiB | ||||
19 | Accepted | 3ms | 4208 KiB | ||||
20 | Accepted | 3ms | 4208 KiB | ||||
subtask5 | 8/8 | ||||||
21 | Accepted | 79ms | 4224 KiB | ||||
22 | Accepted | 39ms | 4344 KiB | ||||
23 | Accepted | 50ms | 4560 KiB | ||||
24 | Accepted | 32ms | 4652 KiB | ||||
25 | Accepted | 17ms | 4740 KiB | ||||
26 | Accepted | 8ms | 4868 KiB | ||||
27 | Accepted | 57ms | 4964 KiB | ||||
28 | Accepted | 12ms | 4964 KiB | ||||
29 | Accepted | 79ms | 5068 KiB | ||||
30 | Accepted | 79ms | 5200 KiB | ||||
subtask6 | 25/25 | ||||||
31 | Accepted | 17ms | 5276 KiB | ||||
32 | Accepted | 17ms | 5308 KiB | ||||
33 | Accepted | 8ms | 5332 KiB | ||||
34 | Accepted | 8ms | 5316 KiB | ||||
35 | Accepted | 6ms | 5324 KiB | ||||
36 | Accepted | 8ms | 5556 KiB | ||||
37 | Accepted | 3ms | 5420 KiB | ||||
38 | Accepted | 3ms | 5420 KiB | ||||
39 | Accepted | 10ms | 5428 KiB | ||||
40 | Accepted | 13ms | 5432 KiB | ||||
subtask7 | 0/40 | ||||||
41 | Accepted | 592ms | 5448 KiB | ||||
42 | Accepted | 1.904s | 5544 KiB | ||||
43 | Time limit exceeded | 2.026s | 5296 KiB | ||||
44 | Time limit exceeded | 2.049s | 5352 KiB | ||||
45 | Time limit exceeded | 2.046s | 5432 KiB | ||||
46 | Accepted | 554ms | 5460 KiB | ||||
47 | Accepted | 888ms | 5388 KiB | ||||
48 | Accepted | 12ms | 5368 KiB | ||||
49 | Accepted | 1.465s | 5492 KiB | ||||
50 | Accepted | 683ms | 5464 KiB |