QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578449 | #8211. Enumerating Substrings | ucup-team3519# | AC ✓ | 303ms | 29672kb | C++20 | 4.1kb | 2024-09-20 19:18:09 | 2024-09-20 19:18:09 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
template <int m>
class ModInt {
int raw_;
public:
ModInt() : raw_(0) {}
ModInt(const auto &v) : raw_(v % m) {}
using i64 = int64_t;
using mint = ModInt;
mint &operator+=(const mint &rhs) {
raw_ = (raw_ + rhs.raw_) % m;
return *this;
}
mint &operator-=(const mint &rhs) {
raw_ = (raw_ - rhs.raw_) % m;
return *this;
}
mint &operator*=(const mint &rhs) {
raw_ = (i64)raw_ * rhs.raw_ % m;
return *this;
}
mint &operator/=(const mint &rhs) {
raw_ = (i64)raw_ * qpow(rhs.raw_, m - 2) % m;
return *this;
}
friend mint operator+(const mint &lhs, const mint &rhs) {
return mint{lhs} += rhs;
}
friend mint operator-(const mint &lhs, const mint &rhs) {
return mint{lhs} -= rhs;
}
friend mint operator*(const mint &lhs, const mint &rhs) {
return mint{lhs} *= rhs;
}
friend mint operator/(const mint &lhs, const mint &rhs) {
return mint{lhs} /= rhs;
}
int value() const {
return (raw_ + m) % m;
}
static constexpr int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = (i64)res * a % m;
}
a = (i64)a * a % m, b >>= 1;
}
return res;
}
};
using mint = ModInt<static_cast<int>(1e9 + 7)>;
constexpr int MAXM = 2e3 + 19;
constexpr int MAXN = 1e6 + 19;
std::map<int, mint> fact, ifact;
void init_fact(int k) {
const int N = 5090, L = std::max(k - N, 0LL);
const int LIM = 20000;
if (k <= LIM) {
fact[0] = 1;
for (int i = 1; i <= LIM; ++i) {
fact[i] = fact[i - 1] * i;
}
ifact[LIM] = 1 / fact[LIM];
for (int i = LIM - 1; i >= 0; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
}
return;
}
ifact[k] = 19;
for (int i = k - 1; i >= L; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
}
fact[L] = 1 / ifact[L];
for (int i = L + 1; i <= k; ++i) {
fact[i] = fact[i - 1] * i;
}
fact[0] = 1;
for (int i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i;
}
ifact[N] = 1 / fact[N];
for (int i = N - 1; i >= 0; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
}
}
mint binom(int n, int m) {
return fact[n] * ifact[n - m] * ifact[m];
}
mint A(int n, int m) {
return fact[n] * ifact[n - m];
}
mint L(int m, int k) {
mint res = 0;
mint C = 1;
for (int occ2 = 0; occ2 * 2 <= m; ++occ2) {
if (occ2 <= k && m - occ2 * 2 <= k - occ2) {
mint v = binom(k, occ2) * A(k - occ2, m - occ2 * 2);
//// mint v=binom(k,occ2)*binom(k-occ2,m-occ2*2)*fact[m]/mint::qpow(2,occ2);
res += v * C;
}
if (2 <= m - occ2 * 2) {
C *= binom(m - occ2 * 2, 2);
}
}
return res;
}
int n, m, k;
mint occ[MAXN];
mint V[MAXM];
void init_occ() {
for (int i = 1; i <= n; ++i) {
occ[i] = (n - i + 1) * mint::qpow(k, n - i);
}
}
void init_V() {
mint f = 1;
for (int i = 1; i * 2 <= m; ++i) {
f *= (k - i + 1);
V[i] = f * L(m - i * 2, k - i);
}
V[0] = L(m, k);
for (int i = 1; i * 2 <= m; ++i) {
V[0] -= V[i];
}
}
mint g[MAXN], f[MAXN];
int32_t main() {
std::cin >> n >> m >> k;
init_fact(k);
init_occ();
init_V();
// std::cout << "PRE DONE\n";
int lim = 1;
g[1] += occ[m] * V[0];
for (int i = 1; m * i - (i - 1) * (m / 2) <= n; ++i) {
lim = i;
for (int a = m / 2; a >= 1 && m * i - (i - 1) * a <= n; --a) {
g[i] += occ[m * i - (i - 1) * a] * V[a];
}
}
// std::cout << "g_1 = " << g[1].value() << '\n';
mint ans = 0;
for (int i = 1; i <= lim; ++i) {
f[i] = (g[i] - g[i + 1]) - (g[i + 1] - g[i + 2]);
ans += f[i] * ((i + 1) / 2);
// std::cout << f[i].value() << '\n';
}
std::cout << ans.value() << '\n';
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 29672kb
input:
4 2 3
output:
228
result:
ok 1 number(s): "228"
Test #2:
score: 0
Accepted
time: 303ms
memory: 28300kb
input:
999999 1999 12345678
output:
52352722
result:
ok 1 number(s): "52352722"
Test #3:
score: 0
Accepted
time: 10ms
memory: 29588kb
input:
7 4 2
output:
182
result:
ok 1 number(s): "182"
Test #4:
score: 0
Accepted
time: 9ms
memory: 29520kb
input:
4 3 4
output:
480
result:
ok 1 number(s): "480"
Test #5:
score: 0
Accepted
time: 7ms
memory: 29604kb
input:
3 1 1
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 4ms
memory: 29516kb
input:
5 5 1
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 9ms
memory: 29672kb
input:
7 4 3
output:
5784
result:
ok 1 number(s): "5784"
Test #8:
score: 0
Accepted
time: 0ms
memory: 29600kb
input:
5 2 4
output:
3932
result:
ok 1 number(s): "3932"
Test #9:
score: 0
Accepted
time: 13ms
memory: 29588kb
input:
8 2 2
output:
1522
result:
ok 1 number(s): "1522"
Test #10:
score: 0
Accepted
time: 3ms
memory: 29656kb
input:
8 1 2
output:
2048
result:
ok 1 number(s): "2048"
Test #11:
score: 0
Accepted
time: 4ms
memory: 29584kb
input:
7 5 3
output:
2430
result:
ok 1 number(s): "2430"
Test #12:
score: 0
Accepted
time: 14ms
memory: 29588kb
input:
10 4 3
output:
272004
result:
ok 1 number(s): "272004"
Test #13:
score: 0
Accepted
time: 68ms
memory: 29596kb
input:
675978 614 2
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 19ms
memory: 29536kb
input:
244613 38 1
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 65ms
memory: 29528kb
input:
186293 1462 1
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 22ms
memory: 29644kb
input:
24867 886 1
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 101ms
memory: 29672kb
input:
976164 1014 2
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 15ms
memory: 28444kb
input:
179356 2 716844809
output:
577866092
result:
ok 1 number(s): "577866092"
Test #19:
score: 0
Accepted
time: 53ms
memory: 28360kb
input:
621001 130 310625363
output:
892869197
result:
ok 1 number(s): "892869197"
Test #20:
score: 0
Accepted
time: 89ms
memory: 28284kb
input:
678862 850 754662812
output:
582264789
result:
ok 1 number(s): "582264789"
Test #21:
score: 0
Accepted
time: 99ms
memory: 28356kb
input:
650845 978 348443366
output:
825425732
result:
ok 1 number(s): "825425732"
Test #22:
score: 0
Accepted
time: 60ms
memory: 28296kb
input:
669914 402 87448112
output:
318098088
result:
ok 1 number(s): "318098088"
Test #23:
score: 0
Accepted
time: 93ms
memory: 28348kb
input:
998593 530 681228665
output:
408255654
result:
ok 1 number(s): "408255654"
Test #24:
score: 0
Accepted
time: 238ms
memory: 28416kb
input:
369361 1954 125266115
output:
509912384
result:
ok 1 number(s): "509912384"
Test #25:
score: 0
Accepted
time: 173ms
memory: 28356kb
input:
900226 1378 424079373
output:
406320917
result:
ok 1 number(s): "406320917"
Test #26:
score: 0
Accepted
time: 149ms
memory: 28356kb
input:
334887 1506 17859926
output:
503264679
result:
ok 1 number(s): "503264679"
Test #27:
score: 0
Accepted
time: 90ms
memory: 28300kb
input:
936048 544 53978328
output:
548647866
result:
ok 1 number(s): "548647866"
Test #28:
score: 0
Accepted
time: 96ms
memory: 28304kb
input:
152789 1264 792983073
output:
839541707
result:
ok 1 number(s): "839541707"
Test #29:
score: 0
Accepted
time: 159ms
memory: 28304kb
input:
714493 1392 91796331
output:
721071046
result:
ok 1 number(s): "721071046"
Test #30:
score: 0
Accepted
time: 53ms
memory: 28356kb
input:
269571 816 830801077
output:
330064211
result:
ok 1 number(s): "330064211"
Test #31:
score: 0
Accepted
time: 111ms
memory: 28356kb
input:
845120 944 424581630
output:
348960190
result:
ok 1 number(s): "348960190"
Test #32:
score: 0
Accepted
time: 47ms
memory: 28372kb
input:
533990 368 163586376
output:
522092095
result:
ok 1 number(s): "522092095"
Test #33:
score: 0
Accepted
time: 188ms
memory: 28300kb
input:
181707 1792 462399634
output:
373795106
result:
ok 1 number(s): "373795106"
Test #34:
score: 0
Accepted
time: 232ms
memory: 28304kb
input:
417349 1920 761212891
output:
587051329
result:
ok 1 number(s): "587051329"
Test #35:
score: 0
Accepted
time: 142ms
memory: 28444kb
input:
526583 1344 500217637
output:
108767800
result:
ok 1 number(s): "108767800"
Test #36:
score: 0
Accepted
time: 97ms
memory: 28308kb
input:
867054 769 93998191
output:
239123369
result:
ok 1 number(s): "239123369"
Extra Test:
score: 0
Extra Test Passed