結果

問題 No.2927 Reverse Polish Equation
コンテスト
ユーザー hato336
提出日時 2024-10-12 16:16:09
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 555 ms / 2,000 ms
コード長 1,179 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 459 ms
コンパイル使用メモリ 85,448 KB
実行使用メモリ 125,660 KB
最終ジャッジ日時 2026-05-05 13:00:26
合計ジャッジ時間 13,039 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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