結果

問題 No.2927 Reverse Polish Equation
ユーザー ntudantuda
提出日時 2024-10-13 19:23:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 623 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 114,968 KB
最終ジャッジ日時 2024-10-16 00:31:43
合計ジャッジ時間 13,274 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 41 ms
51,456 KB
testcase_03 AC 40 ms
52,224 KB
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 40 ms
51,584 KB
testcase_06 AC 40 ms
51,712 KB
testcase_07 AC 68 ms
68,608 KB
testcase_08 AC 68 ms
67,712 KB
testcase_09 AC 74 ms
70,144 KB
testcase_10 AC 54 ms
62,848 KB
testcase_11 AC 75 ms
72,320 KB
testcase_12 AC 208 ms
81,536 KB
testcase_13 AC 332 ms
85,632 KB
testcase_14 AC 252 ms
82,304 KB
testcase_15 AC 278 ms
85,504 KB
testcase_16 AC 173 ms
78,464 KB
testcase_17 AC 388 ms
89,472 KB
testcase_18 AC 478 ms
92,800 KB
testcase_19 AC 126 ms
76,416 KB
testcase_20 AC 386 ms
89,092 KB
testcase_21 AC 507 ms
97,576 KB
testcase_22 AC 124 ms
76,544 KB
testcase_23 AC 40 ms
52,224 KB
testcase_24 AC 41 ms
51,968 KB
testcase_25 AC 41 ms
51,456 KB
testcase_26 AC 40 ms
51,584 KB
testcase_27 AC 474 ms
93,440 KB
testcase_28 AC 537 ms
91,008 KB
testcase_29 AC 157 ms
76,800 KB
testcase_30 AC 592 ms
92,928 KB
testcase_31 AC 116 ms
76,416 KB
testcase_32 AC 216 ms
78,932 KB
testcase_33 AC 315 ms
82,688 KB
testcase_34 AC 354 ms
84,352 KB
testcase_35 AC 66 ms
65,792 KB
testcase_36 AC 398 ms
93,440 KB
testcase_37 AC 251 ms
81,024 KB
testcase_38 AC 623 ms
95,744 KB
testcase_39 AC 330 ms
83,840 KB
testcase_40 AC 540 ms
92,928 KB
testcase_41 AC 496 ms
88,960 KB
testcase_42 AC 379 ms
112,052 KB
testcase_43 AC 429 ms
113,220 KB
testcase_44 AC 443 ms
113,476 KB
testcase_45 AC 376 ms
114,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q, Y = map(int,input().split())
S = input().split()
code = {"+":0,"min":1,"max":2}

def f(x):
    stack = []
    for s in S:
        if s.isdigit():
            stack.append(int(s))
        elif s == "X":
            stack.append(x)
        else:
            a = stack.pop()
            b = stack.pop()
            match code[s]:
                case 0:
                    stack.append(a + b)
                case 1:
                    stack.append(min(a,b))
                case 2:
                    stack.append(max(a,b))
        dum = 0
    return stack[0]

lb = -1
ub = Y
while ub - lb > 1:
    mid = (ub + lb) // 2
    if f(mid) >= Y:
        ub = mid
    else:
        lb = mid
if f(ub) == Y:
    print(ub)
else:
    print(-1)
0