Submission #599791

#TimeUsernameProblemLanguageResultExecution timeMemory
599791flappybirdAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1468 ms3500 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 20 #define MAXS 18 #define INF 1000000000000000001 #define bb ' ' #define ln '\n' #define Ln '\n' #define smin(a, x) (a)=(min((a), (x))) ll dp[303030]; int ban[MAX]; int mul[303030]; const int mod = 998244353; signed main() { ios::sync_with_stdio(false), cin.tie(0); int N, M; cin >> N >> M; int i, j, a, b; for (i = 1; i <= M; i++) { cin >> a >> b; ban[--a] |= 1 << --b; ban[b] |= 1 << a; } int K = 1 << N; dp[0] = 1; for (j = 0; j < K; j++) { int c = 0; for (int k = 0; k < N; k++) if ((j & (1 << k)) && (ban[k] & j)) c = 1; if (c) continue; mul[j] = -1; for (int k = 0; k < N; k++) if (j & (1 << k)) mul[j] *= -1; } for (i = 0; i < K; i++) { for (j = i; j; (--j) &= i) { dp[i] += dp[i ^ j] * (ll)mul[j], dp[i] %= mod; } } if (dp[K - 1] < 0ll) dp[K - 1] += mod; dp[K - 1] *= M; dp[K - 1] %= mod; if (dp[K - 1] % 2) dp[K - 1] += mod; dp[K - 1] /= 2; cout << dp[K - 1] << ln; }
#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...