結果

問題 No.2927 Reverse Polish Equation
ユーザー Basin-BugBasin-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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
57,600 KB
testcase_01 AC 43 ms
52,992 KB
testcase_02 AC 43 ms
52,608 KB
testcase_03 AC 47 ms
52,352 KB
testcase_04 AC 42 ms
52,736 KB
testcase_05 AC 45 ms
52,736 KB
testcase_06 AC 43 ms
52,864 KB
testcase_07 AC 152 ms
73,472 KB
testcase_08 AC 153 ms
77,184 KB
testcase_09 AC 171 ms
72,960 KB
testcase_10 AC 63 ms
62,592 KB
testcase_11 AC 215 ms
80,384 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

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