Submission #748192

#TimeUsernameProblemLanguageResultExecution timeMemory
748192PVSekharAmusement Park (CEOI19_amusementpark)C++14
100 / 100
2380 ms4436 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long // const ll MOD = 1e9+7; const ll MOD = 998244353; const ll N=18; const ll inv=499122177; int edges[N+1]; ll ans[(1<<N)+1]; int cnt[(1<<N)+1];//parity of number of bits int ind[(1<<N)+1];//independence of nodes in set int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); for(int i=0;i<=N;i++)edges[i]=0; for(int i=0;i<=(1<<N);i++)ans[i]=0; for(int i=0;i<=(1<<N);i++)cnt[i]=0; for(int i=0;i<=(1<<N);i++)ind[i]=0; int n,m,a,b; cin>>n>>m; for (int i = 0; i < m; i++) { cin>>a>>b; a--; b--; edges[a]+=(1<<b); edges[b]+=(1<<a); } for (int i = 0; i < (1<<n); i++) { int check=1,num=0; for (int k = 0; k < n; k++) { if((i^(1<<k))<i){ if((edges[k]&i))check=0; } if(!check)break; } ind[i]=check; for (int k = 0; k < n; k++)if((i^(1<<k))<i)cnt[i]++; cnt[i]%=2; } ans[0]=1; for (int i = 1; i < (1<<n); i++) { for (int j = i; j > 0; j=((j-1)&i)) { if(!ind[j])continue; // cout<<i<<" "<<j<<" "<<cnt<<"\n"; if(cnt[j]){ ans[i]+=ans[i^j]; }else{ ans[i]-=ans[i^j]; ans[i]+=MOD; } ans[i]%=MOD; } } cout<<(((ans[(1<<n)-1]*m)%MOD)*inv)%MOD<<"\n"; return 0; }

Compilation message (stderr)

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:34:21: warning: unused variable 'num' [-Wunused-variable]
   34 |         int check=1,num=0;
      |                     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...