結果
| 問題 |
No.2927 Reverse Polish Equation
|
| コンテスト | |
| ユーザー |
はるお味
|
| 提出日時 | 2024-10-14 20:13:52 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,409 bytes |
| コンパイル時間 | 3,315 ms |
| コンパイル使用メモリ | 249,388 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-16 00:34:10 |
| 合計ジャッジ時間 | 7,021 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 RE * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<VL> VVL;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
int A[200000],q;
int g(string s){
int n=s.size();
int a=0;
rep(i,n){
a=a*10+s[i]-'0';
}return a;
}
LL f(LL x){
VL B;
rep(i,q){
/*if(x==0){cout<<'!';
for(int it : B){cout<<it<<' ';}
}cout<<endl;
*/
int m=B.size();
if(A[i]==-10){B.pb(x);}
if(A[i]>0){B.pb(A[i]);}
if(A[i]==-1){
B[m-2]+=B[m-1];B.pop_back();
}
if(A[i]==-2){
B[m-2]=max(B[m-2],B[m-1]);B.pop_back();
}
if(A[i]==-3){
B[m-2]=min(B[m-2],B[m-1]);B.pop_back();
}
}
return B[0];
}
int main() {
cin>>q;
LL y;cin>>y;
int m=0;
rep(i,q){
string s;cin>>s;
//cout<<s<<endl;
if(s=="+"){A[i]=-1;}
else if(s=="max"){A[i]=-2;}
else if(s=="min"){A[i]=-3;}
else if(s=="X"){A[i]=-10;}
else{A[i]=g(s);}
}
//cout<<f(0)<<endl;
if(f(2*y)<y){cout<<-1<<endl; return 0;}
if(f(0)==y){cout<<0<<endl; return 0;}
LL l=0,r=2*y,t;
while(r-l>1){
t=(r+l)/2;
if(f(t)>=y){r=t;}
else{l=t;}
}
//cout<<f(0)<<endl;
if(f(r)!=y){r=-1;}
cout<<r<<endl;
}
はるお味