QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22967 | #2889. 密集子图 | ha114514ha# | AC ✓ | 210ms | 182012kb | C++20 | 3.7kb | 2022-03-11 12:35:27 | 2022-04-30 02:11:27 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#include<ctime>
#include<random>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define bc(x) __builtin_popcount(x)
#define re register
#define il inline
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
// #pragma GCC optimize(3)
//#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO_BUFF{
mt19937 rnd(time(0)^(ll)(new char));
int rend(int x){
return rnd()%x+1;
}
void rendom_shuffle(int *a,int len){
shuffle(a+1,a+len+1,rnd);
}
const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
inline int gc(){
if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);
return (HD==TL)?EOF:*HD++;
}
inline int inn(){
int x,ch,s=1;while((ch=gc())<'0'||ch>'9')if(ch=='-')s=-1;x=ch^'0';
while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x*s;
}
char ssss[19999999],tttt[20];int ssl,ttl;
inline int print(int x)
{
if(x<0)ssss[++ssl]='-',x=(-x);
if(!x) ssss[++ssl]='0';for(ttl=0;x;x/=10) tttt[++ttl]=char(x%10+'0');
for(;ttl;ttl--) ssss[++ssl]=tttt[ttl];return ssss[++ssl]='\n';
}
inline int Flush(){return fwrite(ssss+1,sizeof(char),ssl,stdout),ssl=0,0;}
int read(){
char c=getchar();int x=1;int s=0;
while(c<'0' || c>'9'){if(c=='-')x=-1;c=getchar();}
while(c>='0' && c<='9'){
s=s*10+c-'0';c=getchar();
}
return s*x;
}
}using namespace IO_BUFF;
namespace CFConTest{
const int mod=998244353;
inline int add(const int &x,const int &y){
return (x+y>=mod?x+y-mod:x+y);
}
inline int del(const int &x,const int &y){
return (x-y<0?x-y+mod:x-y);
}
int ksm(int x,int k){
int base=1;
while(k){
if(k&1)base=1ll*base*x%mod;
k>>=1;
x=1ll*x*x%mod;
}
return base;
}
};
using namespace CFConTest;
const int N=13;
const int M=12;
int n,m,x,y,aa,bb;
int p[N][N];
int f[N][1<<M][1<<M];
int g[1<<M][1<<M];
int h[N][1<<M];
int w[1<<M][1<<M];
int main(){
#ifdef newbiewzs
freopen("data.in","r",stdin);
#else
#endif
n=read();m=read();
for(int i=1;i<=n;i++){
for(int k=1;k<=n;k++){
if(i==k)continue;
x=read();y=read();aa=read();bb=read();
p[x][y]=1ll*aa*ksm(bb,mod-2)%mod;
}
}
int S=(1<<n)-1;
for(int i=1;i<=n;i++){
for(int k=0;k<(1<<n);k++){
int tmp=1;
for(int j=1;j<=n;j++){
if(k&(1<<(j-1)))tmp=1ll*tmp*(1-p[j][i]+mod)%mod;
}
h[i][k]=tmp; // 一个都不连
}
}
w[0][0]=g[0][0]=1;
for(int i=1;i<S;i++){
int T=S^i;
for(int k=T;k;k=(k-1)&T){
w[i][k]=g[i][k]=1;
for(int j=1;j<=n;j++){
if(k&(1<<(j-1))){
w[i][k]=1ll*w[i][k]*(1-h[j][i]+mod)%mod;
g[i][k]=1ll*g[i][k]*h[j][i]%mod;
}
}
}
w[i][0]=g[i][0]=1;
}
for(int i=0;i<S;i++)g[0][i]=1;
f[0][1][1]=1;
for(int i=0;i<m;i++){
for(int k=1;k<S;k++){
for(int j=k;j;j=(j-1)&k){
if(!f[i][k][j])continue;
int T=S^k;
for(int h=T;h;h=(h-1)&T){
int KEL=k^j;
f[i+1][k|h][h]=add(f[i+1][k|h][h],1ll*f[i][k][j]*w[j][h]%mod*g[KEL][h]%mod);
}
}
}
}
int ans=0;
for(int i=1;i<=m;i++){
for(int k=S;k;k=(k-1)&S){
ans=add(ans,f[i][S][k]);
}
}
cout<<ans;
#ifdef newbiewzs
cerr<<'\n'<<"Time:"<<clock()<<" ms"<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 20048kb
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: 43976kb
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: 43812kb
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: 15ms
memory: 44032kb
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: 43976kb
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: 14ms
memory: 43332kb
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: 17ms
memory: 43964kb
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: 43812kb
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: 75260kb
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: 44ms
memory: 75812kb
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: 210ms
memory: 180960kb
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: 16100kb
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: 189ms
memory: 182012kb
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: 3ms
memory: 15976kb
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: 3ms
memory: 13896kb
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: 3ms
memory: 19936kb
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: 0ms
memory: 20132kb
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: 10ms
memory: 36344kb
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: 1ms
memory: 35704kb
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: 3ms
memory: 43980kb
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'