結果
| 問題 | No.2927 Reverse Polish  Equation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-12-25 17:24:15 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 647 ms / 2,000 ms | 
| コード長 | 1,240 bytes | 
| コンパイル時間 | 389 ms | 
| コンパイル使用メモリ | 81,792 KB | 
| 実行使用メモリ | 98,432 KB | 
| 最終ジャッジ日時 | 2024-12-25 17:24:34 | 
| 合計ジャッジ時間 | 14,741 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
import sys, math
sys.setrecursionlimit(10**7)
from itertools import *
from heapq import heapify, heappush, heappop
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from copy import copy, deepcopy
# from sortedcontainers import SortedSet, SortedList, SortedDict
INF, LINF, ipt = float('inf'), 1 << 60, sys.stdin.readline
iin, mii = lambda: int(ipt()), lambda: map(int, ipt().split())
lmi = lambda: list(map(int, ipt().split()))
Q, Y = mii()
s = input().split()
def solve(x):
    """f(x) >= Y"""
    st = deque()
    for i in range(Q):
        if s[i].isdigit():
            st.append(int(s[i]))
        elif s[i] == "X":
            st.append(x)
        elif s[i] == "+":
            a = st.pop()
            b = st.pop()
            st.append(a + b)
        elif s[i] == "min":
            a = st.pop()
            b = st.pop()
            st.append(min(a, b))
        elif s[i] == "max":
            a = st.pop()
            b = st.pop()
            st.append(max(a, b))
    
    return st.pop()
ok = 10**13 + 10
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if solve(mid) >= Y:
        ok = mid
    else:
        ng = mid
if solve(ok) == Y:
    print(ok)
else:
    print(-1)
            
            
            
        