Submission #579552

#TimeUsernameProblemLanguageResultExecution timeMemory
579552amunduzbaevAmusement Park (CEOI19_amusementpark)C++17
63 / 100
3069 ms28872 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; int tot = (1 << n) - 1; for(int mask=0;mask <= tot;mask++){ for(int j=0;j<n;j++){ if(mask >> j & 1) continue; int cur = (1 << j) - 1; int on_j = mask | (1 << j); for(int m2=on_j;m2 <= tot; m2++, m2 |= on_j){ int bad = m2 ^ on_j; if(!dp[mask].count(bad)) continue; int edge_out = tot ^ (is[j] ^ (is[j] & mask)); int bad2 = ((bad | cur) ^ (mask & cur)) & edge_out; dp[on_j][bad2] = (dp[on_j][bad2] + dp[mask][bad]) % 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...