結果
| 問題 |
No.2927 Reverse Polish Equation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-14 17:48:36 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,507 bytes |
| コンパイル時間 | 1,540 ms |
| コンパイル使用メモリ | 127,388 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-16 00:33:53 |
| 合計ジャッジ時間 | 7,475 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 WA * 2 |
ソースコード
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#ifdef local
#include <C++/core/io/debug_print.hpp>
#else
#define dump(...) void(0);
#endif
#include <iostream>
#include <ranges>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
namespace man {
}
int main() {
std::cin.tie(nullptr) -> sync_with_stdio(false);
using namespace std::views;
int q;
int64_t y;
std::cin >> q >> y;
std::vector<std::string> s(q);
for(auto &t: s) {
std::cin >> t;
}
const auto f = [&s](const int64_t x) -> int64_t {
std::stack<int64_t> sk;
for(const auto &t: s) {
if(t == "+" || t == "min" || t == "max") {
const int64_t y = sk.top();
sk.pop();
const int64_t x = sk.top();
sk.pop();
if(t == "+") {
sk.emplace(x + y);
} else if(t == "min") {
sk.emplace(std::min(x, y));
} else {
sk.emplace(std::max(x, y));
}
} else {
sk.emplace(t == "X" ? x : std::stol(t));
}
}
return sk.top();
};
int64_t ok = (1L << 61) - 1, ng = -1;
while(std::abs(ok - ng) > 1) {
const auto x = (ok + ng) / 2;
(f(x) >= y ? ok : ng) = x;
}
std::cout << (f(ok) == y ? ok : -1) << '\n';
}