結果

問題 No.2927 Reverse Polish Equation
ユーザー Basin-Bug
提出日時 2024-10-12 16:56:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 636 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 323,020 KB
最終ジャッジ日時 2024-10-16 00:28:34
合計ジャッジ時間 5,157 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 TLE * 1 -- * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

Q, Y = map(int, input().split())
S = list(map(str, input().split()))

stack = []
for i in S:
  if i == "X" or (i != "max" and i != "min" and i != "+"):
    stack.append(i)
  else:
    p = stack.pop()
    q = stack.pop()
    if i == "+":
      stack.append(p + i + q)
    else:
      stack.append(i + "(" + p + "," + q + ")")

que = stack[-1]
left = -1
right = 10 ** 9 + 1
while left + 1 < right:
  mid = (left + right) // 2
  que2 = que.replace("X", str(mid))
  if eval(que2) == Y:
    right = mid
  elif eval(que2) < Y:
    left = mid
  else:
    right = mid
if eval(que.replace("X", str(right))) == Y:
  print(right)
else:
  print(-1)
0