結果
| 問題 |
No.1741 Arrays and XOR Procedure
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2021-10-16 13:16:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 515 ms / 2,000 ms |
| コード長 | 716 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 82,320 KB |
| 実行使用メモリ | 104,380 KB |
| 最終ジャッジ日時 | 2024-11-25 10:59:22 |
| 合計ジャッジ時間 | 13,150 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
def base10int(n,base):
x=[]
while n!=0:
x.append(n%base)
n//=base
return x[::-1]
def comb(n,r):
if r>n:
return 0
tmp1=1
tmp2=1
for i in range(r):
tmp1*=n-i
tmp2*=i+1
return tmp1//tmp2
def lucas(n,k,p):
# nCk mod p を求める
np=base10int(n,p)
kp=base10int(k,p)
kp=[0]*(len(np)-len(kp))+kp
tmp=1
for ni,ki in zip(np,kp):
tmp*=comb(ni,ki)
tmp%=p
return tmp
n=int(input())
b=list(map(int,input().split()))
mod=998244353
dp=[1,0]
for i in range(n):
m=lucas(n-1,i,2)
if b[i]==0:
pass
if b[i]==1:
if m==1:
dp=[dp[1],dp[0]]
if b[i]==-1:
if m==0:
dp=[2*dp[0]%mod,2*dp[1]%mod]
else:
dp=[(dp[0]+dp[1])%mod]*2
print(dp[1])
とりゐ