結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー yansi819yansi819
提出日時 2024-04-12 10:38:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 1,245 bytes
コンパイル時間 3,993 ms
コンパイル使用メモリ 257,364 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2024-04-12 10:38:53
合計ジャッジ時間 10,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 132 ms
15,488 KB
testcase_05 AC 107 ms
12,800 KB
testcase_06 AC 21 ms
7,808 KB
testcase_07 AC 26 ms
8,448 KB
testcase_08 AC 131 ms
19,072 KB
testcase_09 AC 99 ms
11,392 KB
testcase_10 AC 49 ms
7,240 KB
testcase_11 AC 91 ms
13,952 KB
testcase_12 AC 67 ms
9,916 KB
testcase_13 AC 91 ms
16,064 KB
testcase_14 AC 84 ms
8,340 KB
testcase_15 AC 83 ms
15,616 KB
testcase_16 AC 68 ms
8,320 KB
testcase_17 AC 56 ms
14,848 KB
testcase_18 AC 79 ms
16,128 KB
testcase_19 AC 143 ms
18,048 KB
testcase_20 AC 33 ms
8,800 KB
testcase_21 AC 65 ms
10,752 KB
testcase_22 AC 62 ms
8,520 KB
testcase_23 AC 115 ms
16,640 KB
testcase_24 AC 166 ms
20,224 KB
testcase_25 AC 163 ms
20,176 KB
testcase_26 AC 236 ms
20,224 KB
testcase_27 AC 159 ms
20,212 KB
testcase_28 AC 166 ms
20,336 KB
testcase_29 AC 163 ms
20,184 KB
testcase_30 AC 163 ms
20,232 KB
testcase_31 AC 164 ms
20,224 KB
testcase_32 AC 167 ms
20,248 KB
testcase_33 AC 179 ms
20,136 KB
testcase_34 AC 124 ms
8,588 KB
testcase_35 AC 76 ms
8,192 KB
testcase_36 AC 76 ms
8,064 KB
testcase_37 AC 70 ms
8,064 KB
testcase_38 AC 82 ms
8,276 KB
testcase_39 AC 64 ms
8,064 KB
testcase_40 AC 65 ms
8,448 KB
testcase_41 AC 63 ms
8,064 KB
testcase_42 AC 64 ms
8,448 KB
testcase_43 AC 63 ms
8,064 KB
testcase_44 AC 103 ms
20,096 KB
testcase_45 AC 104 ms
20,136 KB
testcase_46 AC 100 ms
20,352 KB
testcase_47 AC 103 ms
20,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int N, M, H[101010];
vector<int> G[101010];

int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> H[i];
  for (int i = 1; i <= M; i++) {
    int x, y; cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  ll INF = 1LL << 60;
  vector<vector<ll>> dpc(N + 1, vector<ll>(2, -INF));
  dpc[1][0] = 0;
  for (int a = 1; a <= N; a++) {
    for (auto b: G[a]) {
      if (a < b) {
        if (H[a] < H[b]) dpc[b][1] = max(dpc[b][1], dpc[a][0] + (H[b] - H[a]));
        else dpc[b][0] = max(dpc[b][0], max(dpc[a][0], dpc[a][1]));
      }
    }
  }
  vector<vector<ll>> dpz(N + 1, vector<ll>(2, -INF));
  dpz[N][0] = 0;
  for (int a = N; a >= 1; a--) {
    for (auto b: G[a]) {
      if (a > b) {
        if (H[a] < H[b]) dpz[b][1] = max(dpz[b][1], dpz[a][0] + (H[b] - H[a]));
        else dpz[b][0] = max(dpz[b][0], max(dpz[a][0], dpz[a][1]));
      }
    }
  }
  cout << (max(dpc[N][0], dpc[N][1]) > -INF / 2 ? max(dpc[N][0], dpc[N][1]): -1) << endl;
  cout << (max(dpz[1][0], dpz[1][1]) > -INF / 2 ? max(dpz[1][0], dpz[1][1]): -1) << endl;
  return 0;
}
0