Submission #728958

#TimeUsernameProblemLanguageResultExecution timeMemory
728958Rafi22Amusement Park (CEOI19_amusementpark)C++14
63 / 100
1784 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=998244353; int inf=1000000007; ll infl=1000000000000000007; const int N=18; unordered_map<int,int>DP[(1<<N)]; vector<int>inside[(1<<N)]; int G[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,a,b; cin>>n>>m; for(int i=0;i<m;i++) { cin>>a>>b; a--,b--; G[a]^=(1<<b); G[b]^=(1<<a); } for(int i=0;i<(1<<n);i++) { for(int j=0;j<n;j++) if(i&(1<<j)) inside[i].pb(j); } DP[0][(1<<n)-1]=1; for(int a=0;a<(1<<n);a++) { int d=(1<<n)-1-a; for(int b=d;b>0;b=(b-1)&d) { int x=DP[a][b]; if(x==0) continue; for(auto k:inside[b]) { int A=a^(1<<k),B=(b&((1<<n)-(1<<(k+1))))|(G[k]&((1<<n)-1-a-(1<<k))); int y=DP[A][B]; y+=x; if(y>=mod) y-=mod; DP[A][B]=y; } } } cout<<(ll)DP[(1<<n)-1][0]*(ll)m%mod*499122177%mod; return 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...