QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334966#8211. Enumerating Substringsucup-team1209#AC ✓190ms3712kbC++202.5kb2024-02-22 15:39:162024-02-22 15:39:17

Judging History

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

  • [2024-02-22 15:39:17]
  • 评测
  • 测评结果:AC
  • 用时:190ms
  • 内存:3712kb
  • [2024-02-22 15:39:16]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;

cs int N = 1e6 + 5, M = 2e3 + 5; 
cs int mod = 1e9 + 7;
int add(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b; 
}
int dec(int a, int b) {
    return a - b < 0 ? a - b + mod : a - b; 
}
int mul(int a, int b) {
    return 1ll * a * b % mod;
}
void Add(int &a , int b) {
    a = add(a, b);
}
void Dec(int &a, int b) {
    a = dec(a, b);
}
void Mul(int &a, int b) {
    a = mul(a, b);
}
int ksm(int a, int b) {
    int c = 1;
    for(; b; b >>= 1, Mul(a, a))
    if(b & 1) Mul(c, a);
    return c; 
}
int n, m, k; 
int fc[M], ifc[M];
void init(int n) {
    fc[0] = ifc[0] = 1; 
    for(int i = 1; i <= n; i++) 
        fc[i] = mul(fc[i - 1], i);
    ifc[n] = ksm(fc[n], mod - 2);
    for(int i = n - 1; i; i--) 
        ifc[i] = mul(ifc[i + 1], i + 1);
}
int F(int a, int b) {
    int coef = 1, ans = 0;
    for(int i = 0; i < min(a, b); i++) Mul(coef, b - i);
    // cout << a << ' ' << b << ' ' << coef <<  endl;
    for(int i = 0; i * 2 <= a; i++) {
        if(a - i > b) continue; 
        // b ^ {a - i}
        int c = mul(ifc[i], ifc[a - 2 * i]);
        Mul(c, ksm(2, mod - 1 - i));
        // cout << "Ffdsfasfsdafasdf " <<i << ' ' << coef << ' ' << c << endl;
        Add(ans, mul(coef, c));
        Mul(coef, ksm(b - (a - i) + 1, mod - 2));
    }
    Mul(ans, fc[a]);
    // cout << "---------------------- " << a << ' ' << b << ' ' << ans << endl;
    return ans; 
}
int calc(int l) {
    int ans = 0; 
    for(int c = 1; c <= n; c++) {
        int len = c * m - (c - 1) * l;
        if(len > n) break;
        if(c & 1) Add(ans, mul(n - len + 1, ksm(k, n - len)));
        else Dec(ans, mul(n - len + 1, ksm(k, n - len)));
    }
    return ans;
}
void Main() {
    cin >> n >> m >> k; 
    init(m);
    int coef = k; 
    int temp = mul(n - m + 1, ksm(k, n - m));
    int ans = mul(temp, F(m, k));
    // cout << temp << ' ' << ans << endl;
    for(int l = 1; l * 2 <= m; l++) {
        int c = mul(coef, F(m - 2 * l, k - l));
        // cout << "FFF " << l << ' ' << coef << ' ' << F(m - 2 * l, k - l) << ' ' << c << endl;
        Add(ans, mul(c, dec(calc(l), temp)));
        // cout << "GGG " << calc(l) << endl;
        Mul(coef, k - l);
    }
    cout << ans << '\n';
}
int main() {
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    ios :: sync_with_stdio(0), cin.tie(0);
    int T = 1; 
    while(T--) Main();
    return 0; 
}

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

详细

Test #1:

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

input:

4 2 3

output:

228

result:

ok 1 number(s): "228"

Test #2:

score: 0
Accepted
time: 190ms
memory: 3656kb

input:

999999 1999 12345678

output:

52352722

result:

ok 1 number(s): "52352722"

Test #3:

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

input:

7 4 2

output:

182

result:

ok 1 number(s): "182"

Test #4:

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

input:

4 3 4

output:

480

result:

ok 1 number(s): "480"

Test #5:

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

input:

3 1 1

output:

3

result:

ok 1 number(s): "3"

Test #6:

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

input:

