結果

問題 No.1741 Arrays and XOR Procedure
ユーザー 夜
提出日時 2021-11-14 12:51:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,687 bytes
コンパイル時間 971 ms
コンパイル使用メモリ 98,212 KB
実行使用メモリ 10,544 KB
最終ジャッジ日時 2023-08-19 18:48:31
合計ジャッジ時間 4,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,276 KB
testcase_01 AC 15 ms
8,344 KB
testcase_02 AC 15 ms
8,272 KB
testcase_03 AC 53 ms
10,456 KB
testcase_04 AC 15 ms
8,332 KB
testcase_05 AC 44 ms
10,464 KB
testcase_06 AC 50 ms
10,428 KB
testcase_07 AC 50 ms
10,316 KB
testcase_08 AC 44 ms
10,532 KB
testcase_09 AC 44 ms
10,396 KB
testcase_10 AC 45 ms
10,352 KB
testcase_11 AC 39 ms
10,156 KB
testcase_12 AC 34 ms
9,828 KB
testcase_13 AC 44 ms
10,280 KB
testcase_14 AC 36 ms
9,748 KB
testcase_15 AC 42 ms
10,244 KB
testcase_16 AC 17 ms
8,380 KB
testcase_17 AC 25 ms
9,076 KB
testcase_18 AC 37 ms
9,792 KB
testcase_19 AC 16 ms
8,428 KB
testcase_20 AC 48 ms
10,460 KB
testcase_21 AC 41 ms
10,120 KB
testcase_22 AC 38 ms
9,924 KB
testcase_23 AC 24 ms
8,984 KB
testcase_24 AC 17 ms
8,424 KB
testcase_25 AC 47 ms
10,544 KB
testcase_26 AC 29 ms
9,208 KB
testcase_27 AC 16 ms
8,444 KB
testcase_28 AC 39 ms
10,060 KB
testcase_29 AC 42 ms
10,172 KB
testcase_30 AC 40 ms
10,132 KB
testcase_31 AC 17 ms
8,372 KB
testcase_32 AC 29 ms
9,324 KB
testcase_33 AC 32 ms
9,620 KB
testcase_34 AC 22 ms
8,716 KB
testcase_35 AC 16 ms
8,560 KB
testcase_36 AC 18 ms
8,580 KB
testcase_37 AC 28 ms
9,332 KB
testcase_38 AC 47 ms
10,384 KB
testcase_39 AC 27 ms
9,320 KB
testcase_40 AC 15 ms
8,308 KB
testcase_41 AC 21 ms
8,884 KB
testcase_42 AC 16 ms
8,456 KB
testcase_43 AC 15 ms
8,364 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