結果
問題 | No.2927 Reverse Polish Equation |
ユーザー |
|
提出日時 | 2024-10-14 15:10:23 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 391 ms / 2,000 ms |
コード長 | 617 bytes |
コンパイル時間 | 1,995 ms |
コンパイル使用メモリ | 208,620 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-10-16 00:32:23 |
合計ジャッジ時間 | 9,252 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using LL=__int128_t; vector<string> S; ll N,Y; LL y,z; LL f(ll x){ stack<LL> P; for(auto s:S){ if(s=="X")P.push(x); else if(isdigit(s[0]))P.push(stoll(s)); else{ y=P.top(); P.pop(); z=P.top(); P.pop(); P.push(s=="+"?y+z:s=="min"?min(y,z):max(y,z)); } } return P.top(); } int main() { cin>>N>>Y; S.resize(N); for(auto &s:S)cin>>s; ll L=-1,R=Y+1; while(R-L>1)(f((R+L)/2)>=LL(Y)?R:L)=(R+L)/2; cout<<(f(R)==LL(Y)?R:-1)<<endl; }