結果

問題 No.1741 Arrays and XOR Procedure
ユーザー wolgnikwolgnik
提出日時 2021-11-12 22:58:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 577 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 104,788 KB
最終ジャッジ日時 2023-08-17 03:25:50
合計ジャッジ時間 8,389 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,320 KB
testcase_01 AC 73 ms
71,244 KB
testcase_02 AC 77 ms
71,336 KB
testcase_03 AC 206 ms
104,788 KB
testcase_04 AC 74 ms
71,096 KB
testcase_05 AC 200 ms
104,304 KB
testcase_06 AC 217 ms
104,420 KB
testcase_07 AC 217 ms
104,536 KB
testcase_08 AC 201 ms
104,320 KB
testcase_09 AC 193 ms
101,148 KB
testcase_10 AC 180 ms
101,144 KB
testcase_11 AC 175 ms
95,552 KB
testcase_12 AC 158 ms
91,316 KB
testcase_13 AC 174 ms
100,940 KB
testcase_14 AC 163 ms
93,224 KB
testcase_15 AC 184 ms
98,736 KB
testcase_16 AC 106 ms
77,260 KB
testcase_17 AC 125 ms
84,148 KB
testcase_18 AC 173 ms
93,648 KB
testcase_19 AC 103 ms
77,416 KB
testcase_20 AC 207 ms
104,088 KB
testcase_21 AC 175 ms
98,192 KB
testcase_22 AC 160 ms
95,608 KB
testcase_23 AC 125 ms
83,008 KB
testcase_24 AC 108 ms
77,716 KB
testcase_25 AC 185 ms
104,200 KB
testcase_26 AC 136 ms
86,376 KB
testcase_27 AC 98 ms
77,376 KB
testcase_28 AC 176 ms
96,004 KB
testcase_29 AC 171 ms
98,356 KB
testcase_30 AC 173 ms
95,992 KB
testcase_31 AC 108 ms
77,212 KB
testcase_32 AC 138 ms
86,700 KB
testcase_33 AC 145 ms
89,288 KB
testcase_34 AC 116 ms
80,852 KB
testcase_35 AC 82 ms
75,508 KB
testcase_36 AC 106 ms
77,436 KB
testcase_37 AC 138 ms
86,456 KB
testcase_38 AC 204 ms
104,208 KB
testcase_39 AC 120 ms
85,068 KB
testcase_40 AC 87 ms
76,260 KB
testcase_41 AC 110 ms
80,252 KB
testcase_42 AC 101 ms
77,344 KB
testcase_43 AC 73 ms
71,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 998244353

def combi(n, k):
  if n < k: return 0
  if n == k: return 1
  if n > k: return 1

def lucas(n, k):
  res = 1
  while n and k:
    if n & 1 < k & 1: res = 0
    elif n & 1 == 0: res &= 1
    else: res &= combi(n & 1, k & 1)
    n >>= 1
    k >>= 1
  return res
dp = [0] * 2
dp[0] = 1
for i in range(N):
  c = lucas(N - 1, i)
  #print(c)
  if a[i] == 1:
    if c: dp[0], dp[1] = dp[1], dp[0]
  if a[i] == -1:
    if c == 0: dp[0], dp[1] = dp[0] * 2 % mod, dp[1] * 2 % mod
    else: dp[0], dp[1] = (dp[0] + dp[1]) % mod, (dp[0] + dp[1]) % mod
print(dp[-1])
0