結果

問題 No.1741 Arrays and XOR Procedure
ユーザー wolgnikwolgnik
提出日時 2021-11-12 22:58:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 103,892 KB
最終ジャッジ日時 2024-05-04 10:37:46
合計ジャッジ時間 6,087 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,224 KB
testcase_01 AC 35 ms
51,840 KB
testcase_02 AC 35 ms
52,352 KB
testcase_03 AC 167 ms
103,680 KB
testcase_04 AC 36 ms
51,968 KB
testcase_05 AC 154 ms
103,296 KB
testcase_06 AC 166 ms
103,552 KB
testcase_07 AC 163 ms
103,892 KB
testcase_08 AC 147 ms
103,296 KB
testcase_09 AC 147 ms
100,116 KB
testcase_10 AC 137 ms
99,968 KB
testcase_11 AC 130 ms
94,604 KB
testcase_12 AC 117 ms
89,856 KB
testcase_13 AC 134 ms
100,096 KB
testcase_14 AC 116 ms
92,160 KB
testcase_15 AC 135 ms
97,152 KB
testcase_16 AC 67 ms
76,032 KB
testcase_17 AC 90 ms
82,784 KB
testcase_18 AC 127 ms
92,416 KB
testcase_19 AC 68 ms
76,160 KB
testcase_20 AC 163 ms
103,552 KB
testcase_21 AC 141 ms
97,280 KB
testcase_22 AC 120 ms
94,592 KB
testcase_23 AC 87 ms
81,920 KB
testcase_24 AC 76 ms
76,176 KB
testcase_25 AC 142 ms
103,424 KB
testcase_26 AC 98 ms
85,504 KB
testcase_27 AC 58 ms
74,368 KB
testcase_28 AC 124 ms
94,336 KB
testcase_29 AC 124 ms
97,280 KB
testcase_30 AC 128 ms
94,720 KB
testcase_31 AC 63 ms
76,032 KB
testcase_32 AC 96 ms
85,376 KB
testcase_33 AC 105 ms
88,360 KB
testcase_34 AC 79 ms
79,488 KB
testcase_35 AC 44 ms
61,440 KB
testcase_36 AC 71 ms
76,160 KB
testcase_37 AC 98 ms
85,120 KB
testcase_38 AC 154 ms
103,580 KB
testcase_39 AC 84 ms
83,712 KB
testcase_40 AC 51 ms
65,152 KB
testcase_41 AC 71 ms
78,852 KB
testcase_42 AC 59 ms
73,600 KB
testcase_43 AC 39 ms
52,352 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