QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751224 | #9611. 木桶效应 | ANIG | 20 | 193ms | 26676kb | C++14 | 2.2kb | 2024-11-15 17:35:09 | 2024-11-15 17:35:09 |
Judging History
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[s],m-sz);
for(int u=0;u<sz;u++){
int sm=n-i-(j-l)-r-cnt[s],op=0;
for(auto d:dy[u]){
if((s>>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(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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 0ms
memory: 5928kb
input:
5 3 0
output:
21412920
result:
ok single line: '21412920'
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 5916kb
input:
5 3 2 3 4 4 2 5 3
output:
34991040
result:
wrong answer 1st lines differ - expected: '847674', found: '34991040'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 8
Accepted
Test #7:
score: 8
Accepted
time: 11ms
memory: 26188kb
input:
50 1 0
output:
263941435
result:
ok single line: '263941435'
Test #8:
score: 8
Accepted
time: 11ms
memory: 24216kb
input:
43 2 0
output:
136378346
result:
ok single line: '136378346'
Test #9:
score: 8
Accepted
time: 13ms
memory: 25112kb
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: 193ms
memory: 26052kb
input:
50 292247015 0
output:
226872193
result:
ok single line: '226872193'
Test #11:
score: 12
Accepted
time: 155ms
memory: 26676kb
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%