QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751242#9611. 木桶效应ANIG20 191ms26752kbC++142.3kb2024-11-15 17:41:262024-11-15 17:41:26

Judging History

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

  • [2024-11-15 17:41:26]
  • 评测
  • 测评结果:20
  • 用时:191ms
  • 内存:26752kb
  • [2024-11-15 17:41:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=55,M=(1<<10)+5,mods=998244353;
int pows(int a,int b){
	if(b==0)return 1;
	int res=pows(a,b>>1);
	res=res*res%mods;
	if(b&1)res=res*a%mods;
	return res;
}
struct node{
	int x,y,w;
}g[N];
int n,m,qs,sz,f[N][N][M],cnt[M],jc[M],ny[M],bh[N],idx;
vector<int>zj[M],dy[N];
int C(int a,int b){
	if(a<0||b<0||a<b)return 0;
	return jc[a]*ny[b]%mods*ny[a-b]%mods;
}
signed main(){
	vector<int>jl;
	auto fd=[&](int x){
		return lower_bound(jl.begin(),jl.end(),x)-jl.begin();
	};
	cin>>n>>m>>qs;
	for(int i=1;i<=qs;i++){
		cin>>g[i].x>>g[i].y>>g[i].w;
		if(!bh[g[i].y])bh[g[i].y]=++idx;
		jl.push_back(g[i].x);
	}
	for(int i=0;i<(1<<idx);i++){
		for(int j=i;j;j=j-1&i)zj[i].push_back(j);
		zj[i].push_back(0);
		cnt[i]=__builtin_popcount(i);
	}
	sort(jl.begin(),jl.end());
	jl.resize(unique(jl.begin(),jl.end())-jl.begin());
	for(int i=1;i<=qs;i++)dy[fd(g[i].x)].push_back(i);
	sz=jl.size();
	jc[0]=ny[0]=1;
	for(int i=1;i<=n;i++)jc[i]=jc[i-1]*i%mods,ny[i]=pows(jc[i],mods-2);
	f[0][n-idx][(1<<idx)-1]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=n-idx;j++){
			for(int k=0;k<(1<<idx);k++){
			    for(int l=0;l<=j;l++){
			    	for(auto t:zj[k]){
			    		int ans=0;
			    		for(int r=0;r<=l;r++){
			    			int sm=0;
			    			for(auto s:zj[t]){
			    				int tmp=pows(n-i-(j-l)-r-(cnt[k]-cnt[t])-cnt[s],m-sz);
			    				for(int u=0;u<sz;u++){
			    					int sm=n-i-(j-l)-r-(cnt[k]-cnt[t])-cnt[s],op=0;
			    					for(auto d:dy[u]){
			    						if((s>>bh[g[d].y]-1&1^1)&&((k^t)>>bh[g[d].y]-1&1^1)&&g[d].w>i)sm--;
			    						if(g[d].w==i)op=bh[g[d].y];
			    					}
			    					if(op){
			    						if((k^t)>>op-1&1)sm=0;
			    						else if(s>>op-1&1)sm=0;
			    						else sm=1;
			    					}
			    					tmp=tmp*sm%mods;
			    				}
			    				if(cnt[s]&1)sm-=tmp;
			    				else sm+=tmp;
			    			}
			    			sm%=mods;
			    			if(r&1)ans-=sm*C(l,r)%mods;
			    			else ans+=sm*C(l,r)%mods;
			    		}
						ans%=mods;
			    		f[i+1][j-l][k^t]+=f[i][j][k]*ans%mods*pows(i+1,l+cnt[t])%mods*C(j,l)%mods;
			    	}
			    }
			}
		}
		for(int j=0;j<=n-idx;j++){
			for(int k=0;k<(1<<idx);k++){
				f[i+1][j][k]%=mods;
			//	cout<<i+1<<" "<<j<<" "<<k<<" "<<f[i+1][j][k]<<endl;
			}
		}
	}
	cout<<(f[n][0][0]+mods)%mods;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 1ms
memory: 5700kb

input:

5 3 0

output:

21412920

result:

ok single line: '21412920'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 7672kb

input:

5 3 2
3 4 4
2 5 3

output:

828618

result:

wrong answer 1st lines differ - expected: '847674', found: '828618'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 12ms
memory: 26632kb

input:

50 1 0

output:

263941435

result:

ok single line: '263941435'

Test #8:

score: 8
Accepted
time: 7ms
memory: 22320kb

input:

43 2 0

output:

136378346

result:

ok single line: '136378346'

Test #9:

score: 8
Accepted
time: 18ms
memory: 26752kb

input:

50 2 0

output:

489087596

result:

ok single line: '489087596'

Subtask #4:

score: 12
Accepted

Dependency #3:

100%
Accepted

Test #10:

score: 12
Accepted
time: 191ms
memory: 26504kb

input:

50 292247015 0

output:

226872193

result:

ok single line: '226872193'

Test #11:

score: 12
Accepted
time: 156ms
memory: 26572kb

input:

50 873009728 0

output:

63648791

result:

ok single line: '63648791'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #8:

0%