結果

問題 No.1741 Arrays and XOR Procedure
ユーザー ks2mks2m
提出日時 2021-11-12 22:21:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 2,799 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 74,984 KB
実行使用メモリ 79,408 KB
最終ジャッジ日時 2023-08-17 02:08:42
合計ジャッジ時間 12,292 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,652 KB
testcase_01 AC 46 ms
47,772 KB
testcase_02 AC 44 ms
49,668 KB
testcase_03 AC 318 ms
79,408 KB
testcase_04 AC 44 ms
49,924 KB
testcase_05 AC 280 ms
79,152 KB
testcase_06 AC 314 ms
78,888 KB
testcase_07 AC 311 ms
78,448 KB
testcase_08 AC 295 ms
79,096 KB
testcase_09 AC 267 ms
64,668 KB
testcase_10 AC 273 ms
64,332 KB
testcase_11 AC 240 ms
66,364 KB
testcase_12 AC 210 ms
62,620 KB
testcase_13 AC 266 ms
66,544 KB
testcase_14 AC 232 ms
66,620 KB
testcase_15 AC 263 ms
67,228 KB
testcase_16 AC 90 ms
52,556 KB
testcase_17 AC 163 ms
58,656 KB
testcase_18 AC 237 ms
66,216 KB
testcase_19 AC 87 ms
50,548 KB
testcase_20 AC 294 ms
76,948 KB
testcase_21 AC 257 ms
70,384 KB
testcase_22 AC 239 ms
66,364 KB
testcase_23 AC 152 ms
57,136 KB
testcase_24 AC 93 ms
52,640 KB
testcase_25 AC 294 ms
76,808 KB
testcase_26 AC 183 ms
58,984 KB
testcase_27 AC 92 ms
52,572 KB
testcase_28 AC 247 ms
67,120 KB
testcase_29 AC 263 ms
65,492 KB
testcase_30 AC 248 ms
67,560 KB
testcase_31 AC 78 ms
52,004 KB
testcase_32 AC 180 ms
58,724 KB
testcase_33 AC 202 ms
63,908 KB
testcase_34 AC 121 ms
56,912 KB
testcase_35 AC 53 ms
50,440 KB
testcase_36 AC 89 ms
54,720 KB
testcase_37 AC 181 ms
58,800 KB
testcase_38 AC 282 ms
65,912 KB
testcase_39 AC 178 ms
60,744 KB
testcase_40 AC 57 ms
51,600 KB
testcase_41 AC 115 ms
57,068 KB
testcase_42 AC 75 ms
51,612 KB
testcase_43 AC 44 ms
49,528 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