結果

問題 No.2927 Reverse Polish Equation
ユーザー MMMM
提出日時 2024-10-12 16:48:21
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 6,267 ms
コンパイル使用メモリ 336,660 KB
実行使用メモリ 17,588 KB
最終ジャッジ日時 2024-10-16 00:27:52
合計ジャッジ時間 12,916 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 4 ms
5,248 KB
testcase_09 AC 3 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 4 ms
5,248 KB
testcase_12 AC 132 ms
6,784 KB
testcase_13 AC 221 ms
9,384 KB
testcase_14 AC 157 ms
7,560 KB
testcase_15 AC 216 ms
9,216 KB
testcase_16 AC 70 ms
5,248 KB
testcase_17 AC 291 ms
11,008 KB
testcase_18 AC 350 ms
12,832 KB
testcase_19 AC 22 ms
5,248 KB
testcase_20 AC 276 ms
11,008 KB
testcase_21 AC 432 ms
14,976 KB
testcase_22 AC 39 ms
5,248 KB
testcase_23 AC 1 ms
5,248 KB
testcase_24 AC 1 ms
5,248 KB
testcase_25 AC 2 ms
5,248 KB
testcase_26 AC 2 ms
5,248 KB
testcase_27 AC 372 ms
13,568 KB
testcase_28 AC 325 ms
11,932 KB
testcase_29 AC 41 ms
5,248 KB
testcase_30 AC 351 ms
13,028 KB
testcase_31 AC 25 ms
5,248 KB
testcase_32 AC 77 ms
5,380 KB
testcase_33 AC 152 ms
7,424 KB
testcase_34 AC 187 ms
8,600 KB
testcase_35 AC 2 ms
5,248 KB
testcase_36 AC 352 ms
13,188 KB
testcase_37 AC 117 ms
6,656 KB
testcase_38 AC 420 ms
14,720 KB
testcase_39 AC 182 ms
7,904 KB
testcase_40 AC 348 ms
12,944 KB
testcase_41 AC 280 ms
11,176 KB
testcase_42 WA -
testcase_43 AC 143 ms
17,588 KB
testcase_44 AC 141 ms
17,584 KB
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))z
using namespace std;
using namespace atcoder;
using ll = long long;
const ll mod = 998244353;
using mint = modint998244353;
using Graph = vector<vector<pair<int,ll>>>;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};

double dist(int x1, int y1, int x2, int y2){
  double res = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);
  return sqrt(res);
}

ll f(ll x, vector<string> v){
  int n = v.size();
  vector<ll> a;
  for(int i = 0; i < n; i++){
    if(v[i] == "X")
      a.push_back(x);
    else if(v[i] == "+"){
      ll b = a.back();
      a.pop_back();
      ll c = a.back();
      a.pop_back();
      a.push_back(b+c);
    }
    else if(v[i] == "min"){
      ll b = a.back();
      a.pop_back();
      ll c = a.back();
      a.pop_back();
      a.push_back(min(b,c));
    }
    else if(v[i] == "max"){
      ll b = a.back();
      a.pop_back();
      ll c = a.back();
      a.pop_back();
      a.push_back(max(b,c));
    }
    else{
      ll m = stoi(v[i]);
      a.push_back(m);
    }
  }
  return a.front();
}

int main(){
  // input
  int Q; ll Y;
  cin >> Q >> Y;
  vector<string> S(Q);
  for(int i = 0; i < Q; i++){
    cin >> S[i];
    assert(S[i].size() > 0);
  }
    
  // solve
  ll lo = -1, hi = 1e18;
  while(abs(hi-lo) > 1){
    ll mid = (lo + hi) / 2;
    
    if(f(mid,S) >= Y) hi = mid;
    else lo = mid;
  }
  
  // output
  cout << (f(hi,S) == Y ? hi : -1) << endl;
}
0