QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547740#8211. Enumerating SubstringsHuTaoAC ✓29ms48760kbC++142.9kb2024-09-05 09:00:002024-09-05 09:00:00

Judging History

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

  • [2024-09-05 09:00:00]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:48760kb
  • [2024-09-05 09:00:00]
  • 提交

answer

/*
1. min{F(i, j), F(j, k)} <= F(i, k):考虑对于任意一组大小小于 min{F(i, j), F(j, k)} 的割,都会保留一条 i -> j,j -> k 的通路。
2. 将所有流至少为 1 的边,分别讨论连通块;将所有流至少为 2 的边,分别讨论连通块,这些连通块外部连边构成连。
3. 对所有流至少为 3 的边,构成团,若团大小:
    - 至少为 4 的偶数:连成环之后,相对的两个点连边。
    - 至少为 4 的奇数:除去最后一个点之外连成环之后,与最后一个点连边。
    - 上面两种其中一个点作为代表连到环内。
    - 2:
        * 只有一个这样的团,这两个点不能相邻,之间额外连边。
        * 若连通块内点数不超过 3,无解。
        * 存在更多这样的团无解。
    - 3:
        * 只有一个这样的团,这三个点之间额外连任意两条边,相连边的两个点不能相邻。
        * 连通块的点个数不超过 4,无解。
4. 按团的数量连外部边:
    - 1:不用管。
    - 2:若大小都为 1,无解;否则将其中一个不为 1 的团中任意两个点向另一个团的点连边。
    - 3:否则可以连成环。
5. 听说上面这样搞出来有反例的,但是不知道是什么。
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 1e6 + 5, P = 1e9 + 7;

int n, m, k;
LL fact[N], invf[N], ck[N], s2[N], pk[N];
LL f[N];

inline LL ksm(LL a, LL n)
{
    LL res = 1;
    while(n)
    {
        if(n & 1) res = res * a % P;
        a = a * a % P;
        n >>= 1;
    }
    return res;
}
inline void Init(int n)
{
    fact[0] = 1;
    for(int i = 1; i <= n; i ++ ) fact[i] = fact[i - 1] * i % P;
    invf[n] = ksm(fact[n], P - 2);
    for(int i = n; i >= 1; i -- ) invf[i - 1] = invf[i] * i % P;
    ck[0] = 1;
    for(int i = 1; i <= n; i ++ ) ck[i] = ck[i - 1] * (k - i + 1) % P;
    s2[0] = 1;
    for(int i = 1; i <= n / 2; i ++ ) s2[i] = s2[i - 1] * (i * 2 - 1) % P;
    for(int i = 1; i <= n / 2; i ++ ) s2[i] = s2[i] * invf[i * 2] % P;
    pk[0] = 1;
    for(int i = 1; i <= n; i ++ ) pk[i] = pk[i - 1] * k % P;
}

int main()
{
    scanf("%d%d%d", &n, &m, &k);

    Init(n);
    LL s0 = 0;
    for(int i = m / 2; i >= 0; i -- )
    {
        LL s = 0;
        for(int j = 0; j <= m / 2 - i; j ++ )
            s = (s + ck[m - i - j] * invf[m - i * 2 - j * 2] % P * s2[j]) % P;
        s = s * fact[m - i * 2] % P;
        if(i == 0)
        {
            s -= s0;
            f[m] += s;
        }
        else
        {
            (s0 += s) >= P && (s0 -= P);
            for(int j = m, k = 1; j <= n; j += m - i, k = -k) f[j] += s * k;
        }
    }
    
    LL ans = 0;
    for(int i = m; i <= n; i ++ ) ans = (ans + (f[i] % P + P) * (n - i + 1) % P * pk[n - i]) % P;
    printf("%lld\n", ans);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2 3

output:

228

result:

ok 1 number(s): "228"

Test #2:

score: 0
Accepted
time: 23ms
memory: 48760kb

input:

999999 1999 12345678

output:

52352722

result:

ok 1 number(s): "52352722"

Test #3:

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

input:

7 4 2

output:

182

result:

ok 1 number(s): "182"

Test #4:

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

input:

4 3 4

output:

480

result:

ok 1 number(s): "480"

Test #5:

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

input:

3 1 1

output:

3

result:

ok 1 number(s): "3"

Test #6:

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

input:

5 5 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

7 4 3

output:

5784

result:

ok 1 number(s): "5784"

Test #8:

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

input:

5 2 4

output:

3932

result:

ok 1 number(s): "3932"

Test #9:

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

input:

8 2 2

output:

1522

result:

ok 1 number(s): "1522"

Test #10:

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

input:

8 1 2

output:

2048

result:

ok 1 number(s): "2048"

Test #11:

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

input:

7 5 3

output:

2430

result:

ok 1 number(s): "2430"

Test #12:

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

input:

10 4 3

output:

272004

result:

ok 1 number(s): "272004"

Test #13:

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

input:

675978 614 2

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 4ms
memory: 25640kb

input:

244613 38 1

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 4ms
memory: 23472kb

input:

186293 1462 1

output:

0

result:

ok 1 number(s): "0"

Test #16:

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

input:

24867 886 1

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 26ms
memory: 48568kb

input:

976164 1014 2

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 8ms
memory: 23728kb

input:

179356 2 716844809

output:

577866092

result:

ok 1 number(s): "577866092"

Test #19:

score: 0
Accepted
time: 18ms
memory: 40640kb

input:

621001 130 310625363

output:

892869197

result:

ok 1 number(s): "892869197"

Test #20:

score: 0
Accepted
time: 16ms
memory: 43044kb

input:

678862 850 754662812

output:

582264789

result:

ok 1 number(s): "582264789"

Test #21:

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

input:

650845 978 348443366

output:

825425732

result:

ok 1 number(s): "825425732"

Test #22:

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

input:

669914 402 87448112

output:

318098088

result:

ok 1 number(s): "318098088"

Test #23:

score: 0
Accepted
time: 18ms
memory: 48732kb

input:

998593 530 681228665

output:

408255654

result:

ok 1 number(s): "408255654"

Test #24:

score: 0
Accepted
time: 16ms
memory: 29700kb

input:

369361 1954 125266115

output:

509912384

result:

ok 1 number(s): "509912384"

Test #25:

score: 0
Accepted
time: 27ms
memory: 48244kb

input:

900226 1378 424079373

output:

406320917

result:

ok 1 number(s): "406320917"

Test #26:

score: 0
Accepted
time: 4ms
memory: 29808kb

input:

334887 1506 17859926

output:

503264679

result:

ok 1 number(s): "503264679"

Test #27:

score: 0
Accepted
time: 23ms
memory: 48240kb

input:

936048 544 53978328

output:

548647866

result:

ok 1 number(s): "548647866"

Test #28:

score: 0
Accepted
time: 7ms
memory: 20576kb

input:

152789 1264 792983073

output:

839541707

result:

ok 1 number(s): "839541707"

Test #29:

score: 0
Accepted
time: 18ms
memory: 46672kb

input:

714493 1392 91796331

output:

721071046

result:

ok 1 number(s): "721071046"

Test #30:

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

input:

269571 816 830801077

output:

330064211

result:

ok 1 number(s): "330064211"

Test #31:

score: 0
Accepted
time: 20ms
memory: 45700kb

input:

845120 944 424581630

output:

348960190

result:

ok 1 number(s): "348960190"

Test #32:

score: 0
Accepted
time: 7ms
memory: 38076kb

input:

533990 368 163586376

output:

522092095

result:

ok 1 number(s): "522092095"

Test #33:

score: 0
Accepted
time: 8ms
memory: 22924kb

input:

181707 1792 462399634

output:

373795106

result:

ok 1 number(s): "373795106"

Test #34:

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

input:

417349 1920 761212891

output:

587051329

result:

ok 1 number(s): "587051329"

Test #35:

score: 0
Accepted
time: 15ms
memory: 37760kb

input:

526583 1344 500217637

output:

108767800

result:

ok 1 number(s): "108767800"

Test #36:

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

input:

867054 769 93998191

output:

239123369

result:

ok 1 number(s): "239123369"

Extra Test:

score: 0
Extra Test Passed