結果
| 問題 | No.2927 Reverse Polish  Equation | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2024-06-12 23:12:54 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 633 ms / 2,000 ms | 
| コード長 | 728 bytes | 
| コンパイル時間 | 520 ms | 
| コンパイル使用メモリ | 82,784 KB | 
| 実行使用メモリ | 128,908 KB | 
| 最終ジャッジ日時 | 2024-10-16 00:19:46 | 
| 合計ジャッジ時間 | 15,126 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
Q, Y = map(int, input().split())
S = input().split()
def rev_poland(x):
    A = []
    for s in S:
        if s in ('+', 'min', 'max'):
            a = A.pop()
            b = A.pop()
            
            if s == '+':
                A.append(a + b)
            if s == 'min':
                A.append(min(a, b))
            if s == 'max':
                A.append(max(a, b))
        
        else:
            if s == 'X':
                A.append(x)
            else:
                A.append(int(s))
    
    return A[0]
ok, ng = 10**14, -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if rev_poland(mid) >= Y:
        ok = mid
    else:
        ng = mid
if rev_poland(ok) == Y:
    print(ok)
else:
    print(-1)
            
            
            
        