제출 #572991

#제출 시각아이디문제언어결과실행 시간메모리
572991piOOEAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1420 ms2900 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int)size(x)) #define all(x) begin(x), end(x) #define trace(x) cout << #x << ": " << (x) << endl; typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; } const int N = 18, MOD = 998244353; int dp[1 << N], popc[1 << N]; bool ok[1 << N]; int add(int a, int b) { return a + b < MOD ? a + b : a + b - MOD; } int mul(int a, int b) { return a * (ll) b % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); memset(ok, 1, sizeof(ok)); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; ok[(1 << a) | (1 << b)] = false; } for (int mask = 1; mask < (1 << n); ++mask) { popc[mask] = __builtin_popcount(mask); for (int i = 0; i < n; ++i) { if ((mask & (1 << i)) && !ok[mask ^ (1 << i)]) { ok[mask] = false; break; } } } dp[0] = 1; for (int mask = 1; mask < (1 << n); ++mask) { for (int msk = mask; msk > 0; msk = (msk - 1) & mask) { if (!ok[msk]) { continue; } if (popc[msk] & 1) { dp[mask] = add(dp[mask], dp[mask ^ msk]); } else { dp[mask] = add(dp[mask], MOD - dp[mask ^ msk]); } } } cout << mul(dp[(1 << n) - 1], mul(m, (MOD + 1) >> 1)); 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...