QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88764#5827. 异或图wzh202120 1599ms4984kbC++143.4kb2023-03-17 07:22:472023-03-17 07:22:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-17 07:22:50]
  • 评测
  • 测评结果:20
  • 用时:1599ms
  • 内存:4984kb
  • [2023-03-17 07:22:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 20, S = 1 << 15, L = 61, P = 998244353;
ll c;
ll a[N];
int n, m, ans;
bool ed[N][N];
int f[S], g[S], h0[S];
int dp[L][S], h[N][S];
int p[N], q[N], pw2[N];
#define popc __builtin_popcount
int pls(int x, int y) {
	return x + y < P ? x + y : x + y - P;
}
int sub(int x, int y) {
	return x < y ? x + P - y : x - y;
}
void dfs(int d, int s, int t, int x, int y, int z) {
	if (x > m) {
		if (y && !z)
			return;
		if (!z)
			dp[d - 1][t] = pls(dp[d - 1][t], dp[d][s]);
		else
			dp[d - 1][t] = (dp[d - 1][t] + (ll) dp[d][s] * (1 << (z - 1))) % P;
		return;
	}
	if (!(s & pw2[x - 1]))
		return dfs(d, s, t, x + 1, y, z + 1);
	if ((a[p[x]] >> (d - 1)) & 1) {
		dfs(d, s, t | pw2[x - 1], x + 1, !y, z);
		dfs(d, s, t, x + 1, y, z);
		return;
	}
	dfs(d, s, t | pw2[x - 1], x + 1, y, z);
}
int main() {
	scanf("%d%d%lld", &n, &m, &c);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		p[i] = i;
	}
	sort(p + 1, p + n + 1, [] (int i, int j) {
		return a[i] < a[j];
	});
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
		q[p[i]] = i;
	pw2[0] = 1;
	for (int i = 1; i <= n; ++i)
		pw2[i] = pw2[i - 1] << 1;
	for (int i = 1; i <= m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		if (u == v)
			continue;
		u = q[u];
		v = q[v];
		ed[u][v] = ed[v][u] = 1;
	}
	for (int i = 0; i < pw2[n]; ++i)
		for (int j = 1; j <= n; ++j)
			if (i & pw2[j - 1])
				for (int k = j + 1; k <= n; ++k)
					if (ed[j][k] && i & pw2[k - 1])
						++f[i];
	for (int i = 0; i < 1 << n; ++i) {
		g[i] = !f[i];
		int t = i & (-i);
		for (int j = i; j; j = (j - 1) & i)
			if (!f[j] && !(j & t))
				g[i] = sub(g[i], g[i ^ j]);
	}
	h0[0] = 1;
	for (int i = 1; i < 1 << n; ++i) {
		int t = i & (-i);
		for (int j = i; j; j = (j - 1) & i)
			if (!(popc(j) & 1) && j & t)
				h0[i] = (h0[i] + (a[(int) log2(j & (-j)) + 1] + 1) % P * h0[i ^ j] % P * g[j]) % P;
	}
	for (int s = 0; s < 1 << n; ++s) {
		if ((n - popc(s)) & 1)
			continue;
		m = 0;
		for (int i = 1; i <= n; ++i)
			if (s & pw2[i - 1])
				p[++m] = i;
		for (int i = 0; i < L; ++i)
			for (int j = 0; j < pw2[m]; ++j)
				dp[i][j] = 0;
		dp[L - 1][pw2[m] - 1] = 1;
		for (int i = L - 1; i; --i) {
			int opt = (c >> (i - 1)) & 1;
			for (int j = 0; j < pw2[m]; ++j)
				if (dp[i][j])
					dfs(i, j, 0, 1, opt, 0);
		}
		h[0][0] = 1;
		for (int i = 1; i <= m; ++i)
			for (int j = 0; j < pw2[n - m]; ++j) {
				h[i][j] = (ll) h[i - 1][j] * g[pw2[p[i] - 1]] % P;
				for (int k = j; k; k = (k - 1) & j) {
					if (popc(k) & 1)
						continue;
					int sta = pw2[p[i] - 1];
					for (int l = 1, t = 1; l <= n; ++l)
						if (!(s & pw2[l - 1])) {
							if (k & pw2[t - 1]) {
								if (l < p[i]) {
									sta = -1;
									break;
								}
								sta |= pw2[l - 1];
							}
							++t;
						}
					if (!~sta)
						continue;
					h[i][j] = (h[i][j] + (ll) h[i - 1][j ^ k] * g[sta]) % P;
				}
			}
		int t1 = 0;
		for (int i = 0; i < 1 << m; ++i)
			t1 = pls(t1, dp[0][i]);
		int t2 = 0;
		for (int i = 0; i < pw2[n - m]; ++i) {
			int sta = s;
			for (int j = 1, k = 1; j <= n; ++j)
				if (!(s & pw2[j - 1])) {
					if (i & pw2[k - 1])
						sta |= pw2[j - 1];
					++k;
				}
			t2 = (t2 + (ll) h[m][i] * h0[(pw2[n] - 1) ^ sta]) % P;
		}
		ans = (ans + (ll) t1 * t2) % P;
	}
	printf("%d", ans);
	return 0;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 2ms
memory: 4040kb

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: 2ms
memory: 3904kb

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: 2ms
memory: 3916kb

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: 2ms
memory: 4028kb

input:

4 0 4
9 8 5 2

output:

148

result:

ok 1 number(s): "148"

Test #5:

score: 0
Accepted
time: 0ms
memory: 4032kb

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: 0
Accepted
time: 2ms
memory: 4048kb

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: 0
Accepted
time: 2ms
memory: 3916kb

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: 0
Accepted
time: 0ms
memory: 4024kb

input:

4 2 12
1 12 4 11
2 1
3 1

output:

70

result:

ok 1 number(s): "70"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3912kb

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: 0
Accepted
time: 2ms
memory: 4048kb

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: 0
Accepted
time: 0ms
memory: 3920kb

input:

3 0 3
15 7 12

output:

104

result:

ok 1 number(s): "104"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

3 2 9
10 6 5
1 2
1 3

output:

17

result:

ok 1 number(s): "17"

Test #13:

score: 0
Accepted
time: 2ms
memory: 4052kb

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: 0
Accepted
time: 2ms
memory: 4052kb

input:

5 0 12
9 8 14 11 2

output:

3006

result:

ok 1 number(s): "3006"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

3 1 1
6 10 4
3 1

output:

30

result:

ok 1 number(s): "30"

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #16:

score: 50
Accepted
time: 41ms
memory: 3900kb

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:

5392583

result:

ok 1 number(s): "5392583"

Test #17:

score: 0
Accepted
time: 41ms
memory: 4060kb

input:

9 7 788762650337246371
605340092851479114 625896945107761227 361131331380167081 572133549445050458 929899192003968010 340514051531987427 690728985364969400 268762741220048006 818120252827139346
5 8
9 6
6 1
1 9
9 8
5 1
4 5

output:

35237078

result:

ok 1 number(s): "35237078"

Test #18:

score: 0
Accepted
time: 4ms
memory: 3888kb

input:

7 8 968166787047166534
945734997493219809 465616677643913237 530128109571749460 717120283671096308 118646732725835921 510958884109370001 797022604947155276
5 2
4 7
1 2
6 5
4 2
4 6
1 6
6 3

output:

133871438

result:

ok 1 number(s): "133871438"

Test #19:

score: 0
Accepted
time: 1599ms
memory: 4984kb

input:

12 21 341964498832651322
422448536649714733 488538974423366199 893293448611252565 879334133559023407 13516625885288091 43377983230712374 263189254162337644 474056776923289355 540904774976211471 103364876621830299 515157013276720499 213857038587555252
12 9
8 3
1 9
1 7
3 1
8 11
11 10
6 10
6 1
10 2
7 9...

output:

296076062

result:

ok 1 number(s): "296076062"

Test #20:

score: 0
Accepted
time: 605ms
memory: 4508kb

input:

11 42 215284372701527433
670445786006000260 969876209382224733 248721347029697734 375741447316879814 840434941395805804 187091598433077755 126574401069916039 764298539206353847 750906714570719526 387387869969339518 713140316419888823
1 10
2 5
1 7
4 11
3 11
2 7
4 5
9 5
1 6
3 4
10 9
11 9
3 7
2 1
8 11
...

output:

861118590

result:

ok 1 number(s): "861118590"

Test #21:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

7 20 619868500075052677
653541655679358091 619279335581334164 74945438024390700 772996180610853550 636253173293891586 125935970032544337 454311587629767538
7 3
4 5
6 7
2 7
4 2
5 3
4 6
2 6
7 4
5 7
2 5
6 3
5 1
2 3
3 4
1 7
2 1
1 3
5 6
4 1

output:

396474896

result:

ok 1 number(s): "396474896"

Test #22:

score: -50
Time Limit Exceeded

input:

13 1 655058659126783551
220930961455414900 363602338013759573 443737606888655227 137555247528320912 492558319379424931 930253239754276705 727679308735300884 787033056632957722 29595553176095069 586820353385061840 342786039873677428 141912073483259823 800159879032310691
4 9

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #47:

score: 0
Time Limit Exceeded

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:

100%
Accepted

Dependency #2:

0%