結果

問題 No.2927 Reverse Polish Equation
ユーザー yonihayoniha
提出日時 2024-10-12 16:47:26
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 1,998 bytes
コンパイル時間 6,334 ms
コンパイル使用メモリ 336,452 KB
実行使用メモリ 13,244 KB
最終ジャッジ日時 2024-10-16 00:27:27
合計ジャッジ時間 13,170 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 4 ms
5,248 KB
testcase_12 AC 100 ms
5,248 KB
testcase_13 AC 170 ms
6,272 KB
testcase_14 AC 119 ms
5,376 KB
testcase_15 AC 153 ms
6,144 KB
testcase_16 AC 54 ms
5,248 KB
testcase_17 AC 217 ms
7,168 KB
testcase_18 AC 249 ms
8,192 KB
testcase_19 AC 18 ms
5,248 KB
testcase_20 AC 200 ms
7,168 KB
testcase_21 AC 306 ms
9,216 KB
testcase_22 AC 30 ms
5,248 KB
testcase_23 AC 1 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 267 ms
8,320 KB
testcase_28 AC 226 ms
7,552 KB
testcase_29 AC 29 ms
5,248 KB
testcase_30 AC 250 ms
8,192 KB
testcase_31 AC 19 ms
5,248 KB
testcase_32 AC 57 ms
5,248 KB
testcase_33 AC 111 ms
5,248 KB
testcase_34 AC 138 ms
6,144 KB
testcase_35 AC 2 ms
5,248 KB
testcase_36 AC 257 ms
8,192 KB
testcase_37 AC 85 ms
5,248 KB
testcase_38 AC 290 ms
9,216 KB
testcase_39 AC 118 ms
5,632 KB
testcase_40 AC 251 ms
8,064 KB
testcase_41 AC 203 ms
7,168 KB
testcase_42 AC 176 ms
13,244 KB
testcase_43 AC 192 ms
13,108 KB
testcase_44 AC 185 ms
13,108 KB
testcase_45 AC 173 ms
12,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n - 1); i >= 0; i--)
template <typename T> bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template <typename T> bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
// using mint = modint!!!number!!!;

signed main(){
  int q, y; cin >> q >> y;
  vs s(q); rep(i, q) cin >> s.at(i);
  __int128_t ok = 1ll << 60, ng = -1;
  while(ok - ng > 1){
  	__int128_t mid = (ok + ng) / 2;
  	vector<__int128_t> a; int n = 0;
  	rep(i, q){
  		if(s.at(i) == "X"){
  			a.push_back(mid);
  			n++;
  		}
  		else if(s.at(i) == "+"){
  			a.at(n - 2) += a.at(n - 1);
  			a.erase(a.begin() + n - 1);
  			n--;
  		}
  		else if(s.at(i) == "min"){
  			chmin(a.at(n - 2), a.at(n - 1));
  			a.erase(a.begin() + n - 1);
  			n--;
  		}
  		else if(s.at(i) == "max"){
  			chmax(a.at(n - 2), a.at(n - 1));
  			a.erase(a.begin() + n - 1);
  			n--;
  		}
  		else{
  			a.push_back(stoll(s.at(i)));
  			n++;
  		}
  	}
  	(a.at(0) >= y ? ok : ng) = mid;
  }
  __int128_t mid = ok, n = 0; vector<__int128_t> a;
  rep(i, q){
  		if(s.at(i) == "X"){
  			a.push_back(mid);
  			n++;
  		}
  		else if(s.at(i) == "+"){
  			a.at(n - 2) += a.at(n - 1);
  			a.erase(a.begin() + n - 1);
  			n--;
  		}
  		else if(s.at(i) == "min"){
  			chmin(a.at(n - 2), a.at(n - 1));
  			a.erase(a.begin() + n - 1);
  			n--;
  		}
  		else if(s.at(i) == "max"){
  			chmax(a.at(n - 2), a.at(n - 1));
  			a.erase(a.begin() + n - 1);
  			n--;
  		}
  		else{
  			a.push_back(stoll(s.at(i)));
  			n++;
  		}
  	}
  	cout << (a.at(0) == y ? int(ok) : -1) << endl;
}
0