結果

問題 No.1741 Arrays and XOR Procedure
ユーザー 夜
提出日時 2021-11-14 12:51:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,687 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 99,948 KB
実行使用メモリ 10,568 KB
最終ジャッジ日時 2024-05-07 01:44:18
合計ジャッジ時間 4,306 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
9,924 KB
testcase_01 AC 16 ms
8,644 KB
testcase_02 AC 17 ms
9,412 KB
testcase_03 AC 55 ms
10,564 KB
testcase_04 AC 17 ms
9,160 KB
testcase_05 AC 47 ms
10,568 KB
testcase_06 AC 52 ms
10,464 KB
testcase_07 AC 52 ms
10,432 KB
testcase_08 AC 46 ms
10,560 KB
testcase_09 AC 48 ms
10,440 KB
testcase_10 AC 49 ms
10,436 KB
testcase_11 AC 40 ms
10,312 KB
testcase_12 AC 36 ms
10,184 KB
testcase_13 AC 46 ms
10,440 KB
testcase_14 AC 38 ms
10,052 KB
testcase_15 AC 44 ms
10,312 KB
testcase_16 AC 17 ms
9,928 KB
testcase_17 AC 27 ms
9,928 KB
testcase_18 AC 39 ms
10,180 KB
testcase_19 AC 18 ms
9,544 KB
testcase_20 AC 50 ms
10,440 KB
testcase_21 AC 42 ms
10,304 KB
testcase_22 AC 40 ms
10,308 KB
testcase_23 AC 25 ms
9,928 KB
testcase_24 AC 19 ms
9,804 KB
testcase_25 AC 50 ms
10,436 KB
testcase_26 AC 31 ms
9,796 KB
testcase_27 AC 18 ms
9,672 KB
testcase_28 AC 42 ms
10,308 KB
testcase_29 AC 44 ms
10,564 KB
testcase_30 AC 41 ms
10,432 KB
testcase_31 AC 18 ms
9,292 KB
testcase_32 AC 30 ms
9,540 KB
testcase_33 AC 33 ms
10,184 KB
testcase_34 AC 23 ms
10,052 KB
testcase_35 AC 16 ms
8,776 KB
testcase_36 AC 18 ms
9,676 KB
testcase_37 AC 29 ms
9,544 KB
testcase_38 AC 49 ms
10,440 KB
testcase_39 AC 28 ms
9,412 KB
testcase_40 AC 16 ms
9,796 KB
testcase_41 AC 23 ms
9,668 KB
testcase_42 AC 17 ms
10,048 KB
testcase_43 AC 16 ms
9,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
#include <fstream>
using namespace std;
long long fac[200020], finv[200020], inv[200020];
long long mod = 998244353;
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long a[200020];
int tco[200020];
vector<int> vec;
long long co = 0, co1 = 0;
int main() {
	COMinit();
	long long n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == -1) {
			co1++;
		}
	}
	for (int i = 1; i <= n; i++) {
		int co2 = 0, i1 = i;
		while (i1 % 2 == 0) {
			i1 /= 2;
			co2++;
		}
		tco[i] = co2;
	}
	int now = 0;
	vec.emplace_back(0);
	for (int i = 1; i < n; i++) {
		now += tco[n - i];
		now -= tco[i];
		if (now == 0) {
			vec.emplace_back(i);
		}
	}
	int x = 0;
	for (int i = 0; i < vec.size(); i++) {
		if (a[vec[i]] != -1) {
			x ^= a[vec[i]];
		}
		else {
			co++;
		}
	}
	long long ans = 0;
	if (x == 0) {
		for (int i = 1; i <= co; i += 2) {
			ans += COM(co, i);
			ans %= mod;
		}
	}
	else {
		for (int i = 0; i <= co; i += 2) {
			ans += COM(co, i);
			ans %= mod;
		}
	}
	for (int i = 0; i < co1 - co; i++) {
		ans *= 2;
		ans %= mod;
	}
	cout << ans << endl;
}
0