結果
問題 | No.2927 Reverse Polish Equation |
ユーザー | loop0919 |
提出日時 | 2024-07-17 00:22:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 644 ms / 2,000 ms |
コード長 | 799 bytes |
コンパイル時間 | 298 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 128,848 KB |
最終ジャッジ日時 | 2024-10-16 00:20:21 |
合計ジャッジ時間 | 14,364 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,096 KB |
testcase_01 | AC | 44 ms
56,448 KB |
testcase_02 | AC | 44 ms
56,704 KB |
testcase_03 | AC | 43 ms
56,576 KB |
testcase_04 | AC | 46 ms
57,088 KB |
testcase_05 | AC | 44 ms
57,088 KB |
testcase_06 | AC | 45 ms
57,216 KB |
testcase_07 | AC | 100 ms
75,904 KB |
testcase_08 | AC | 80 ms
70,784 KB |
testcase_09 | AC | 98 ms
75,776 KB |
testcase_10 | AC | 72 ms
68,224 KB |
testcase_11 | AC | 99 ms
76,032 KB |
testcase_12 | AC | 270 ms
81,664 KB |
testcase_13 | AC | 375 ms
86,400 KB |
testcase_14 | AC | 298 ms
82,560 KB |
testcase_15 | AC | 376 ms
85,632 KB |
testcase_16 | AC | 196 ms
78,080 KB |
testcase_17 | AC | 465 ms
88,960 KB |
testcase_18 | AC | 540 ms
92,800 KB |
testcase_19 | AC | 144 ms
76,476 KB |
testcase_20 | AC | 460 ms
89,216 KB |
testcase_21 | AC | 644 ms
97,792 KB |
testcase_22 | AC | 163 ms
76,928 KB |
testcase_23 | AC | 41 ms
51,968 KB |
testcase_24 | AC | 43 ms
52,096 KB |
testcase_25 | AC | 42 ms
51,968 KB |
testcase_26 | AC | 46 ms
56,704 KB |
testcase_27 | AC | 568 ms
93,312 KB |
testcase_28 | AC | 483 ms
90,624 KB |
testcase_29 | AC | 165 ms
76,672 KB |
testcase_30 | AC | 546 ms
92,800 KB |
testcase_31 | AC | 125 ms
76,160 KB |
testcase_32 | AC | 209 ms
78,464 KB |
testcase_33 | AC | 296 ms
82,560 KB |
testcase_34 | AC | 348 ms
84,352 KB |
testcase_35 | AC | 72 ms
66,688 KB |
testcase_36 | AC | 528 ms
93,184 KB |
testcase_37 | AC | 234 ms
81,280 KB |
testcase_38 | AC | 615 ms
95,616 KB |
testcase_39 | AC | 317 ms
83,456 KB |
testcase_40 | AC | 519 ms
92,672 KB |
testcase_41 | AC | 476 ms
88,960 KB |
testcase_42 | AC | 437 ms
124,256 KB |
testcase_43 | AC | 499 ms
125,828 KB |
testcase_44 | AC | 532 ms
125,580 KB |
testcase_45 | AC | 418 ms
128,848 KB |
ソースコード
Q, Y = map(int, input().split()) S = input().split() assert 1 <= Q <= 2 * 10**5 assert 0 <= Y <= 10**14 assert len(S) == Q def rev_poland(x): A = [] for s in S: if s in ('+', 'min', 'max'): a = A.pop() b = A.pop() if s == '+': A.append(a + b) if s == 'min': A.append(min(a, b)) if s == 'max': A.append(max(a, b)) else: if s == 'X': A.append(x) else: A.append(int(s)) return A[0] ok, ng = 10**14, -1 while ok - ng > 1: mid = (ok + ng) // 2 if rev_poland(mid) >= Y: ok = mid else: ng = mid if rev_poland(ok) == Y: print(ok) else: print(-1)