Submission #782029

#TimeUsernameProblemLanguageResultExecution timeMemory
782029LoboAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1313 ms223032 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 18; const int mod = 998244353; int n, m, g[maxn]; unordered_map<int,int> dp[(1<<maxn)]; int opos(int x) { return (1<<n)-1-x; } void solve() { cin >> n >> m; for(int i = 1; i <= m; i++) { int u,v; cin >> u >> v; u--; v--; g[u]+= (1<<v); g[v]+= (1<<u); } dp[0][(1<<n)-1] = 1; for(int use = 0; use < (1<<n)-1; use++) { for(auto X : dp[use]) { int nxt = X.fr; int cnt = X.sc; for(int i = 0; i < n; i++) { if(((1<<i)&nxt) == 0) continue; int use1 = use+(1<<i); int nxt1 = ((nxt&opos((1<<(i+1))-1))|g[i])&(opos(use1)); dp[use1][nxt1]+= cnt; dp[use1][nxt1]%= mod; } } } cout << dp[(1<<n)-1][0]*m%mod*((mod+1)/2)%mod << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { solve(); } }
#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...