結果
| 問題 |
No.2927 Reverse Polish Equation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-12 16:56:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 633 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 82,444 KB |
| 実行使用メモリ | 325,300 KB |
| 最終ジャッジ日時 | 2024-10-16 00:28:31 |
| 合計ジャッジ時間 | 5,410 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 TLE * 1 -- * 33 |
ソースコード
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 ** 14
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)