結果
| 問題 | No.2927 Reverse Polish  Equation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-10-12 16:16:09 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 830 ms / 2,000 ms | 
| コード長 | 1,179 bytes | 
| コンパイル時間 | 296 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 119,208 KB | 
| 最終ジャッジ日時 | 2024-10-16 00:25:32 | 
| 合計ジャッジ時間 | 15,810 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
q,t = map(int,input().split())
s = list(input().split())
l,r = 0,10**18
for i in range(70):
    mid = (l+r)//2
    st = []
    for j in s:
        if j == '+':
            x = st.pop()
            y = st.pop()
            st.append(x+y)
        elif j == 'max':
            x = st.pop()
            y = st.pop()
            st.append(max(x,y))
        elif j == 'min':
            x = st.pop()
            y = st.pop()
            st.append(min(x,y))
        elif j == 'X':
            st.append(mid)
        else:
            st.append(int(j))
    if st[0] < t:
        l = mid
    else:
        r = mid
    #print(l,r,st[0])
    if i != 69:
        continue
    mid = r
    st = []
    for j in s:
        if j == '+':
            x = st.pop()
            y = st.pop()
            st.append(x+y)
        elif j == 'max':
            x = st.pop()
            y = st.pop()
            st.append(max(x,y))
        elif j == 'min':
            x = st.pop()
            y = st.pop()
            st.append(min(x,y))
        elif j == 'X':
            st.append(mid)
        else:
            st.append(int(j))
    if st[0] == t:
        print(r)
    else:
        print(-1)
        
            
            
            
        