QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#147409#6647. 老虎机275307894aTL 0ms0kbC++142.3kb2023-08-23 06:42:032023-08-25 01:28:50

Judging History

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

  • [2023-08-25 01:28:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-08-23 06:42:03]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=15+5,M=(1<<15)+5,K=14348907+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,k,m,A[M],Po[N];ll p[N],f[M],t[M],ans[M];char s[N];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
const int inv=mpow(10000);
int tg[K];
void dfs(int x,int y,int Is){
	if(tg[x]==-1) return;
	if(tg[x]==0) tg[x]=Is;
	else tg[x]=-1;
	if(y==k) return;
	for(int j=y;j<k;j++) dfs(x-x/Po[j]%3*Po[j]+2*Po[j],j+1,Is);
}
void find(int x,int y,int z,int Is){
	if(tg[x]^Is) return;
	ans[Is]-=f[z]*t[z]%mod;
	// cerr<<x<<' '<<tg[x]<<' '<<z<<' '<<Is<<'\n';
	if(y==k) return;
	for(int j=y;j<k;j++) find(x-x/Po[j]%3*Po[j]+2*Po[j],j+1,z^(1<<j),Is);
}
void Solve(){
	int i,j,h;scanf("%d%d",&k,&n);m=1<<k;
	for(i=0;i<k;i++) scanf("%lld",&p[i]),p[i]=p[i]*inv%mod;
	for(i=1;i<=n;i++) {
		scanf("%s",s);A[i]=0;
		for(j=0;j<k;j++) A[i]|=s[j]-'0'<<j;
	}
	Me(f,0);Me(t,0);
	f[0]=1;
	for(i=0;i<m-1;i++){
		ll q=1;for(j=0;j<n;j++) if(!(i>>j&1)) q=q*(mod+1-p[j])%mod;
		t[i]=mpow(mod+1-q);
		int x=(m-1)^i;
		for(j=x;j;j=(j-1)&x){
			ll w=1;
			for(h=0;h<k;h++) if(x>>h&1) w=w*(j>>h&1?p[h]:mod+1-p[h])%mod;
			f[i|j]=(f[i|j]+f[i]*w%mod*t[i])%mod;
		}
		// cerr<<f[i]<<' '<<t[i]<<'\n';
	}
	// cerr<<f[m-1]<<' '<<t[m-1]<<'\n';
	for(Po[0]=i=1;i<=k;i++) Po[i]=Po[i-1]*3;
	Me(tg,0);
	for(i=1;i<=n;i++){
		int x=0;for(j=0;j<k;j++) if(A[i]>>j&1) x+=Po[j];
		dfs(x,0,i);
	}
	Me(ans,0);
	ll tot=0;for(i=0;i<m;i++) tot+=f[i]*t[i]%mod;
	fill(ans+1,ans+n+1,tot);
	for(i=1;i<=n;i++){
		int x=0;for(j=0;j<k;j++) if(A[i]>>j&1) x+=Po[j];
		find(x,0,m-1,i);
	}
	for(i=1;i<=n;i++) printf("%lld\n",(ans[i]%mod+mod)%mod);
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;                                                                                       
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

10
15 662
5038 7472 8988 9724 4995 8209 3006 2436 5397 5524 3147 6106 5676 4188 475
001000000000000
001100100000000
001001100000000
111101010000000
001000110000000
110100110000000
001010110000000
000011110000000
010100001000000
010101001000000
010100101000000
000100011000000
101010011000000
11110101...

output:

690415724
590627067
730242968
379405319
996869142
880487147
597828086
658381497
278692939
160995569
129766959
587935669
690507371
851039814
438800999
326795029
807064875
558071134
947554428
90050808
918834217
559606509
452849471
980346403
678014414
696434401
969455023
621259310
364054773
86478946
61...

result: