QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689406 | #2889. 密集子图 | ffffyc | AC ✓ | 140ms | 174952kb | C++14 | 2.3kb | 2024-10-30 16:53:05 | 2024-10-30 16:53:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
int len=0;
char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
#define reg register
inline int read(){
reg char ch=gh();
reg int x=0;
reg char t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
inline void putc(char ch){
out[len++]=ch;
}
template<class T>
inline void write(T x){
if(x<0)putc('-'),x=-x;
if(x>9)write(x/10);
out[len++]=x%10+48;
}
inline void flush(){
fwrite(out,1,len,stdout);
len=0;
}
inline char getc(){
char ch=gh();
while(ch<'A'||ch>'Z') ch=gh();
return ch;
}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=12+2,S=1<<12,mod=998244353;
inline int add(int a,int b){ return a+b>=mod?a+b-mod:a+b; }
inline int dec(int a,int b){ return a>=b?a-b:a+mod-b; }
inline void inc(int &a,int b){ a=a+b>=mod?a+b-mod:a+b; }
inline int qpow(int x,int y){
int res=1;
while(y){
if(y&1) res=1ll*res*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return res;
}
int n,u,k,w[N][N],f[2][S][S],ci[S][S],ic[S][S],ip[N],ans;
int main(){
n=read(),k=read(),u=1<<n;
for(int c=1;c<=n*(n-1);c++){
int i=read()-1,j=read()-1,x=read(),y=read();
w[i][j]=1ll*x*qpow(y,mod-2)%mod;
}
for(int s=1;s<u;s++){
for(int i=0;i<n;i++){
if(s>>i&1) continue;
int tp=1;
for(int j=0;j<n;j++)
if(s>>j&1)
tp=1ll*tp*dec(1,w[j][i])%mod;
ip[i]=dec(1,tp);
}
for(int rs=(u-1)^s,r=rs;r;r=(r-1)&rs){
int tp1=1,tp2=1;
for(int i=0;i<n;i++)
if(r>>i&1)
tp1=1ll*tp1*ip[i]%mod,
tp2=1ll*tp2*dec(1,ip[i])%mod;
ci[s][r]=tp1,ic[s][r]=tp2;
}
ic[0][s]=1;
}
f[0][1][1]=1;
for(int d=1,c=0;d<=k;d++,c^=1){
for(int s=1;s<u;s+=2)
for(int t=s,rs=(u-1)^s;t;t=(t-1)&s){
int v=f[c][s][t];
if(!v) continue;
for(int r=rs;r;r=(r-1)&rs)
inc(f[!c][s^r][r],1ll*v*ci[t][r]%mod*ic[s^t][r]%mod);
f[c][s][t]=0;
}
for(int t=0;t<u;t++)
inc(ans,f[c^1][u-1][t]);
}
write(ans);
flush();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13960kb
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: 3ms
memory: 46832kb
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: 3ms
memory: 47076kb
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: 4ms
memory: 46816kb
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: 3ms
memory: 47160kb
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: 47044kb
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: 47176kb
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: 4ms
memory: 47080kb
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: 31ms
memory: 87804kb
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: 88292kb
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: 134ms
memory: 174344kb
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: 2ms
memory: 9836kb
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: 140ms
memory: 174952kb
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: 0ms
memory: 14084kb
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: 2ms
memory: 9864kb
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: 9924kb
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: 2ms
memory: 9956kb
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: 0ms
memory: 44984kb
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: 0ms
memory: 28496kb
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: 12ms
memory: 46852kb
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'