QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#668931 | #5827. 异或图 | HuTao | 0 | 73ms | 47512kb | C++14 | 3.8kb | 2024-10-23 16:38:18 | 2024-10-23 16:38:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 17, M = 110, T = 14348910, P = 998244353;
const int p3[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907};
int n, m, p[N], q[N];
LL C, a[N];
int u[N], v[N], fa[N];
inline int gfa(int i) {return i == fa[i] ? i : fa[i] = gfa(fa[i]);}
inline bool CheckConnect(int s, int &mn, int &cnt)
{
for(int i = 0; i < n; i ++ ) fa[i] = i;
for(int i = 0; i < m; i ++ )
if((s >> u[i] & 1) && (s >> v[i] & 1))
fa[gfa(u[i])] = gfa(v[i]);
mn = cnt = 0;
int ff = -1;
for(int i = 0; i < n; i ++ )
if(s >> i & 1)
{
if(ff == -1)
{
ff = gfa(i);
mn = i;
cnt = 1;
}
else
{
if(gfa(i) != ff) return 0;
cnt ^= 1;
}
}
return 1;
}
int st[T];
vector<int> state, state0[N], state1[N];
LL c[T], cc[T], g[T], f[T];
inline void DP0()
{
for(int i : state)
{
int s = ((1 << n) - 1) ^ i, t = s;
if((i & -i) == i) c[i] = 1;
(cc[i] += c[i]) >= P && (cc[i] -= P);
do{
if(st[t])
{
c[i | t] = (c[i | t] + (P - c[i]) * cc[t]) % P;
cc[i | t] = (cc[i | t] + c[i] * cc[t]) % P;
}
t = (t - 1) & s;
}while(t != s);
}
// for(int i = 0; i < (1 << n); i ++ ) printf("%lld ", c[i]);
// puts("");
}
inline void DP1()
{
g[0] = 1;
for(int j = n - 1; j >= 0; j -- )
{
for(int i : state0[j])
{
int s = ((1 << n) - 1) ^ i, t = s;
do{
g[i | t] = (g[i | t] + g[t] * c[i] % P * ((a[j] + 1) % P)) % P;
t = (t - 1) & s;
}while(t != s);
}
}
// for(int i = 0; i < (1 << n); i ++ ) printf("%lld ", g[i]);
// puts("");
}
inline void DFS(int i, int t0, int t1, const int &s)
{
if(i == n)
{
f[t1] = (f[t1] + f[t0] * c[s]) % P;
return ;
}
if(s >> i & 1)
{
DFS(i + 1, t0, t1 + p3[i], s);
}
else
{
DFS(i + 1, t0, t1, s);
DFS(i + 1, t0 + p3[i], t1 + p3[i], s);
DFS(i + 1, t0 + p3[i] * 2, t1 + p3[i] * 2, s);
}
}
inline void DP2()
{
f[0] = 1;
for(int i = n - 1; i >= 0; i -- )
{
for(int j : state1[i])
DFS(i + 1, 0, p3[i] * 2, j);
}
}
int k;
LL b[N];
inline LL Calc()
{
// printf("#%d\n", k);
// for(int i = 0; i < k; i ++ ) printf("%lld ", b[i]);
// puts("");
LL ans = 0;
for(int i = 59; i >= 0; i -- )
{
int c = 0;
LL h0 = 1, h1 = 0, h2 = 0, t0, t1, t2;
for(int j = 0; j < k; j ++ )
{
LL t = (b[j] & ((1LL << i) - 1)) % P + 1;
if(b[j] >> i & 1)
{
c ^= 1;
t0 = h0 * t % P;
t1 = (h0 + (h2 << i) + h1 * t) % P;
t2 = ((h1 << i) + h2 * t) % P;
h0 = t0, h1 = t1, h2 = t2;
}
else
{
h0 = h0 * t % P;
h1 = h1 * t % P;
h2 = h2 * t % P;
}
}
(ans += (((C >> i) ^ c) & 1 ? h1 : h2)) >= P && (ans -= P);
if(c != (C >> i & 1)) return ans;
}
( ++ ans) >= P && (ans -= P);
return ans;
}
LL ans = 0;
inline void DFS1(int i, int t0, int t1)
{
if(i == n)
{
if(!f[t0] || !g[t1]) return ;
ans = (ans + f[t0] * g[t1] % P * Calc()) % P;
// printf("!%d %d %d %lld %lld\n", k, t0, t1, f[t0] * g[t1] % P, ans);
return ;
}
DFS1(i + 1, t0, t1 | 1 << i);
DFS1(i + 1, t0 + p3[i], t1);
b[k ++ ] = a[i];
DFS1(i + 1, t0 + p3[i] * 2, t1);
k -- ;
}
int main()
{
scanf("%d%d%lld", &n, &m, &C);
for(int i = 0; i < n; i ++ ) scanf("%lld", &a[i]), p[i] = i;
sort(p, p + n, [](const int &x, const int &y){return a[x] < a[y];});
for(int i = 0; i < n; i ++ ) q[p[i]] = i;
sort(a, a + n);
for(int i = 0; i < m; i ++ ) scanf("%d%d", &u[i], &v[i]), u[i] = q[u[i] - 1], v[i] = q[v[i] - 1];
for(int i = 1; i < 1 << n; i ++ )
{
int mn = 0, cnt = 0;
if(CheckConnect(i, mn, cnt))
{
st[i] = 1;
state.push_back(i);
if(cnt) state1[mn].push_back(i);
else state0[mn].push_back(i);
}
}
DP0(), DP1(), DP2(), DFS1(0, 0, 0);
printf("%lld\n", ans);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 1ms
memory: 10024kb
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
Accepted
time: 0ms
memory: 9960kb
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: 20
Accepted
time: 0ms
memory: 10000kb
input:
3 3 2 10 4 11 2 1 3 2 1 3
output:
33
result:
ok 1 number(s): "33"
Test #4:
score: 20
Accepted
time: 0ms
memory: 10020kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 9948kb
input:
5 6 14 12 15 13 13 12 3 1 2 4 2 5 2 1 5 3 4 5
output:
21819
result:
wrong answer 1st numbers differ - expected: '21337', found: '21819'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 73ms
memory: 47512kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
-536433629
result:
wrong answer 1st numbers differ - expected: '231790380', found: '-536433629'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%