結果
問題 | No.2872 Depth of the Parentheses |
ユーザー | timi |
提出日時 | 2024-09-06 22:15:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 868 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 81,964 KB |
実行使用メモリ | 54,276 KB |
最終ジャッジ日時 | 2024-09-06 22:15:25 |
合計ジャッジ時間 | 2,005 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 5 |
ソースコード
S,N=map(int,input().split()) # A=list(map(int, input().split())) if N>10: exit() mod=998244353 D={} D[(0,0)]=1 def xgcd(a, b): x0, y0, x1, y1 = 1, 0, 0, 1 while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return a, x0, y0 def modinv(a, m): g, x, y = xgcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m gt=modinv(100,mod) s=S*gt%mod t=(100-S)*gt%mod for i in range(2*N): E={} for x,y in D: d=D[(x,y)] if x!=0: xx=x-1 if (xx,y) not in E: E[(xx,y)]=0 E[(xx,y)]+=d*t E[(xx,y)]%=mod xx=x+1 y=max(xx,y) if (xx,y) not in E: E[(xx,y)]=0 E[(xx,y)]+=d*s E[(xx,y)]%=mod D=E ans=0 for x,y in D: if x==0: ans+=y*D[(x,y)] ans%=mod print(ans)