QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88763 | #5827. 异或图 | wzh2021 | 0 | 0ms | 0kb | C++14 | 3.5kb | 2023-03-17 07:22:33 | 2023-03-17 07:22:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 20, S = 1 << 15, L = 61, P = 998244353;
ll c;
ll a[N];
int n, m, ans;
bool ed[N][N];
int f[S], g[S], h0[S];
int dp[L][S], h[N][S];
int p[N], q[N], pw2[N];
#define popc __builtin_popcount
int pls(int x, int y) {
return x + y < P ? x + y : x + y - P;
}
int sub(int x, int y) {
return x < y ? x + P - y : x - y;
}
void dfs(int d, int s, int t, int x, int y, int z) {
if (x > m) {
if (y && !z)
return;
if (!z)
dp[d - 1][t] = pls(dp[d - 1][t], dp[d][s]);
else
dp[d - 1][t] = (dp[d - 1][t] + (ll) dp[d][s] * (1 << (z - 1))) % P;
return;
}
if (!(s & pw2[x - 1]))
return dfs(d, s, t, x + 1, y, z + 1);
if ((a[p[x]] >> (d - 1)) & 1) {
dfs(d, s, t | pw2[x - 1], x + 1, !y, z);
dfs(d, s, t, x + 1, y, z);
return;
}
dfs(d, s, t | pw2[x - 1], x + 1, y, z);
}
int main() {
freopen("graph.in", "r", stdin);
freopen("graph.out", "w", stdout);
scanf("%d%d%lld", &n, &m, &c);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
p[i] = i;
}
sort(p + 1, p + n + 1, [] (int i, int j) {
return a[i] < a[j];
});
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
q[p[i]] = i;
pw2[0] = 1;
for (int i = 1; i <= n; ++i)
pw2[i] = pw2[i - 1] << 1;
for (int i = 1; i <= m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
if (u == v)
continue;
u = q[u];
v = q[v];
ed[u][v] = ed[v][u] = 1;
}
for (int i = 0; i < pw2[n]; ++i)
for (int j = 1; j <= n; ++j)
if (i & pw2[j - 1])
for (int k = j + 1; k <= n; ++k)
if (ed[j][k] && i & pw2[k - 1])
++f[i];
for (int i = 0; i < 1 << n; ++i) {
g[i] = !f[i];
int t = i & (-i);
for (int j = i; j; j = (j - 1) & i)
if (!f[j] && !(j & t))
g[i] = sub(g[i], g[i ^ j]);
}
h0[0] = 1;
for (int i = 1; i < 1 << n; ++i) {
int t = i & (-i);
for (int j = i; j; j = (j - 1) & i)
if (!(popc(j) & 1) && j & t)
h0[i] = (h0[i] + (a[(int) log2(j & (-j)) + 1] + 1) % P * h0[i ^ j] % P * g[j]) % P;
}
for (int s = 0; s < 1 << n; ++s) {
if ((n - popc(s)) & 1)
continue;
m = 0;
for (int i = 1; i <= n; ++i)
if (s & pw2[i - 1])
p[++m] = i;
for (int i = 0; i < L; ++i)
for (int j = 0; j < pw2[m]; ++j)
dp[i][j] = 0;
dp[L - 1][pw2[m] - 1] = 1;
for (int i = L - 1; i; --i) {
int opt = (c >> (i - 1)) & 1;
for (int j = 0; j < pw2[m]; ++j)
if (dp[i][j])
dfs(i, j, 0, 1, opt, 0);
}
h[0][0] = 1;
for (int i = 1; i <= m; ++i)
for (int j = 0; j < pw2[n - m]; ++j) {
h[i][j] = (ll) h[i - 1][j] * g[pw2[p[i] - 1]] % P;
for (int k = j; k; k = (k - 1) & j) {
if (popc(k) & 1)
continue;
int sta = pw2[p[i] - 1];
for (int l = 1, t = 1; l <= n; ++l)
if (!(s & pw2[l - 1])) {
if (k & pw2[t - 1]) {
if (l < p[i]) {
sta = -1;
break;
}
sta |= pw2[l - 1];
}
++t;
}
if (!~sta)
continue;
h[i][j] = (h[i][j] + (ll) h[i - 1][j ^ k] * g[sta]) % P;
}
}
int t1 = 0;
for (int i = 0; i < 1 << m; ++i)
t1 = pls(t1, dp[0][i]);
int t2 = 0;
for (int i = 0; i < pw2[n - m]; ++i) {
int sta = s;
for (int j = 1, k = 1; j <= n; ++j)
if (!(s & pw2[j - 1])) {
if (i & pw2[k - 1])
sta |= pw2[j - 1];
++k;
}
t2 = (t2 + (ll) h[m][i] * h0[(pw2[n] - 1) ^ sta]) % P;
}
ans = (ans + (ll) t1 * t2) % P;
}
printf("%d", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Dangerous Syscalls
Test #47:
score: 0
Dangerous Syscalls
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%