QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643118 | #247. 州区划分 | Lackofgod | 0 | 4ms | 81400kb | C++14 | 2.6kb | 2024-10-15 19:00:30 | 2024-10-15 19:00:30 |
Judging History
answer
#include <bits/stdc++.h>
#define forn(i,aa,bb) for(int i=aa;i<=bb;++i)
#define LL long long
#define pii pair<int,int>
using namespace std;
const int N=2.5e6+5;
const LL mod=998244353;
int n,m,p;
int f[23][(1<<21)],g[23][(1<<21)];
int d[30],w[30];
bool vis[30];
vector<int> G[N];
int s[N],sum[N];
int inv[N];
vector<int> q;
int qpow(int aa,int bb){
int ans=1;
for(;bb>0;bb>>=1) {
if (bb&1ll) ans=1ll*ans*aa%mod;
aa=1ll*aa*aa%mod;
}
return ans;
}
int calc(int x){ return __builtin_popcount(x); }
int calc1(int x) {
int ans=1;
forn(i,1,p)
ans=1ll*ans*x%mod;
return ans;
}
int lowbit(int x){
return x&(-x);
}
void OR(int*f,int x,int n){ // [0,n-1]
for(int len=2;len<=n;len*=2){
for(int i=0;i<n;i+=len){
int mid=len>>1;
for(int j=0;j<mid;j++){
f[i+j+mid]=(f[i+j+mid]+1ll*f[i+j]*x%mod)%mod;
f[i+j+mid]=(f[i+j+mid]+mod)%mod;
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
//cin>>T;
T=1;
while (T--) {
cin>>n>>m>>p;
forn(i,0,n-1)
s[(1<<i)]=i+1;
forn(i,1,m) {
int x,y;
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
forn(i,1,n)
cin>>w[i];
int lim=n; n=(1<<n);
f[0][0]=0;
forn(i,1,n-1) {
q.clear();
forn(j,0,lim)
d[j]=0,vis[j]=0;
for(int x=i;x>0;x-=lowbit(x)) {
int now=s[lowbit(x)];
vis[now]=1;
sum[i]+=w[now];
q.push_back(now);
}
bool fl=0;
for(int x:q) {
for(int y:G[x])
if (vis[y]) d[x]++;
if (d[x]&1ll) {
fl=1;
break;
}
}
if (fl) g[calc(i)][i]=calc1(sum[i]);
else g[calc(i)][i]=0;
}
g[0][0]=1ll;
forn(i,0,lim)
OR(g[i],1,n);
forn(i,1,n-1)
inv[i]=qpow(sum[i],mod-2);
f[0][0]=1ll;
OR(f[0],1,n);
forn(i,1,lim) {
forn(j,0,i)
forn(k,0,n-1)
f[i][k]=(f[i][k]+1ll*f[i-j][k]*g[j][k]%mod)%mod;
OR(f[i],-1,n);
forn(k,0,n-1)
if (calc(k)==i) f[i][k]=1ll*f[i][k]*inv[k]%mod;
if (i<lim) OR(f[i],1,n);
}
cout<<f[lim][n-1]<<'\n';
}
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 81400kb
input:
5 4 2 3 1 4 1 5 1 4 3 94 45 77 43 3
output:
33307
result:
wrong answer 1st numbers differ - expected: '652834711', found: '33307'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%