5 5 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

7 4 3

output:

5784

result:

ok 1 number(s): "5784"

Test #8:

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

input:

5 2 4

output:

3932

result:

ok 1 number(s): "3932"

Test #9:

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

input:

8 2 2

output:

1522

result:

ok 1 number(s): "1522"

Test #10:

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

input:

8 1 2

output:

2048

result:

ok 1 number(s): "2048"

Test #11:

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

input:

7 5 3

output:

2430

result:

ok 1 number(s): "2430"

Test #12:

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

input:

10 4 3

output:

272004

result:

ok 1 number(s): "272004"

Test #13:

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

input:

675978 614 2

output:

0

result:

ok 1 number(s): "0"

Test #14:

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

input:

244613 38 1

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 11ms
memory: 3652kb

input:

186293 1462 1

output:

0

result:

ok 1 number(s): "0"

Test #16:

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

input:

24867 886 1

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 58ms
memory: 3696kb

input:

976164 1014 2

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 13ms
memory: 3640kb

input:

179356 2 716844809

output:

577866092

result:

ok 1 number(s): "577866092"

Test #19:

score: 0
Accepted
time: 36ms
memory: 3708kb

input:

621001 130 310625363

output:

892869197

result:

ok 1 number(s): "892869197"

Test #20:

score: 0
Accepted
time: 63ms
memory: 3640kb

input:

678862 850 754662812

output:

582264789

result:

ok 1 number(s): "582264789"

Test #21:

score: 0
Accepted
time: 65ms
memory: 3652kb

input:

650845 978 348443366

output:

825425732

result:

ok 1 number(s): "825425732"

Test #22:

score: 0
Accepted
time: 44ms
memory: 3556kb

input:

669914 402 87448112

output:

318098088

result:

ok 1 number(s): "318098088"

Test #23:

score: 0
Accepted
time: 68ms
memory: 3612kb

input:

998593 530 681228665

output:

408255654

result:

ok 1 number(s): "408255654"

Test #24:

score: 0
Accepted
time: 146ms
memory: 3588kb

input:

369361 1954 125266115

output:

509912384

result:

ok 1 number(s): "509912384"

Test #25:

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

input:

900226 1378 424079373

output:

406320917

result:

ok 1 number(s): "406320917"

Test #26:

score: 0
Accepted
time: 93ms
memory: 3652kb

input:

334887 1506 17859926

output:

503264679

result:

ok 1 number(s): "503264679"

Test #27:

score: 0
Accepted
time: 64ms
memory: 3584kb

input:

936048 544 53978328

output:

548647866

result:

ok 1 number(s): "548647866"

Test #28:

score: 0
Accepted
time: 60ms
memory: 3592kb

input:

152789 1264 792983073

output:

839541707

result:

ok 1 number(s): "839541707"

Test #29:

score: 0
Accepted
time: 105ms
memory: 3604kb

input:

714493 1392 91796331

output:

721071046

result:

ok 1 number(s): "721071046"

Test #30:

score: 0
Accepted
time: 37ms
memory: 3584kb

input:

269571 816 830801077

output:

330064211

result:

ok 1 number(s): "330064211"

Test #31:

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

input:

845120 944 424581630

output:

348960190

result:

ok 1 number(s): "348960190"

Test #32:

score: 0
Accepted
time: 35ms
memory: 3624kb

input:

533990 368 163586376

output:

522092095

result:

ok 1 number(s): "522092095"

Test #33:

score: 0
Accepted
time: 111ms
memory: 3696kb

input:

181707 1792 462399634

output:

373795106

result:

ok 1 number(s): "373795106"

Test #34:

score: 0
Accepted
time: 155ms
memory: 3648kb

input:

417349 1920 761212891

output:

587051329

result:

ok 1 number(s): "587051329"

Test #35:

score: 0
Accepted
time: 85ms
memory: 3656kb

input:

526583 1344 500217637

output:

108767800

result:

ok 1 number(s): "108767800"

Test #36:

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

input:

867054 769 93998191

output:

239123369

result:

ok 1 number(s): "239123369"

Extra Test:

score: 0
Extra Test Passed