結果

問題 No.1741 Arrays and XOR Procedure
ユーザー ks2mks2m
提出日時 2021-11-12 22:21:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 2,799 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 77,072 KB
実行使用メモリ 67,908 KB
最終ジャッジ日時 2024-05-04 09:22:10
合計ジャッジ時間 11,586 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
37,308 KB
testcase_01 AC 49 ms
37,284 KB
testcase_02 AC 48 ms
36,832 KB
testcase_03 AC 315 ms
67,908 KB
testcase_04 AC 49 ms
37,208 KB
testcase_05 AC 269 ms
61,948 KB
testcase_06 AC 314 ms
66,840 KB
testcase_07 AC 307 ms
66,408 KB
testcase_08 AC 285 ms
61,604 KB
testcase_09 AC 267 ms
60,244 KB
testcase_10 AC 291 ms
60,948 KB
testcase_11 AC 237 ms
56,852 KB
testcase_12 AC 199 ms
52,888 KB
testcase_13 AC 264 ms
59,628 KB
testcase_14 AC 223 ms
56,764 KB
testcase_15 AC 267 ms
61,624 KB
testcase_16 AC 77 ms
40,080 KB
testcase_17 AC 149 ms
45,856 KB
testcase_18 AC 230 ms
53,888 KB
testcase_19 AC 86 ms
39,240 KB
testcase_20 AC 282 ms
61,856 KB
testcase_21 AC 250 ms
60,164 KB
testcase_22 AC 234 ms
56,428 KB
testcase_23 AC 148 ms
45,800 KB
testcase_24 AC 92 ms
40,272 KB
testcase_25 AC 270 ms
60,984 KB
testcase_26 AC 172 ms
46,644 KB
testcase_27 AC 87 ms
39,768 KB
testcase_28 AC 247 ms
56,736 KB
testcase_29 AC 260 ms
61,124 KB
testcase_30 AC 233 ms
56,940 KB
testcase_31 AC 79 ms
39,720 KB
testcase_32 AC 180 ms
46,908 KB
testcase_33 AC 181 ms
52,012 KB
testcase_34 AC 134 ms
45,360 KB
testcase_35 AC 51 ms
37,464 KB
testcase_36 AC 105 ms
40,736 KB
testcase_37 AC 174 ms
46,628 KB
testcase_38 AC 280 ms
60,264 KB
testcase_39 AC 166 ms
47,884 KB
testcase_40 AC 50 ms
37,376 KB
testcase_41 AC 112 ms
45,412 KB
testcase_42 AC 78 ms
39,516 KB
testcase_43 AC 46 ms
36,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 998244353;
		Kaijou kai = new Kaijou(n, mod);
		Kaijou2 kai2 = new Kaijou2(n, 2);

		int n1 = n - 1;
		int a = 0;
		int x = 0;
		int y = 0;
		for (int i = 0; i < n; i++) {
			long v = kai2.comb(n1, i);
			if (v % 2 == 1) {
				if (b[i] == 1) {
					a++;
				} else if (b[i] == -1) {
					x++;
				}
			}
			if (b[i] == -1) {
				y++;
			}
		}

		long ans = 0;
		if (a % 2 == 0) {
			for (int i = 1; i <= x; i += 2) {
				ans += kai.comb(x, i);
			}
		} else {
			for (int i = 0; i <= x; i += 2) {
				ans += kai.comb(x, i);
			}
		}
		ans %= mod;
		ans *= power(2, y - x, mod);
		ans %= mod;
		System.out.println(ans);
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			val = val * x % m;
		}
		return val;
	}

	static class Kaijou {
		long[] p, pi;
		int m;

		public Kaijou(int n, int mod) {
			n++;
			m = mod;
			p = new long[n];
			pi = new long[n];
			p[0] = 1;
			pi[0] = 1;
			for (int i = 1; i < n; i++) {
				p[i] = p[i - 1] * i % m;
			}
			pi[n - 1] = BigInteger.valueOf(p[n - 1])
					.modInverse(BigInteger.valueOf(m)).longValue();
			for (int i = n - 1; i > 1; i--) {
				pi[i - 1] = pi[i] * i % m;
			}
		}

		public long comb(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[r] % m * pi[n - r] % m;
		}

		public long perm(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[n - r] % m;
		}
	}

	static class Kaijou2 {
		long[] p, pi;
		int[] im, cm;
		int m;

		public Kaijou2(int n, int mod) {
			n++;
			m = mod;
			p = new long[n];
			pi = new long[n];
			im = new int[n];
			cm = new int[n];
			p[0] = 1;
			pi[0] = 1;
			for (int i = 1; i < n; i++) {
				int i2 = i;
				while (i2 % m == 0) {
					cm[i]++;
					i2 /= m;
				}
				p[i] = p[i - 1] * i2 % m;
				im[i] = i2;
				cm[i] += cm[i - 1];
			}
			pi[n - 1] = BigInteger.valueOf(p[n - 1])
					.modInverse(BigInteger.valueOf(m)).longValue();
			for (int i = n - 1; i > 1; i--) {
				pi[i - 1] = pi[i] * im[i] % m;
			}
		}

		public long comb(int n, int r) {
			if (n < r) return 0;
			if (cm[n] > cm[r] + cm[n - r]) {
				return 0;
			}
			return p[n] * pi[r] % m * pi[n - r] % m;
		}

		public long perm(int n, int r) {
			if (n < r) return 0;
			if (cm[n] > cm[n - r]) {
				return 0;
			}
			return p[n] * pi[n - r] % m;
		}
	}
}
0