QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303091 | #5827. 异或图 | Leasier | 0 | 1ms | 5876kb | C++98 | 3.3kb | 2024-01-11 18:02:55 | 2024-01-11 18:02:56 |
answer
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int refer[17], edge[17], coef[65537], dp1[4097][4097], lst[65537], dp2[17][7][7];
bool inside[65537];
pair<ll, int> pr[17];
inline void sub(int &x, int y){
if ((x -= y) < 0) x += mod;
}
inline void add1(int &x, int y){
if ((x += y) >= mod) x -= mod;
}
inline int add2(int x, int y){
return x + y >= mod ? x + y - mod : x + y;
}
inline int calc(int state, int n, ll c){
int ans = 0;
ll xor_val = 0;
for (int i = 1; i <= n; i++){
if (state >> (i - 1) & 1) xor_val ^= pr[i].first;
}
for (int i = 59; i >= 0; i--){
int power = (1ll << i) % mod;
for (int j = 1; j <= n; j++){
for (int k = 0; k <= 1; k++){
for (int l = 0; l <= 1; l++){
dp2[j][k][l] = 0;
}
}
}
dp2[0][0][0] = 1;
for (int j = 1; j <= n; j++){
if (!(state >> (j - 1) & 1)){
for (int k = 0; k <= 1; k++){
for (int l = 0; l <= 1; l++){
dp2[j][k][l] = dp2[j - 1][k][l];
}
}
} else {
int way = (pr[j].first & ((1ll << i) - 1)) % mod;
if (pr[j].first >> i & 1){
for (int k = 0; k <= 1; k++){
for (int l = 0; l <= 1; l++){
add1(dp2[j][k ^ 1][l], 1ll * dp2[j - 1][k][l] * way % mod);
}
add1(dp2[j][k][1], add2(dp2[j - 1][k][0], 1ll * dp2[j - 1][k][1] * power % mod));
}
} else {
for (int k = 0; k <= 1; k++){
for (int l = 0; l <= 1; l++){
add1(dp2[j][k][l], 1ll * dp2[j - 1][k][l] * way % mod);
}
}
}
}
}
add1(ans, dp2[n][c >> i & 1][1]);
if ((xor_val >> i & 1) != (c >> i & 1)) break;
}
return ans;
}
int main(){
int n, m, full, ans = 0;
ll c;
cin >> n >> m >> c;
full = (1 << n) - 1;
for (int i = 1; i <= n; i++){
ll limit;
cin >> limit;
pr[i] = make_pair(++limit, i);
}
sort(pr + 1, pr + n + 1);
for (int i = 1; i <= n; i++){
refer[pr[i].second] = i;
}
for (int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
u = refer[u];
v = refer[v];
edge[u] |= 1 << (v - 1);
edge[v] |= 1 << (u - 1);
}
for (int i = 1; i <= full; i++){
int low = __builtin_ctz(i) + 1;
inside[i] = inside[i ^ (1 << (low - 1))] || (i & edge[low]) != 0;
}
coef[0] = 1;
for (int i = 1; i <= full; i++){
int low = __builtin_ctz(i) + 1, t = i ^ (1 << (low - 1));
coef[i] = inside[i] ? 0 : 1;
for (int j = t; j != 0; j = t & (j - 1)){
if (!inside[j]) sub(coef[i], coef[i ^ j]);
}
}
dp1[0][0] = 1;
for (int i = 0; i < full; i++){
int cnt = 0, t = full ^ i;
for (int j = t & (t - 1); ; j = t & (j - 1)){
lst[++cnt] = j;
if (j == 0) break;
}
for (int j = cnt; j >= 1; j--){
if (dp1[i][lst[j]] == 0) continue;
int rem = t ^ lst[j], low = __builtin_ctz(rem) + 1;
rem ^= 1 << (low - 1);
for (int k = rem; ; k = rem & (k - 1)){
int cur = k | (1 << (low - 1));
if (__builtin_popcount(cur) % 2 == 0){
add1(dp1[i][lst[j] | cur], dp1[i][lst[j]] * coef[cur] % mod * (pr[low].first % mod) % mod);
} else {
add1(dp1[i | (1 << (low - 1))][lst[j] | k], 1ll * dp1[i][lst[j]] * coef[cur] % mod);
}
if (k == 0) break;
}
}
}
for (int i = 0; i <= full; i++){
if ((n - __builtin_popcount(i)) % 2 == 0) add1(ans, 1ll * dp1[i][full ^ i] * calc(i, n, c) % mod);
}
cout << ans;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 0ms
memory: 3552kb
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: 0
Accepted
time: 0ms
memory: 3616kb
input:
4 4 6 12 14 14 5 4 2 1 4 3 2 1 2
output:
798
result:
ok 1 number(s): "798"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 3 2 10 4 11 2 1 3 2 1 3
output:
33
result:
ok 1 number(s): "33"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: -20
Wrong Answer
time: 1ms
memory: 5876kb
input:
5 6 14 12 15 13 13 12 3 1 2 4 2 5 2 1 5 3 4 5
output:
796938917
result:
wrong answer 1st numbers differ - expected: '21337', found: '796938917'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #47:
score: 0
Runtime Error
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%