結果
問題 | No.2927 Reverse Polish Equation |
ユーザー |
|
提出日時 | 2025-02-10 13:49:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 767 ms / 2,000 ms |
コード長 | 856 bytes |
コンパイル時間 | 382 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 125,888 KB |
最終ジャッジ日時 | 2025-02-10 13:49:55 |
合計ジャッジ時間 | 16,146 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
q,y=map(int,input().split())S=input().split()def f(n):E=["+", "min", "max"]stc=[]for i in S:if i in E:c=E.index(i)if c==0:a=stc.pop()b=stc.pop()stc.append(a+b)elif c==1:a = stc.pop()b = stc.pop()stc.append(min(a,b))else:a = stc.pop()b = stc.pop()stc.append(max(a, b))else:if i=="X":stc.append(n)else:stc.append(int(i))return stc[0]l,r=0,10**18if f(0)>y or f(r)<y:print(-1)exit()elif f(0)==y:print(0)exit()while r-l>1:c=(l+r)//2if f(c)>=y:r=celse:l=cif f(r)==y:print(r)else:print(-1)