結果
問題 | No.1741 Arrays and XOR Procedure |
ユーザー | ks2m |
提出日時 | 2021-11-12 22:18:07 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,795 bytes |
コンパイル時間 | 2,456 ms |
コンパイル使用メモリ | 76,880 KB |
実行使用メモリ | 77,640 KB |
最終ジャッジ日時 | 2024-05-04 09:15:50 |
合計ジャッジ時間 | 11,557 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
50,580 KB |
testcase_01 | AC | 51 ms
50,500 KB |
testcase_02 | AC | 52 ms
50,212 KB |
testcase_03 | AC | 300 ms
77,640 KB |
testcase_04 | AC | 49 ms
37,416 KB |
testcase_05 | WA | - |
testcase_06 | AC | 297 ms
66,980 KB |
testcase_07 | AC | 291 ms
66,888 KB |
testcase_08 | AC | 280 ms
62,104 KB |
testcase_09 | AC | 263 ms
60,320 KB |
testcase_10 | AC | 269 ms
61,548 KB |
testcase_11 | AC | 232 ms
56,584 KB |
testcase_12 | AC | 200 ms
53,072 KB |
testcase_13 | AC | 271 ms
59,920 KB |
testcase_14 | AC | 215 ms
56,904 KB |
testcase_15 | AC | 255 ms
62,052 KB |
testcase_16 | AC | 94 ms
39,928 KB |
testcase_17 | AC | 155 ms
45,472 KB |
testcase_18 | AC | 216 ms
53,940 KB |
testcase_19 | AC | 88 ms
39,404 KB |
testcase_20 | AC | 273 ms
61,700 KB |
testcase_21 | AC | 261 ms
60,596 KB |
testcase_22 | AC | 229 ms
56,312 KB |
testcase_23 | AC | 142 ms
46,072 KB |
testcase_24 | AC | 94 ms
40,548 KB |
testcase_25 | AC | 274 ms
61,976 KB |
testcase_26 | AC | 180 ms
48,236 KB |
testcase_27 | AC | 78 ms
39,368 KB |
testcase_28 | AC | 236 ms
57,400 KB |
testcase_29 | AC | 269 ms
61,252 KB |
testcase_30 | AC | 239 ms
56,612 KB |
testcase_31 | WA | - |
testcase_32 | AC | 173 ms
48,364 KB |
testcase_33 | AC | 200 ms
53,460 KB |
testcase_34 | AC | 127 ms
45,596 KB |
testcase_35 | AC | 53 ms
37,364 KB |
testcase_36 | AC | 93 ms
41,332 KB |
testcase_37 | AC | 187 ms
47,112 KB |
testcase_38 | AC | 274 ms
61,260 KB |
testcase_39 | AC | 161 ms
48,208 KB |
testcase_40 | AC | 55 ms
37,488 KB |
testcase_41 | AC | 125 ms
45,288 KB |
testcase_42 | AC | 79 ms
39,896 KB |
testcase_43 | AC | 53 ms
37,288 KB |
ソースコード
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 == 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; } } }