結果

問題 No.2927 Reverse Polish Equation
ユーザー loop0919loop0919
提出日時 2024-06-12 23:58:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,063 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 132,300 KB
最終ジャッジ日時 2024-10-16 00:19:52
合計ジャッジ時間 19,283 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,712 KB
testcase_01 AC 40 ms
52,352 KB
testcase_02 AC 39 ms
51,712 KB
testcase_03 AC 38 ms
51,840 KB
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 41 ms
52,352 KB
testcase_06 AC 39 ms
52,096 KB
testcase_07 AC 66 ms
67,840 KB
testcase_08 AC 65 ms
66,944 KB
testcase_09 AC 67 ms
67,840 KB
testcase_10 AC 58 ms
63,872 KB
testcase_11 AC 67 ms
68,992 KB
testcase_12 AC 348 ms
81,792 KB
testcase_13 AC 564 ms
87,040 KB
testcase_14 AC 412 ms
83,328 KB
testcase_15 AC 564 ms
87,424 KB
testcase_16 AC 225 ms
78,336 KB
testcase_17 AC 705 ms
90,752 KB
testcase_18 AC 742 ms
95,232 KB
testcase_19 AC 117 ms
75,776 KB
testcase_20 AC 714 ms
90,496 KB
testcase_21 AC 1,063 ms
100,224 KB
testcase_22 AC 170 ms
76,416 KB
testcase_23 AC 40 ms
52,352 KB
testcase_24 AC 40 ms
51,712 KB
testcase_25 AC 39 ms
51,840 KB
testcase_26 AC 38 ms
52,096 KB
testcase_27 AC 655 ms
95,872 KB
testcase_28 AC 771 ms
92,672 KB
testcase_29 AC 161 ms
76,416 KB
testcase_30 AC 877 ms
94,976 KB
testcase_31 AC 99 ms
75,776 KB
testcase_32 AC 256 ms
78,976 KB
testcase_33 AC 434 ms
83,072 KB
testcase_34 AC 511 ms
85,504 KB
testcase_35 AC 61 ms
65,280 KB
testcase_36 AC 487 ms
94,976 KB
testcase_37 AC 338 ms
81,152 KB
testcase_38 AC 1,063 ms
97,920 KB
testcase_39 AC 451 ms
84,608 KB
testcase_40 AC 911 ms
94,848 KB
testcase_41 AC 738 ms
90,752 KB
testcase_42 AC 485 ms
131,236 KB
testcase_43 AC 632 ms
118,868 KB
testcase_44 AC 677 ms
118,904 KB
testcase_45 AC 511 ms
132,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Generated by ChatGPT-4o

def evaluate_rpn(expression, x):
    stack = []
    for token in expression:
        if token == 'X':
            stack.append(x)
        elif token.isdigit():
            stack.append(int(token))
        else:
            b = stack.pop()
            a = stack.pop()
            if token == '+':
                stack.append(a + b)
            elif token == 'min':
                stack.append(min(a, b))
            elif token == 'max':
                stack.append(max(a, b))
    return stack[0]

def find_min_x(Q, Y, S):
    left, right = 0, 10**14
    result = -1
    
    while left <= right:
        mid = (left + right) // 2
        if evaluate_rpn(S, mid) == Y:
            result = mid
            right = mid - 1
        elif evaluate_rpn(S, mid) < Y:
            left = mid + 1
        else:
            right = mid - 1
            
    return result

if __name__ == "__main__":
    import sys
    input = sys.stdin.read
    data = input().split()
    
    Q = int(data[0])
    Y = int(data[1])
    S = data[2:]
    
    result = find_min_x(Q, Y, S)
    print(result)
0