結果
問題 | No.2927 Reverse Polish Equation |
ユーザー | hanage |
提出日時 | 2024-10-12 15:57:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,468 bytes |
コンパイル時間 | 1,995 ms |
コンパイル使用メモリ | 207,976 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-10-16 00:24:27 |
合計ジャッジ時間 | 11,155 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 4 ms
5,248 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 4 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 6 ms
5,248 KB |
testcase_12 | AC | 165 ms
5,248 KB |
testcase_13 | AC | 277 ms
6,272 KB |
testcase_14 | AC | 196 ms
5,376 KB |
testcase_15 | AC | 263 ms
6,144 KB |
testcase_16 | AC | 87 ms
5,248 KB |
testcase_17 | AC | 359 ms
7,040 KB |
testcase_18 | AC | 438 ms
8,064 KB |
testcase_19 | AC | 29 ms
5,248 KB |
testcase_20 | AC | 346 ms
7,168 KB |
testcase_21 | AC | 535 ms
9,088 KB |
testcase_22 | AC | 52 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 | 479 ms
8,320 KB |
testcase_28 | AC | 406 ms
7,552 KB |
testcase_29 | AC | 52 ms
5,248 KB |
testcase_30 | AC | 451 ms
8,064 KB |
testcase_31 | AC | 33 ms
5,248 KB |
testcase_32 | AC | 100 ms
5,248 KB |
testcase_33 | AC | 192 ms
5,248 KB |
testcase_34 | AC | 250 ms
5,888 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 452 ms
8,192 KB |
testcase_37 | AC | 161 ms
5,248 KB |
testcase_38 | AC | 542 ms
8,960 KB |
testcase_39 | AC | 214 ms
5,504 KB |
testcase_40 | AC | 439 ms
8,064 KB |
testcase_41 | AC | 362 ms
7,168 KB |
testcase_42 | WA | - |
testcase_43 | AC | 274 ms
10,240 KB |
testcase_44 | AC | 330 ms
10,240 KB |
testcase_45 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int Q; long long Y; cin >> Q >> Y; vector<string> s(Q); for (int i = 0; i < Q; i++) { cin >> s[i]; } long long le = 0, ri = 1e18; long long ans = ri; while (le <= ri) { long long mid = le + (ri - le) / 2; stack<long long> st; for (int i = 0; i < Q; i++) { if (s[i] == "X") { st.push(mid); } else if (s[i] == "+") { long long t1 = st.top(); st.pop(); long long t2 = st.top(); st.pop(); st.push(t1 + t2); } else if (s[i] == "min") { long long t1 = st.top(); st.pop(); long long t2 = st.top(); st.pop(); st.push(min(t1, t2)); } else if (s[i] == "max") { long long t1 = st.top(); st.pop(); long long t2 = st.top(); st.pop(); st.push(max(t1, t2)); } else { st.push(stoll(s[i])); } } long long f = st.top(); // cout << mid << " " << f << endl; if (f >= Y) { if (f == Y) ans = min(ans, mid); ri = mid - 1; } else if (f < Y) { le = mid + 1; } } if (ans == 1e18) ans = -1; cout << ans << endl; return 0; }