# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
545930 | rainboy | Amusement Park (CEOI19_amusementpark) | C11 | 300 ms | 59892 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* https://codeforces.com/blog/entry/68748?#comment-530893 (Paulliant) */
#include <stdio.h>
#define N 18
#define MD 998244353
#define MD2 996491788296388609LL
#define V2 499122177
void sub(int *aa, int n) {
int i, b;
for (i = 0; i < n; i++)
for (b = 0; b < 1 << n; b++)
if ((b & 1 << i) != 0 && (aa[b] += aa[b ^ 1 << i]) >= MD)
aa[b] -= MD;
}
int main() {
static int adj[N], cnt[1 << N], dp[N + 1][1 << N];
static long long dq[N + 1][1 << N];
int n, m, h, i, j, k, l, b, c;
long long ans;
scanf("%d%d", &n, &m);
for (h = 0; h < m; h++) {
scanf("%d%d", &i, &j), i--, j--;
adj[i] |= 1 << j, adj[j] |= 1 << i;
}
for (b = 1; b < 1 << n; b++)
cnt[b] = cnt[b & b - 1] + 1;
for (b = 1; b < 1 << n; b++) {
c = 0;
for (i = 0; i < n; i++)
if ((b & 1 << i) != 0)
c |= adj[i];
if ((b & c) != 0)
continue;
dp[cnt[b]][b] = cnt[b] % 2 == 0 ? MD - 1 : 1;
}
for (k = 0; k <= n; k++)
sub(dp[k], n);
for (b = 0; b < 1 << n; b++)
dq[0][b] = 1;
for (k = 0; k < n; k++) {
for (b = 0; b < 1 << n; b++)
dq[k][b] %= MD;
for (l = 1; k + l <= n; l++)
for (b = 0; b < 1 << n; b++)
if ((dq[k + l][b] += dq[k][b] * dp[l][b]) >= MD2)
dq[k + l][b] -= MD2;
}
ans = 0;
for (b = 0; b < 1 << n; b++)
ans += dq[k][b] % MD * (cnt[(1 << n) - 1 ^ b] % 2 == 0 ? 1 : -1);
ans %= MD;
if (ans < 0)
ans += MD;
ans = ans * m % MD * V2 % MD;
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |