QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303108 | #5827. 异或图 | Leasier | 10 | 60ms | 11320kb | C++11 | 3.4kb | 2024-01-11 18:19:59 | 2024-01-11 18:19:59 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int refer[17], edge[17], coef[65537], lst[65537], dp[17][7][7];
bool inside[65537];
pair<ll, int> pr[17];
unordered_map<int, int> mp[65537];
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++){
dp[j][k][l] = 0;
}
}
}
dp[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++){
dp[j][k][l] = dp[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(dp[j][k ^ 1][l], 1ll * dp[j - 1][k][l] * way % mod);
}
add1(dp[j][k][1], add2(dp[j - 1][k][0], 1ll * dp[j - 1][k][1] * power % mod));
}
} else {
for (int k = 0; k <= 1; k++){
for (int l = 0; l <= 1; l++){
add1(dp[j][k][l], 1ll * dp[j - 1][k][l] * way % mod);
}
}
}
}
}
add1(ans, dp[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]);
}
}
mp[0][0] = 1;
for (int i = 0; i < full; i++){
int cnt = 0, t = full ^ i;
for (int j = t; ; j = t & (j - 1)){
lst[++cnt] = j;
if (j == 0) break;
}
for (int j = cnt; j >= 1; j--){
if (!mp[i].count(lst[j])) 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(mp[i][lst[j] | cur], 1ll * mp[i][lst[j]] * coef[cur] % mod * (pr[low].first % mod) % mod);
} else {
add1(mp[i | (1 << (low - 1))][lst[j] | k], 1ll * mp[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 * mp[i][full ^ i] * calc(i, n, c) % mod);
}
cout << ans;
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7268kb
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: 10
Accepted
Test #47:
score: 10
Accepted
time: 60ms
memory: 11320kb
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: 0ms
memory: 7572kb
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: 3ms
memory: 7204kb
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: 0ms
memory: 7332kb
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%