結果
問題 |
No.1741 Arrays and XOR Procedure
|
ユーザー |
![]() |
提出日時 | 2021-10-16 13:18:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 529 ms / 2,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 104,660 KB |
最終ジャッジ日時 | 2024-11-25 10:59:48 |
合計ジャッジ時間 | 13,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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())) if 1<=n<=200000 and min(b)>=-1 and max(b)<=1: pass else: raise Exception 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])