結果
| 問題 |
No.2927 Reverse Polish Equation
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2024-10-12 15:12:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 664 ms / 2,000 ms |
| コード長 | 692 bytes |
| コンパイル時間 | 276 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 199,188 KB |
| 最終ジャッジ日時 | 2024-10-16 00:22:15 |
| 合計ジャッジ時間 | 13,056 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
def Bisect_Int(ok,ng,is_ok):
while abs(ok-ng)>1:
mid=(ok+ng)//2
if is_ok(mid):
ok=mid
else:
ng=mid
return ok
Q,Y=map(int,input().split())
S=input().split()
def f(x):
queue=[]
for s in S:
if s=="+":
queue.append(queue.pop()+queue.pop())
elif s=="min":
queue.append(min(queue.pop(),queue.pop()))
elif s=="max":
queue.append(max(queue.pop(),queue.pop()))
elif s=="X":
queue.append(x)
else:
queue.append(int(s))
return queue[0]
def is_ok(x):
return f(x)>=Y
ans=Bisect_Int(1<<60,-1,is_ok)
if f(ans)!=Y:
ans=-1
print(ans)
vwxyz