結果

問題 No.2927 Reverse Polish Equation
ユーザー flippergo
提出日時 2024-11-12 08:41:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 129,576 KB
最終ジャッジ日時 2024-11-12 08:41:36
合計ジャッジ時間 15,403 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Y = map(int,input().split())
S = list(input().split())
Op = ["+","min","max"]
def f(x):
    A = []
    for i in range(N):
        if S[i] not in Op:
            if S[i]=="X":
                A.append(x)
            else:
                A.append(int(S[i]))
        else:
            a = A.pop()
            b = A.pop()
            if S[i]=="+":
                A.append(a+b)
            elif S[i]=="min":
                A.append(min(a,b))
            else:
                A.append(max(a,b))
    return A[0]
low = -1
high = 10**13+10
while high-low>1:
    mid = (high+low)//2
    if f(mid)>=Y:
        high = mid
    else:
        low = mid
x = high
if f(x)==Y:
    print(x)
else:
    print(-1)
0