QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559649 | #247. 州区划分 | ucup-team3659 | Compile Error | / | / | C++20 | 2.7kb | 2024-09-12 08:02:16 | 2024-09-12 08:02:16 |
Judging History
This is the latest submission verdict.
- [2024-09-12 08:02:16]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-09-12 08:02:16]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
long long dp[22][1<<21],f[22][1<<21];
int num[1<<21],flag[1<<21],inv[1<<21];
int w[22];
int popcount[1<<21];
int lg[1<<21];
int fa[21],d[21];
int u[505],v[505];
int root(int u)
{
if(fa[u]==u)
return u;
return fa[u]=root(fa[u]);
}
void merge(int u,int v)
{
u=root(u);
v=root(v);
fa[u]=v;
}
int n,m,p;
int pw(long long a,int b)
{
long long ans=1;
while(b)
{
if(b&1)
ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
void add(long long &x,long long y)
{
x+=y;
if(x>=mod)
x-=mod;
}
void FWT(long long *a,int n,int f)
{
for(int j=0;j<n;j++)
for(int i=0;i<(1<<n);i++)
{
if(!f) if((i>>j)&1) add(a[i],a[i^(1<<j)]);
if(f) if((i>>j)&1) add(a[i],mod-a[i^(1<<j)]);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>p;
lg[1]=0;
for(int i=2;i<(1<<n);i++)
lg[i]=lg[i>>1]+1;
popcount[0]=0;
for(int i=1;i<(1<<n);i++)
popcount[i]=popcount[i&(i-1)]+1;
for(int i=1;i<=m;i++)
{
cin>>u[i]>>v[i];
u[i]--,v[i]--;
}
for(int i=0;i<n;i++)
cin>>w[i];
for(int i=0;i<n;i++)
fa[i]=i;
for(int S=0;S<(1<<n);S++)
{
// cout<<S<<"\n";
for(int i=0;i<n;i++)
if(S&(1<<i))
num[S]+=w[i];
num[S]=pw(num[S],p);
inv[S]=pw(num[S],mod-2);
for(int j=0;j<n;j++)
fa[j]=j,d[j]=0;
for(int i=1;i<=m;i++)
if((S&(1<<u[i]))&&(S&(1<<v[i])))
{
d[u[i]]++;
d[v[i]]++;
merge(u[i],v[i]);
}
// cout<<n<<"\n";
flag[S]=0;
for(int i=0;i<n;i++)
if((S&(1<<i))&&(d[i]&1))
flag[S]=1;
int cnt=0;
for(int i=0;i<n;i++)
cnt+=(root(i)==i&&(S&(1<<i)));
if(cnt>=2)
flag[S]=1;
if(flag[S])
f[popcount[S]][S]=num[S];
}
dp[0][0]=1;
FWT(dp[0],n,0);
for(int i=0;i<=n;i++)
FWT(f[i],n,0);
for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++)
for(int k=0;k<(1<<n);k++)
dp[i][k]+=dp[j][k]*f[i-j][k]%mod;
for(int j=0;j<(1<<n);j++)
dp[i][j]%=mod;
FWT(dp[i],n,1);
// for(int j=0;j<(1<<n);j++)
// cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
for(int j=0;j<(1<<n);j++)
if(popcount[j]==i)
dp[i][j]=dp[i][j]*inv[j]%mod;
FWT(dp[i],n,0);
}
FWT(dp[n],n,1);
cout<<dp[n][(1<<n)-1];
}
Details
answer.code: In function ‘int main()’: answer.code:60:5: error: reference to ‘popcount’ is ambiguous 60 | popcount[0]=0; | ^~~~~~~~ In file included from /usr/include/c++/13/bits/stl_algobase.h:76, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bit:426:5: note: candidates are: ‘template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)’ 426 | popcount(_Tp __x) noexcept | ^~~~~~~~ answer.code:7:5: note: ‘int popcount [2097152]’ 7 | int popcount[1<<21]; | ^~~~~~~~ answer.code:62:9: error: reference to ‘popcount’ is ambiguous 62 | popcount[i]=popcount[i&(i-1)]+1; | ^~~~~~~~ /usr/include/c++/13/bit:426:5: note: candidates are: ‘template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)’ 426 | popcount(_Tp __x) noexcept | ^~~~~~~~ answer.code:7:5: note: ‘int popcount [2097152]’ 7 | int popcount[1<<21]; | ^~~~~~~~ answer.code:62:21: error: reference to ‘popcount’ is ambiguous 62 | popcount[i]=popcount[i&(i-1)]+1; | ^~~~~~~~ /usr/include/c++/13/bit:426:5: note: candidates are: ‘template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)’ 426 | popcount(_Tp __x) noexcept | ^~~~~~~~ answer.code:7:5: note: ‘int popcount [2097152]’ 7 | int popcount[1<<21]; | ^~~~~~~~ answer.code:100:15: error: reference to ‘popcount’ is ambiguous 100 | f[popcount[S]][S]=num[S]; | ^~~~~~~~ /usr/include/c++/13/bit:426:5: note: candidates are: ‘template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)’ 426 | popcount(_Tp __x) noexcept | ^~~~~~~~ answer.code:7:5: note: ‘int popcount [2097152]’ 7 | int popcount[1<<21]; | ^~~~~~~~ answer.code:117:16: error: reference to ‘popcount’ is ambiguous 117 | if(popcount[j]==i) | ^~~~~~~~ /usr/include/c++/13/bit:426:5: note: candidates are: ‘template<class _Tp> constexpr std::_If_is_unsigned_integer<_Tp, int> std::popcount(_Tp)’ 426 | popcount(_Tp __x) noexcept | ^~~~~~~~ answer.code:7:5: note: ‘int popcount [2097152]’ 7 | int popcount[1<<21]; | ^~~~~~~~