QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303040#5827. 异或图Leasier0 1ms3524kbC++983.4kb2024-01-11 17:07:082024-01-11 17:07:09

Judging History

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

  • [2024-01-11 17:07:09]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3524kb
  • [2024-01-11 17:07:08]
  • 提交

answer

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int mod = 998244353;
int refer[17], edge[17], coef[17], 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 {
				if (pr[j].first >> i & 1){
					int way = (pr[j].first & ((1ll << i) - 1)) % mod;
					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 {
					int way = ((pr[j].first & ((1ll << i) - 1)) + 1) % mod;
					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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3524kb

input:

4 6 2
7 11 14 0
1 2
1 3
2 3
2 4
4 1
4 3

output:

113

result:

wrong answer 1st numbers differ - expected: '44', found: '113'

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%