結果
問題 | No.1741 Arrays and XOR Procedure |
ユーザー |
|
提出日時 | 2025-04-13 19:50:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 2,220 bytes |
コンパイル時間 | 649 ms |
コンパイル使用メモリ | 82,668 KB |
実行使用メモリ | 108,104 KB |
最終ジャッジ日時 | 2025-04-13 19:51:07 |
合計ジャッジ時間 | 6,888 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
## https://yukicoder.me/problems/no/1741 class CombinationCalculator: """ modを考慮したPermutation, Combinationを計算するためのクラス """ def __init__(self, size, mod): self.mod = mod self.factorial = [0] * (size + 1) self.factorial[0] = 1 for i in range(1, size + 1): self.factorial[i] = (i * self.factorial[i - 1]) % self.mod self.inv_factorial = [0] * (size + 1) self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod) for i in reversed(range(size)): self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod def calc_combination(self, n, r): if n < 0 or n < r or r < 0: return 0 if r == 0 or n == r: return 1 ans = self.inv_factorial[n - r] * self.inv_factorial[r] ans %= self.mod ans *= self.factorial[n] ans %= self.mod return ans def calc_permutation(self, n, r): if n < 0 or n < r: return 0 ans = self.inv_factorial[n - r] ans *= self.factorial[n] ans %= self.mod return ans MOD = 998244353 def main(): N = int(input()) B = list(map(int, input().split())) array = [0] * (N + 1) a = 2 while a <= N: b = a while b <= N: array[b] += 1 b += a a *= 2 c = 0 cum_array = [0] * (N + 1) for i in range(N + 1): c += array[i] cum_array[i] = c dp = [0] * 2 dp[0] = 1 for i in range(N): new_dp = [0] * 2 c = cum_array[N - 1] - cum_array[N - 1 - i] - cum_array[i] if c > 0: d = 0 else: d = 1 for k in range(2): if B[i] in (0, -1): k0 = k + d * 0 k0 %= 2 new_dp[k0] += dp[k] new_dp[k0] %= MOD if B[i] in (1, -1): k0 = k + d * 1 k0 %= 2 new_dp[k0] += dp[k] new_dp[k0] %= MOD dp = new_dp print(dp[1]) if __name__ == "__main__": main()