結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー butsurizukibutsurizuki
提出日時 2022-10-07 11:03:11
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 9,543 ms
コンパイル使用メモリ 337,692 KB
実行使用メモリ 22,060 KB
最終ジャッジ日時 2023-09-08 20:35:43
合計ジャッジ時間 15,942 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 145 ms
17,276 KB
testcase_05 AC 120 ms
14,424 KB
testcase_06 AC 19 ms
6,048 KB
testcase_07 AC 25 ms
6,488 KB
testcase_08 AC 138 ms
18,344 KB
testcase_09 AC 124 ms
13,696 KB
testcase_10 AC 72 ms
9,672 KB
testcase_11 AC 102 ms
14,104 KB
testcase_12 AC 85 ms
10,796 KB
testcase_13 AC 76 ms
13,304 KB
testcase_14 AC 75 ms
10,080 KB
testcase_15 AC 85 ms
13,600 KB
testcase_16 AC 85 ms
10,708 KB
testcase_17 AC 48 ms
10,804 KB
testcase_18 AC 82 ms
13,400 KB
testcase_19 AC 175 ms
19,896 KB
testcase_20 AC 34 ms
7,076 KB
testcase_21 AC 77 ms
10,912 KB
testcase_22 AC 79 ms
10,332 KB
testcase_23 AC 126 ms
16,708 KB
testcase_24 AC 202 ms
21,840 KB
testcase_25 AC 197 ms
21,636 KB
testcase_26 AC 196 ms
21,720 KB
testcase_27 AC 197 ms
21,856 KB
testcase_28 AC 192 ms
21,716 KB
testcase_29 AC 199 ms
22,060 KB
testcase_30 AC 190 ms
21,820 KB
testcase_31 AC 189 ms
21,964 KB
testcase_32 AC 189 ms
21,696 KB
testcase_33 AC 192 ms
21,728 KB
testcase_34 AC 125 ms
13,280 KB
testcase_35 AC 115 ms
13,036 KB
testcase_36 AC 115 ms
12,876 KB
testcase_37 AC 109 ms
12,772 KB
testcase_38 AC 120 ms
13,244 KB
testcase_39 AC 103 ms
12,684 KB
testcase_40 AC 109 ms
12,600 KB
testcase_41 AC 107 ms
12,644 KB
testcase_42 AC 105 ms
12,588 KB
testcase_43 AC 104 ms
12,596 KB
testcase_44 AC 98 ms
20,020 KB
testcase_45 AC 97 ms
20,040 KB
testcase_46 AC 95 ms
20,088 KB
testcase_47 AC 96 ms
20,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;
using pi=pair<int,int>;

int n,m;
vector<int> h;
vector<pi> xy;

void reverseProblem(){
  reverse(h.begin(),h.end());
  for(int i=0;i<m;i++){
    swap(xy[i].first,xy[i].second);
    xy[i].first=n-1-xy[i].first;
    xy[i].second=n-1-xy[i].second;
  }
}

long long solve(){
  vector<vector<long long>> dp(n,vector<long long>(2,-8e18));
  dp[0][0]=0;
  dp[0][1]=0;
  vector<vector<int>> g(n);
  for(int i=0;i<m;i++){
    g[xy[i].first].push_back(xy[i].second);
  }
  for(int i=0;i<n;i++){
    for(auto &nx : g[i]){
      if(h[i]<h[nx]){dp[nx][1]=max(dp[nx][1],dp[i][0]+h[nx]-h[i]);}
      else{dp[nx][0]=max(dp[nx][0],max(dp[i][0],dp[i][1]));}
    }
  }
  long long res=max(dp[n-1][0],dp[n-1][1]);
  if(res<0){res=-1;}
  return res;
}

int main(){
  registerValidation();
  n=inf.readInt(2,100000);inf.readSpace();
  m=inf.readInt(1,150000);inf.readEoln();
  h=inf.readInts(n,0,1000000000);inf.readEoln();
  xy.resize(m);
  set<pi> st;
  for(int i=0;i<m;i++){
    xy[i].first=inf.readInt(1,n);inf.readSpace();
    xy[i].second=inf.readInt(xy[i].first+1,n);inf.readEoln();
    xy[i].first--;xy[i].second--;
    st.insert(xy[i]);
    ensuref(h[xy[i].first]!=h[xy[i].second],"This is not a stairs");
  }
  ensuref(st.size()==m,"doubled stairs");
  inf.readEof();

  cout << solve() << "\n";
  reverseProblem();
  cout << solve() << "\n";
  return 0;
}
0