結果
問題 | No.2927 Reverse Polish Equation |
ユーザー | loop0919 |
提出日時 | 2024-06-13 04:32:18 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 332 ms / 2,000 ms |
コード長 | 1,285 bytes |
コンパイル時間 | 3,906 ms |
コンパイル使用メモリ | 281,528 KB |
実行使用メモリ | 10,432 KB |
最終ジャッジ日時 | 2024-10-16 00:20:03 |
合計ジャッジ時間 | 10,414 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 3 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 4 ms
5,248 KB |
testcase_12 | AC | 99 ms
5,248 KB |
testcase_13 | AC | 169 ms
6,272 KB |
testcase_14 | AC | 116 ms
5,504 KB |
testcase_15 | AC | 163 ms
6,144 KB |
testcase_16 | AC | 54 ms
5,248 KB |
testcase_17 | AC | 213 ms
7,144 KB |
testcase_18 | AC | 264 ms
7,928 KB |
testcase_19 | AC | 18 ms
5,248 KB |
testcase_20 | AC | 213 ms
7,088 KB |
testcase_21 | AC | 332 ms
9,172 KB |
testcase_22 | AC | 32 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 287 ms
8,312 KB |
testcase_28 | AC | 238 ms
7,568 KB |
testcase_29 | AC | 32 ms
5,248 KB |
testcase_30 | AC | 275 ms
8,080 KB |
testcase_31 | AC | 20 ms
5,248 KB |
testcase_32 | AC | 62 ms
5,248 KB |
testcase_33 | AC | 117 ms
5,376 KB |
testcase_34 | AC | 145 ms
6,144 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 270 ms
8,124 KB |
testcase_37 | AC | 93 ms
5,248 KB |
testcase_38 | AC | 323 ms
8,992 KB |
testcase_39 | AC | 131 ms
5,632 KB |
testcase_40 | AC | 270 ms
8,064 KB |
testcase_41 | AC | 220 ms
6,964 KB |
testcase_42 | AC | 94 ms
10,240 KB |
testcase_43 | AC | 121 ms
10,240 KB |
testcase_44 | AC | 121 ms
10,432 KB |
testcase_45 | AC | 89 ms
9,648 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll Q, Y; cin >> Q >> Y; vector<string> S(Q); for (int i = 0; i < Q; i++) { cin >> S[i]; } auto rpn = [&](ll x) -> ll { stack<ll> A; for (string s: S) { if (s == "+" || s == "min" || s == "max") { ll a = A.top(); A.pop(); ll b = A.top(); A.pop(); if (s == "+") { A.push(a + b); } else if (s == "min") { A.push(min(a, b)); } else { A.push(max(a, b)); } } else { if (s == "X") { A.push(x); } else { A.push((ll)stoi(s)); } } } return A.top(); }; ll ok = (ll) 1e14; ll ng = -1LL; while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (rpn(mid) >= Y) { ok = mid; } else { ng = mid; } } if (rpn(ok) == Y) { cout << ok << endl; } else { cout << -1 << endl; } return 0; }