結果
問題 |
No.2927 Reverse Polish Equation
|
ユーザー |
|
提出日時 | 2024-10-12 17:16:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 772 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 129,768 KB |
最終ジャッジ日時 | 2024-10-16 00:30:01 |
合計ジャッジ時間 | 14,458 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 WA * 2 |
ソースコード
Q, Y = map(int, input().split()) S = list(map(str, input().split())) def solve(S, x): stack = [] for i in S: if i == "X" or (i != "max" and i != "min" and i != "+"): if i == "X": stack.append(x) else: stack.append(i) else: p = stack.pop() q = stack.pop() if i == "+": stack.append(int(p) + int(q)) else: if i == "max": stack.append(max(int(p), int(q))) else: stack.append(min(int(p), int(q))) return stack[-1] left = -1 right = 10 ** 14 while left + 1 < right: mid = (left + right) // 2 res = int(solve(S, mid)) if res == Y: right = mid elif res < Y: left = mid else: right = mid if solve(S, right) == Y: print(right) else: print(-1)