QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355351 | #5827. 异或图 | wsyear | 10 | 7ms | 6024kb | C++14 | 6.2kb | 2024-03-16 16:20:58 | 2024-03-16 16:20:58 |
Judging History
answer
// Author: Klay Thompson
// Problem: P10104 [GDKOI2023 提高组] 异或图
// Memory Limit: 1 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D("[Debug] "#__VA_ARGS__ " = "), \
debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
template <int P>
class mod_int {
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const {
Z res = 1, t = *this;
while (k) {
if (k & 1) res *= t;
if (k >>= 1) t *= t;
}
return res;
}
Z &operator++() {
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--() {
x ? --x : x = P - 1;
return *this;
}
Z operator++(int) {
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int) {
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs) {
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs) {
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z &operator*=(const Z &rhs) {
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) {\
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
};
const int P = 998244353;
using Z = mod_int<P>;
const int maxn = 15;
int n, m, tot, e[maxn][maxn], p[maxn];
ll C, a[maxn], b[maxn], mn[1 << maxn];
Z f[maxn][1 << maxn], g[1 << maxn], h[1 << maxn], dp[maxn][2][2];
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> m >> C;
rep (i, 0, n - 1) cin >> a[i], p[i] = i;
sort(p, p + n, [&](int x, int y) { return a[x] < a[y]; });
sort(a, a + n);
rep (i, 1, m) {
int u, v;
cin >> u >> v;
u = p[u - 1], v = p[v - 1];
e[u][v] = e[v][u] = 1;
}
rep (s, 0, (1 << n) - 1) {
mn[s] = 2e18;
rep (i, 0, n - 1) if (s >> i & 1) chkmn(mn[s], a[i]);
}
rep (i, 0, n - 1) g[1 << i] = 1;
rep (i, 0, n - 1) rep (j, i + 1, n - 1) if (e[i][j]) {
rep (s, 0, (1 << n) - 1) if ((s >> i & 1) && (s >> j & 1)) g[s] = 0;
per (s, (1 << n) - 1, 0) if ((s >> i & 1) && (s >> j & 1)) {
for (int t = s; t; t = (t - 1) & s) {
if ((t >> i & 1) && (t >> j & 1)) continue;
if (((s ^ t) >> i & 1) && ((s ^ t) >> j & 1)) continue;
if (__builtin_ctz(s) != __builtin_ctz(t)) continue;
g[s] -= g[t] * g[s ^ t];
}
}
}
rep (s, 1, (1 << n) - 1) {
tot = 0;
rep (i, 0, n - 1) if (s >> i & 1) b[tot++] = a[i];
per (dig, 59, 0) {
ll msk = (1ll << 60) - (1ll << (dig + 1)), sum = 0;
rep (i, 0, tot - 1) sum ^= (msk & b[i]);
if (sum != (C & msk)) break;
rep (i, 0, tot - 1) dp[i][0][0] = dp[i][0][1] = dp[i][1][0] = dp[i][1][1] = 0;
if (b[0] >> dig & 1) dp[0][0][1] = (b[0] & ((1ll << dig) - 1)) + 1, dp[0][1][0] = 1;
else dp[0][0][0] = (b[0] & ((1ll << dig) - 1)) + 1;
rep (i, 1, tot - 1) {
if (b[i] >> dig & 1) {
dp[i][0][0] = dp[i - 1][0][1] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][0][1] = dp[i - 1][0][0] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][1][0] = dp[i - 1][1][0] * (1ll << dig) + dp[i - 1][1][1] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][1][1] = dp[i - 1][1][1] * (1ll << dig) + dp[i - 1][1][0] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][1][0] += dp[i - 1][0][0], dp[i][1][1] += dp[i - 1][0][1];
} else {
dp[i][0][0] = dp[i - 1][0][0] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][0][1] = dp[i - 1][0][1] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][1][0] = dp[i - 1][1][0] * ((b[i] & ((1ll << dig) - 1)) + 1);
dp[i][1][1] = dp[i - 1][1][1] * ((b[i] & ((1ll << dig) - 1)) + 1);
}
}
h[s] += dp[tot - 1][1][C >> dig & 1];
}
ll sum = 0;
rep (i, 0, tot - 1) sum ^= b[i];
if (sum == C) h[s]++;
}
rep (s, 0, (1 << n) - 1) if (s & 1) f[0][(__builtin_popcount(s) & 1) ? s : (s ^ 1)] = g[s] * ((__builtin_popcount(s) & 1) ? 1 : mn[s] + 1);
rep (i, 0, n - 1) rep (s, 0, (1 << n) - 1) {
if (!f[i][s].val()) continue;
int p = n;
per (j, n - 1, i + 1) if (!(s >> j & 1)) p = j;
if (p == n) continue;
int rs = 0;
rep (j, i + 1, n - 1) if (!(s >> j & 1)) rs |= (1 << j);
for (int t = rs; t; t = (t - 1) & rs) {
if (t >> p & 1) {
int ts = 0;
Z coe = 1;
if (__builtin_popcount(t) & 1) ts |= (1 << p);
else coe = mn[t] + 1;
rep (j, 0, i) if (s >> j & 1) ts |= (1 << j);
rep (j, p + 1, n - 1) if ((t >> j & 1) || (s >> j & 1)) ts |= (1 << j);
f[p][ts] += g[t] * f[i][s] * coe;
}
}
}
Z ans = 0;
rep (i, 0, n - 1) rep (s, 0, (1 << n) - 1) {
int rs = 0, ok = 1;
rep (j, 0, i) if (s >> j & 1) rs |= (1 << j);
rep (j, i + 1, n - 1) if (!(s >> j & 1)) ok = 0;
if (ok) ans += f[i][s] * h[rs];
}
cout << ans.val() << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 1ms
memory: 5848kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
44
result:
ok 1 number(s): "44"
Test #2:
score: -20
Wrong Answer
time: 0ms
memory: 5756kb
input:
4 4 6 12 14 14 5 4 2 1 4 3 2 1 2
output:
804
result:
wrong answer 1st numbers differ - expected: '798', found: '804'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 10
Accepted
Test #47:
score: 10
Accepted
time: 7ms
memory: 6024kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
231790380
result:
ok 1 number(s): "231790380"
Test #48:
score: 0
Accepted
time: 2ms
memory: 5864kb
input:
11 0 101435837408688522 638776638580507479 933944392115323974 19098604312360490 142362319980029593 419910251764515410 275591812677260089 770239593400917018 928344484461634421 67340905784404712 378109786925249078 110881245457449811
output:
242383534
result:
ok 1 number(s): "242383534"
Test #49:
score: 0
Accepted
time: 2ms
memory: 5760kb
input:
9 0 100988561775675251 622570387572403506 684352103903274038 784649864569409753 270298495621205212 56183537059869110 346856482529145989 86639702870530669 607198038565138736 14747634008501988
output:
20893166
result:
ok 1 number(s): "20893166"
Test #50:
score: 0
Accepted
time: 2ms
memory: 5828kb
input:
10 0 839910859917247463 611237879350518457 292219463776059962 548211857317940894 822255554598388425 335628456629874391 774414280870858683 882480367082748768 654587410087321403 74330774886125511 22894883233341926
output:
61697734
result:
ok 1 number(s): "61697734"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%