QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350351#8211. Enumerating Substringsucup-team1198#AC ✓216ms8208kbC++203.1kb2024-03-10 17:37:232024-03-10 17:37:23

Judging History

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

  • [2024-03-10 17:37:23]
  • 评测
  • 测评结果:AC
  • 用时:216ms
  • 内存:8208kb
  • [2024-03-10 17:37:23]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int MOD = 1e9 + 7;

int add(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}

int sub(int a, int b) {
    return a >= b ? a - b : a + MOD - b;
}

int mul(int a, int b) {
    return (1ll * a * b) % MOD;
}

int pw(int x, int n) {
    int res = 1;
    while (n) {
        if (n % 2 == 0) {
            x = mul(x, x);
            n /= 2;
        } else {
            res = mul(res, x);
            --n;
        }
    }
    return res;
}

const int MAXF = 1e5 + 100;
int fact[MAXF], invf[MAXF];

int pw2[MAXF];

int C(int n, int k) {
    if (k < 0 || k > n) return 0;
    return mul(fact[n], mul(invf[k], invf[n - k]));
}

int inv(int x) {
    return mul(invf[x], fact[x - 1]);
}

int get2(int m, int k) {
    if (k < 0) return 0;
    if (m == 0) return 1;
    int c = 1;
    int ans = 0;
    for (int t = 1; t <= m; ++t) {
        c = mul(c, k - t + 1);
        c = mul(c, inv(t));
        int cur = mul(c, mul(C(t, m - t), mul(fact[m], pw2[m - t])));
        ans = add(ans, cur);
    }
    return ans;
}

