結果

問題 No.2927 Reverse Polish Equation
コンテスト
ユーザー hato336
提出日時 2024-10-12 16:16:09
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 569 ms / 2,000 ms
+ 428µs
コード長 1,179 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 75 ms
コンパイル使用メモリ 81,152 KB
実行使用メモリ 128,196 KB
最終ジャッジ日時 2026-09-18 23:35:17
合計ジャッジ時間 12,722 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)

        
0