QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100900 | #5827. 异或图 | Scintilla | 0 | 1340ms | 43276kb | C++14 | 3.1kb | 2023-04-28 17:03:53 | 2023-04-28 17:03:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
const int P = 998244353;
const int N = 16;
const int M = 1 << N;
const int K = 14348907;
const int L = 60;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
int inc(int a, int b) { return (a += b) >= P ? a - P : a; }
int dec(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
void add(int &a, int b) { (a += b) >= P ? a -= P : 1; }
void sub(int &a, int b) { (a -= b) < 0 ? a += P : 1; }
int sgn(int x) { return x & 1 ? P - 1 : 1; }
int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }
int n, m, c, a[N], id[N], rk[N], e[N], f[M], g[M], pw[N], dat[M], h[K], ans;
int dig(int x, int k) {
return (x / pw[k]) % 3;
}
int dp[N][2][2];
int calc(vector <int> val) {
int m = val.size(), res = 0;
drep(i, L - 1, 0) {
int cnt = 0, t = 1;
memset(dp, 0, sizeof(dp));
dp[0][0][0] = 1;
rep(j, 0, m - 1) rep(x, 0, 1) rep(y, 0, 1) {
add(dp[j + 1][x ^ (val[j] >> i & 1)][0], mul(dp[j][x][y], (val[j] & ((1ll << i) - 1)) % P));
if (val[j] >> i & 1) {
add(dp[j + 1][x][1], mul(dp[j][x][y], y ? ((1ll << i) % P) : 1));
}
}
add(res, dp[m][c >> i & 1][1]);
}
return res;
}
signed main() {
n = read(), m = read(), c = read();
pw[0] = 1;
rep(i, 1, n) pw[i] = mul(pw[i - 1], 3);
rep(i, 0, n - 1) a[i] = read() + 1, id[i] = i;
sort(id, id + n, [&](int i, int j) { return a[i] < a[j]; });
rep(i, 0, n - 1) rk[id[i]] = i;
sort(a, a + n);
rep(i, 1, m) {
int u = rk[read() - 1], v = rk[read() - 1];
e[u] |= 1 << v, e[v] |= 1 << u;
}
for (int s = 0; s < 1 << n; ++ s) {
g[s] = 1;
rep(i, 0, n - 1) if (s >> i & 1) {
g[s] &= !__builtin_popcount(e[i] & s);
dat[s] += pw[i];
}
f[s] = g[s];
if (!s) continue;
int p = __lg(s & -s);
for (int t = s & s - 1; t; t = s & t - 1) {
if (!(t >> p & 1)) continue;
sub(f[s], mul(f[t], g[s ^ t]));
}
}
h[0] = 1;
for (int s = 0; s < pw[n]; ++ s) {
auto mn = [&]() {
rep(i, 0, n - 1) if (!dig(s, i)) return i;
return -1ll;
} ;
int p = mn();
if (!~p) {
vector <int> val;
rep(i, 0, n - 1) if (dig(s, i) == 2) val.emplace_back(a[i]);
add(ans, mul(h[s], calc(val)));
}
else {
int r = 0;
rep(i, p, n - 1) if (!dig(s, i)) r |= 1 << i;
for (int t = r; t; t = r & t - 1) {
if (!(t >> p & 1)) continue;
add(h[s + dat[t] + pw[p]], mul(h[s], f[t]));
}
}
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 5512kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
24
result:
wrong answer 1st numbers differ - expected: '44', found: '24'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 1340ms
memory: 43276kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
60148091
result:
wrong answer 1st numbers differ - expected: '231790380', found: '60148091'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%