const int MAXM = 2e3 + 100;
int cnt[MAXM];


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    fact[0] = 1;
    for (int i = 1; i < MAXF; ++i) {
        fact[i] = mul(fact[i - 1], i);
    }
    invf[MAXF - 1] = pw(fact[MAXF - 1], MOD - 2);
    for (int i = MAXF - 1; i > 0; --i) {
        invf[i - 1] = mul(invf[i], i);
    }

    pw2[0] = 1;
    for (int i = 1; i < MAXF; ++i) {
        pw2[i] = mul(pw2[i - 1], (MOD + 1) / 2);
    }

    int n, m, k;
    cin >> n >> m >> k;
    int c = 1;
    for (int l = 0; l * 2 <= m; ++l) {
        cnt[m - l] = mul(get2(m - 2 * l, k - l), c);
        c = mul(c, k - l);
        /// c = mul(c, inv(l + 1));
        /// cerr << l << ": " << cnt[m - l] << endl;
    }
    int total = 0;
    for (int i = 0; i < m; ++i) {
        cnt[m] = sub(cnt[m], cnt[i]);
        total = add(total, cnt[i]);
    }

    int ans = mul(cnt[m], mul(pw(k, n - m), n - m + 1));

    /// cerr << ans << endl;

    vector<int> f(n + 1);
    for (int l = 1; l < m; ++l) {
        for (int i = l; i <= n; i += l) {
            if ((i / l) % 2 == 1) {
                f[i] = add(f[i], cnt[l]);
            } else {
                f[i] = sub(f[i], cnt[l]);
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        f[i] = add(f[i], mul(f[i - 1], k));
        /// cerr << i << ": " << f[i] << endl;
    }
    for (int i = m; i <= n; ++i) {
        int cur = sub(mul(pw(k, i - m), total), f[i - m]);
        /// cerr << i << endl;
        /// cerr << pw(k, i - m) << " " << f[i - m] << endl;
        /// cerr << i << ": " << cur << endl;
        ans = add(ans, mul(cur, pw(k, n - i)));
    }
    cout << ans << "\n";
    
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4776kb

input:

4 2 3

output:

228

result:

ok 1 number(s): "228"

Test #2:

score: 0
Accepted
time: 216ms
memory: 8108kb

input:

999999 1999 12345678

output:

52352722

result:

ok 1 number(s): "52352722"

Test #3:

score: 0
Accepted
time: 2ms
memory: 4728kb

input:

7 4 2

output:

182

result:

ok 1 number(s): "182"

Test #4:

score: 0
Accepted
time: 3ms
memory: 4964kb

input:

4 3 4

output:

480

result:

ok 1 number(s): "480"

Test #5:

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

input:

3 1 1

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 2ms
memory: 4784kb

input:

5 5 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

7 4 3

output:

5784

result:

ok 1 number(s): "5784"

Test #8:

score: 0
Accepted
time: 2ms
memory: 4752kb

input:

5 2 4

output:

3932

result:

ok 1 number(s): "3932"

Test #9:

score: 0
Accepted
time: 2ms
memory: 4752kb

input:

8 2 2

output:

1522

result:

ok 1 number(s): "1522"

Test #10:

score: 0
Accepted
time: 2ms
memory: 4712kb

input:

8 1 2

output:

2048

result:

ok 1 number(s): "2048"

Test #11:

score: 0
Accepted
time: 2ms
memory: 4820kb

input:

7 5 3

output:

2430

result:

ok 1 number(s): "2430"

Test #12:

score: 0
Accepted
time: 2ms
memory: 4728kb

input:

10 4 3

output:

272004

result:

ok 1 number(s): "272004"

Test #13:

score: 0
Accepted
time: 124ms
memory: 7072kb

input:

675978 614 2

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 43ms
memory: 5140kb

input:

244613 38 1

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 34ms
memory: 5024kb

input:

186293 1462 1

output:

0

result:

ok 1 number(s): "0"

Test #16:

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

input:

24867 886 1

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 186ms
memory: 8136kb

input:

976164 1014 2

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 32ms
memory: 4864kb

input:

179356 2 716844809

output:

577866092

result:

ok 1 number(s): "577866092"

Test #19:

score: 0
Accepted
time: 119ms
memory: 6712kb

input:

621001 130 310625363

output:

892869197

result:

ok 1 number(s): "892869197"

Test #20:

score: 0
Accepted
time: 132ms
memory: 6988kb

input:

678862 850 754662812

output:

582264789

result:

ok 1 number(s): "582264789"

Test #21:

score: 0
Accepted
time: 127ms
memory: 6748kb

input:

650845 978 348443366

output:

825425732

result:

ok 1 number(s): "825425732"

Test #22:

score: 0
Accepted
time: 128ms
memory: 7080kb

input:

669914 402 87448112

output:

318098088

result:

ok 1 number(s): "318098088"

Test #23:

score: 0
Accepted
time: 202ms
memory: 8088kb

input:

998593 530 681228665

output:

408255654

result:

ok 1 number(s): "408255654"

Test #24:

score: 0
Accepted
time: 80ms
memory: 5708kb

input:

369361 1954 125266115

output:

509912384

result:

ok 1 number(s): "509912384"

Test #25:

score: 0
Accepted
time: 178ms
memory: 7872kb

input:

900226 1378 424079373

output:

406320917

result:

ok 1 number(s): "406320917"

Test #26:

score: 0
Accepted
time: 70ms
memory: 5752kb

input:

334887 1506 17859926

output:

503264679

result:

ok 1 number(s): "503264679"

Test #27:

score: 0
Accepted
time: 195ms
memory: 8208kb

input:

936048 544 53978328

output:

548647866

result:

ok 1 number(s): "548647866"

Test #28:

score: 0
Accepted
time: 29ms
memory: 4928kb

input:

152789 1264 792983073

output:

839541707

result:

ok 1 number(s): "839541707"

Test #29:

score: 0
Accepted
time: 154ms
memory: 6992kb

input:

714493 1392 91796331

output:

721071046

result:

ok 1 number(s): "721071046"

Test #30:

score: 0
Accepted
time: 50ms
memory: 5452kb

input:

269571 816 830801077

output:

330064211

result:

ok 1 number(s): "330064211"

Test #31:

score: 0
Accepted
time: 178ms
memory: 7476kb

input:

845120 944 424581630

output:

348960190

result:

ok 1 number(s): "348960190"

Test #32:

score: 0
Accepted
time: 107ms
memory: 6496kb

input:

533990 368 163586376

output:

522092095

result:

ok 1 number(s): "522092095"

Test #33:

score: 0
Accepted
time: 42ms
memory: 4908kb

input:

181707 1792 462399634

output:

373795106

result:

ok 1 number(s): "373795106"

Test #34:

score: 0
Accepted
time: 91ms
memory: 6064kb

input:

417349 1920 761212891

output:

587051329

result:

ok 1 number(s): "587051329"

Test #35:

score: 0
Accepted
time: 104ms
memory: 6220kb

input:

526583 1344 500217637

output:

108767800

result:

ok 1 number(s): "108767800"

Test #36:

score: 0
Accepted
time: 175ms
memory: 7496kb

input:

867054 769 93998191

output:

239123369

result:

ok 1 number(s): "239123369"

Extra Test:

score: 0
Extra Test Passed