QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#669149 | #5827. 异或图 | HuTao | 20 | 167ms | 47528kb | C++14 | 3.9kb | 2024-10-23 17:26:44 | 2024-10-23 17:27:07 |
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;
else c[i] = P - cc[i];
(cc[i] += c[i]) >= P && (cc[i] -= P);
do{
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 * ((1 << i) % P) + h1 * t) % P;
t2 = (h1 * ((1 << i) % P) + 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 = 0; i < m; i ++ ) printf("*%d %d\n", u[i], v[i]);
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: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 10044kb
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: 2ms
memory: 9972kb
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: 10040kb
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: 2ms
memory: 10040kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 20
Accepted
time: 0ms
memory: 10032kb
input:
5 6 14 12 15 13 13 12 3 1 2 4 2 5 2 1 5 3 4 5
output:
21337
result:
ok 1 number(s): "21337"
Test #6:
score: 20
Accepted
time: 2ms
memory: 9956kb
input:
4 5 5 5 2 4 13 2 1 3 4 1 4 4 2 3 2
output:
42
result:
ok 1 number(s): "42"
Test #7:
score: 20
Accepted
time: 0ms
memory: 10108kb
input:
4 4 3 13 7 8 12 4 1 3 1 2 4 4 3
output:
552
result:
ok 1 number(s): "552"
Test #8:
score: 20
Accepted
time: 2ms
memory: 9912kb
input:
4 2 12 1 12 4 11 2 1 3 1
output:
70
result:
ok 1 number(s): "70"
Test #9:
score: 20
Accepted
time: 0ms
memory: 10036kb
input:
5 5 6 10 7 8 2 13 1 5 1 3 2 1 4 3 5 3
output:
1231
result:
ok 1 number(s): "1231"
Test #10:
score: 20
Accepted
time: 2ms
memory: 9916kb
input:
5 7 9 6 7 13 15 12 1 3 5 3 5 2 4 5 4 3 4 1 3 2
output:
6223
result:
ok 1 number(s): "6223"
Test #11:
score: 20
Accepted
time: 0ms
memory: 10108kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 20
Accepted
time: 2ms
memory: 10032kb
input:
3 2 9 10 6 5 1 2 1 3
output:
17
result:
ok 1 number(s): "17"
Test #13:
score: 20
Accepted
time: 0ms
memory: 10024kb
input:
5 5 11 7 9 15 9 9 5 4 5 1 5 2 1 3 3 4
output:
5224
result:
ok 1 number(s): "5224"
Test #14:
score: 20
Accepted
time: 0ms
memory: 9968kb
input:
5 0 12 9 8 14 11 2
output:
3006
result:
ok 1 number(s): "3006"
Test #15:
score: 20
Accepted
time: 2ms
memory: 9912kb
input:
3 1 1 6 10 4 3 1
output:
30
result:
ok 1 number(s): "30"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #16:
score: 0
Wrong Answer
time: 0ms
memory: 10208kb
input:
9 27 705410105529944560 929827299070190972 733413770730537329 473007347105710981 190062421504120247 918561152768663129 196040702922254016 981530663192980241 203295856357272834 337150461958783092 2 8 7 9 8 9 2 3 9 2 2 7 9 5 9 4 4 8 1 7 6 3 6 1 4 1 6 5 2 4 2 1 9 3 9 6 7 3 7 5 5 2 4 5 2 6 3 1 3 8 4 3 8 6
output:
156916887
result:
wrong answer 1st numbers differ - expected: '5392583', found: '156916887'
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 167ms
memory: 47528kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
624244102
result:
wrong answer 1st numbers differ - expected: '231790380', found: '624244102'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%