Submission #579565

#TimeUsernameProblemLanguageResultExecution timeMemory
579565amunduzbaevAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1548 ms234764 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef int64_t ll; //~ #define int ll const int mod = 119 << 23 | 1; const int N = 18; map<int, int> dp[1 << N]; int is[N]; int bp(int a, int b){ int c = 1; while(b){ if(b & 1) c = c * 1ll * a % mod; a = a * 1ll * a % mod, b >>= 1; } return c; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; for(int i=0;i<m;i++){ int a, b; cin>>a>>b; --a, --b; is[a] |= (1 << b); is[b] |= (1 << a); } dp[0][0] = 1; for(int mask=0;mask < (1 << n);mask++){ vector<int> rem; for(int i=0;i<n;i++) if(!(mask >> i & 1)) rem.push_back(i); for(auto& [bad, cur] : dp[mask]){ for(auto j : rem){ if(bad >> j & 1) continue; int on_j = mask | (1 << j); int edge_out = ((1 << n) - 1) ^ (is[j] ^ (is[j] & mask)); int bad2 = ((bad | ((1 << j) - 1)) ^ (mask & ((1 << j) - 1))) & edge_out; int& res = dp[on_j][bad2]; res = (res + cur); if(res >= mod) res -= mod; } } } int res = dp[(1 << n) - 1][0]; //~ cout<<res<<"\n"; cout<<res * 1ll * bp(2, mod - 2) % mod * m % mod<<"\n"; }
#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...