QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594131#2889. 密集子图ship2077AC ✓144ms256416kbC++231.6kb2024-09-27 19:35:192024-09-27 19:35:19

Judging History

This is the latest submission verdict.

  • [2024-09-27 19:35:19]
  • Judged
  • Verdict: AC
  • Time: 144ms
  • Memory: 256416kb
  • [2024-09-27 19:35:19]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=(1<<12)+5,mod=998244353;
int n,k,m,ans,a[13][13],res1[13][M],res2[M][M],res3[M][M],dp[13][M][M];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
int qpow(int x,int n){
    int s=1;while (n){
        if (n&1) s=1ll*s*x%mod;
        x=1ll*x*x%mod; n>>=1;
    } return s;
}
int rdc(int x){return x>=mod?x-mod:x;}
int main(){
    n=read();k=read();m=(1<<n)-1;
    for (int i=1;i<=n*(n-1);i++){
        int x=read(),y=read(),p=read(),q=read();
        a[x-1][y-1]=1ll*p*qpow(q,mod-2)%mod;
    }
    for (int i=0;i<n;i++)
        for (int sta=res1[i][0]=1;sta<=m;sta++){
            int low=sta&-sta,p=__builtin_ctz(sta);
            res1[i][sta]=1ll*res1[i][sta^low]*(mod+1-a[p][i])%mod;
        }
    for (int i=0;i<=m;i++)
        for (int sta=res2[i][0]=res3[i][0]=1;sta<=m;sta++){
            int low=sta&-sta,p=__builtin_ctz(sta);
            res2[i][sta]=1ll*res2[i][sta^low]*res1[p][i]%mod;
            res3[i][sta]=1ll*res3[i][sta^low]*(mod+1-res1[p][i])%mod;
        }
    dp[0][0][1]=1;
    for (int i=1;i<=k;i++){
        for (int s=1;s<=m;s++)
            for (int t=s;t;(--t)&=s){
                if (!dp[i-1][s^t][s]) continue;
                int sta=m^s;
                for (int p=sta;p;(--p)&=sta)
                    dp[i][s][s|p]=(dp[i][s][s|p]+1ll*dp[i-1][s^t][s]*res2[s^t][p]%mod*res3[t][p])%mod;
            }
        for (int j=1;j<=m;j++)
            ans=rdc(ans+dp[i][j][m]);
    }
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 10076kb

input:

5 2
1 4 56427109 606991454
3 1 487793106 676077026
3 5 72340646 115960795
3 4 111286308 439475455
4 3 3165516 128305017
1 3 24396079 573477048
5 1 447395517 901314953
2 5 2574474 277987429
1 2 420484321 660202741
2 3 48876465 659081847
4 5 544251503 764175644
5 4 60727244 762893819
4 1 715698235 974...

output:

136904393

result:

ok single line: '136904393'

Test #2:

score: 0
Accepted
time: 17ms
memory: 53948kb

input:

10 9
4 10 56232994 226874299
6 9 21007518 354387183
1 9 644052854 811830566
1 7 804073089 988348035
6 7 22824337 536950644
5 2 311892968 769069047
4 9 231055250 603727264
9 10 87797610 421971685
3 1 233327852 856883439
2 7 582745837 710866220
8 9 251310865 738132712
8 5 704143938 754140553
3 2 18708...

output:

453304103

result:

ok single line: '453304103'

Test #3:

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

input:

10 6
3 4 1 2
10 4 1 2
10 1 1 2
3 2 1 2
4 3 1 2
4 6 1 2
8 4 1 2
9 8 1 2
8 2 1 2
2 7 1 2
8 3 1 2
1 2 1 2
8 7 1 2
1 6 1 2
6 3 1 2
2 5 1 2
4 1 1 2
6 7 1 2
6 10 1 2
5 2 1 2
1 8 1 2
1 4 1 2
3 1 1 2
2 4 1 2
4 8 1 2
4 2 1 2
1 10 1 2
4 7 1 2
5 10 1 2
2 3 1 2
9 6 1 2
8 6 1 2
8 10 1 2
7 3 1 2
10 2 1 2
9 1 1 2
...

output:

923478165

result:

ok single line: '923478165'

Test #4:

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

input:

10 8
4 2 1 2
6 5 1 2
10 7 1 2
3 1 1 2
2 4 1 2
8 7 1 2
7 5 1 2
8 9 1 2
9 6 1 2
2 5 1 2
5 3 1 2
7 8 1 2
3 8 1 2
1 3 1 2
4 10 1 2
10 5 1 2
7 6 1 2
7 2 1 2
10 1 1 2
7 4 1 2
9 7 1 2
1 10 1 2
9 8 1 2
5 6 1 2
3 6 1 2
5 4 1 2
5 8 1 2
3 9 1 2
3 4 1 2
5 2 1 2
7 9 1 2
6 7 1 2
6 9 1 2
9 1 1 2
7 1 1 2
9 5 1 2
3 ...

output:

301003872

result:

ok single line: '301003872'

Test #5:

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

input:

10 7
4 8 1 2
4 7 1 2
1 7 0 1
4 3 1 2
8 4 0 1
9 5 1 2
8 9 1 2
10 7 1 2
8 6 1 2
7 1 1 2
4 6 1 2
6 1 1 2
3 10 1 2
5 10 1 2
3 9 1 2
10 4 1 2
9 7 1 2
7 9 1 2
6 9 1 2
10 1 1 2
9 2 1 2
10 5 1 2
10 9 1 2
5 8 1 2
9 1 1 2
3 7 1 2
2 1 1 2
3 2 1 2
7 8 1 2
6 7 1 2
10 2 0 1
7 10 1 2
8 7 1 2
2 3 0 1
2 6 0 1
2 8 1 ...

output:

476419709

result:

ok single line: '476419709'

Test #6:

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

input:

10 5
8 2 0 1
7 2 1 2
6 3 1 2
1 8 1 2
9 3 1 2
1 2 1 2
6 4 1 2
8 6 0 1
1 9 1 2
3 5 1 2
5 7 1 2
2 5 1 2
8 7 1 2
1 4 1 2
9 1 1 2
4 10 1 2
3 10 0 1
8 9 1 2
3 6 1 2
8 5 1 2
1 5 1 2
6 1 0 1
2 10 1 2
6 9 1 2
6 5 1 2
1 6 1 2
2 3 1 2
4 3 1 2
9 8 0 1
8 1 1 2
5 6 1 2
9 2 1 2
10 9 0 1
3 9 1 2
7 8 1 2
5 10 0 1
9 ...

output:

763052824

result:

ok single line: '763052824'

Test #7:

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

input:

10 7
8 7 306708432 768415750
8 2 558623889 824391857
9 3 22900898 958786971
5 3 41177682 49073086
8 1 302090535 989478233
10 9 28538906 273709737
5 4 310580250 336934541
2 7 391982262 783649098
1 8 99036525 360225467
10 3 148937902 399447072
3 10 199533994 404126126
9 6 778782929 990414638
1 9 21924...

output:

112617945

result:

ok single line: '112617945'

Test #8:

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

input:

10 6
1 6 42561704 180868457
6 5 486852955 590254496
1 10 94613022 799997575
3 4 171287567 382015991
9 2 368609400 541632011
8 2 9073882 963403739
4 8 418898799 814136332
7 3 110798098 188829266
7 5 396232285 654541079
2 7 29619882 435220549
3 1 233819471 527349958
3 6 25757100 179321329
2 3 39998754...

output:

320618543

result:

ok single line: '320618543'

Test #9:

score: 0
Accepted
time: 24ms
memory: 110792kb

input:

11 7
10 5 332391915 555869306
5 7 559104879 815273866
5 3 538503101 849174866
10 11 286809324 468797302
6 11 85271126 535744477
9 3 530314680 974060588
3 9 151508583 781638505
11 10 415332987 720567712
2 10 538878061 569872677
2 5 573386546 719516337
5 10 34124545 807450785
2 11 536482184 858748179
...

output:

705046959

result:

ok single line: '705046959'

Test #10:

score: 0
Accepted
time: 24ms
memory: 111960kb

input:

11 8
9 1 409758495 451743405
7 2 794462004 973967853
4 1 3653205 702961053
3 11 527860714 990558967
4 7 269425256 303681323
4 11 221495849 606967822
8 1 530493754 664158544
6 10 6791463 358695865
4 10 182997050 845289599
9 8 29966078 651187157
11 8 258656462 393304806
6 9 124181743 240060423
5 9 618...

output:

181037559

result:

ok single line: '181037559'

Test #11:

score: 0
Accepted
time: 144ms
memory: 254120kb

input:

12 8
2 10 210062994 490287677
1 5 198690049 221617901
3 7 204739753 770779829
7 11 447812212 555202110
11 4 433726525 734395100
5 4 722815236 930942839
3 2 27052249 36698440
8 2 74352296 292061080
10 9 339548130 783536966
6 7 418950243 907568601
4 5 237698236 864805326
12 11 288683075 796813311
10 5...

output:

692537227

result:

ok single line: '692537227'

Test #12:

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

input:

5 3
4 3 43747095 148956208
3 4 847034560 969760917
1 5 175549552 387202157
1 2 422665369 556514536
1 3 107995358 476550185
4 1 76783498 680782254
5 2 23112164 453726809
5 1 553938770 720497880
5 4 51309724 578667230
3 2 131923295 301666613
3 5 73501524 709365504
5 3 44452592 557174893
2 5 209729254 ...

output:

312398132

result:

ok single line: '312398132'

Test #13:

score: 0
Accepted
time: 102ms
memory: 256416kb

input:

12 9
8 11 366725388 467725450
12 8 295479639 448377391
1 12 5387863 969142841
9 6 176662776 204772512
1 3 462479590 898927048
10 6 703445836 801388516
8 2 263958403 995927421
8 9 299816170 340754241
6 12 621135702 690613307
2 6 209028961 285504322
6 2 415622013 766150761
9 11 249362806 785365842
4 8...

output:

137709457

result:

ok single line: '137709457'

Test #14:

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

input:

5 3
5 2 22542121 887477358
2 3 327595119 402238767
2 5 125368583 246007117
4 2 639141205 706948513
4 3 480337384 793944345
5 1 279755772 531780590
1 2 423614073 456133345
1 3 432936373 682494137
4 5 456537224 831955467
4 1 209851941 826116591
5 3 292488641 684474188
1 5 17264553 398803254
2 1 274000...

output:

872691703

result:

ok single line: '872691703'

Test #15:

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

input:

4 2
1 2 355817691 424595544
3 1 137509354 392113026
3 4 349387008 626507379
2 1 118129143 706828238
4 2 440488747 685242390
4 1 342920384 971450927
2 3 410437119 932688610
4 3 429379245 895712751
3 2 5572773 343030533
2 4 187696608 215692639
1 4 188556887 714285917
1 3 183251093 389322562

output:

29091743

result:

ok single line: '29091743'

Test #16:

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

input:

4 3
1 3 208347260 360224842
2 1 587281366 730086747
4 3 7088701 305662159
2 4 452355797 807145513
1 2 425217091 646810839
2 3 60279087 827143432
4 1 70096133 73740584
3 4 463457103 958848185
1 4 548490675 618222388
3 2 896558700 933046890
3 1 195214776 460308958
4 2 511757224 844633042

output:

936501175

result:

ok single line: '936501175'

Test #17:

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

input:

5 2
5 3 7599843 928532203
1 2 36601042 426056742
1 3 241786972 321460650
3 1 630080203 909139887
3 2 309804891 638412224
3 4 410493258 425374196
4 3 444294031 611448967
3 5 220341269 775705284
4 2 699551484 950638414
5 4 548344979 649158047
5 2 352303307 829505829
4 5 182250714 312915047
2 5 7448071...

output:

458234109

result:

ok single line: '458234109'

Test #18:

score: 0
Accepted
time: 9ms
memory: 40756kb

input:

10 1
1 5 760137998 851661231
8 2 139011657 715382231
8 9 194449226 738868607
9 3 381482209 919350427
8 7 219168693 503741614
1 2 232025248 433777443
4 3 290764755 777935039
1 8 69594093 180059368
4 7 73383499 118813384
6 7 386548765 838702947
8 10 278711947 646883010
6 1 704237723 864962354
3 4 3669...

output:

70893419

result:

ok single line: '70893419'

Test #19:

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

input:

9 8
6 2 484962713 658647463
3 4 541813315 706980621
6 4 156159398 507109190
6 3 650469940 932636299
4 3 160813991 624564868
3 6 357756095 602417269
1 2 435086072 814077080
6 9 1403845 256156786
4 2 7428878 135026245
1 6 215354079 928492279
5 4 313354053 558060684
2 6 262322231 677024064
2 7 56281080...

output:

16107274

result:

ok single line: '16107274'

Test #20:

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

input:

10 9
2 8 8867281 470903964
8 4 844022268 898454406
1 5 71423032 482285876
2 6 95200164 268063273
8 7 482828764 960723839
7 1 38935089 395345873
4 3 340273557 823314763
7 3 29457243 434072447
10 1 699220809 958693021
2 10 185046292 472621602
6 9 829168811 896217630
3 4 22671881 887762060
10 5 4125219...

output:

829905555

result:

ok single line: '829905555'