結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー butsurizukibutsurizuki
提出日時 2022-10-07 11:02:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,390 bytes
コンパイル時間 8,334 ms
コンパイル使用メモリ 336,556 KB
実行使用メモリ 22,148 KB
最終ジャッジ日時 2023-09-08 20:35:14
合計ジャッジ時間 15,832 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 103 ms
12,608 KB
testcase_40 AC 106 ms
12,568 KB
testcase_41 AC 106 ms
12,620 KB
testcase_42 AC 103 ms
12,684 KB
testcase_43 AC 105 ms
12,668 KB
testcase_44 AC 99 ms
20,104 KB
testcase_45 AC 98 ms
19,960 KB
testcase_46 WA -
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

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,-1));
  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]);
  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