結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー | みここ |
提出日時 | 2022-12-12 04:14:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 267 ms / 2,000 ms |
コード長 | 2,635 bytes |
コンパイル時間 | 934 ms |
コンパイル使用メモリ | 81,944 KB |
実行使用メモリ | 33,640 KB |
最終ジャッジ日時 | 2024-04-23 22:05:55 |
合計ジャッジ時間 | 10,140 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 203 ms
25,288 KB |
testcase_05 | AC | 164 ms
21,212 KB |
testcase_06 | AC | 27 ms
9,072 KB |
testcase_07 | AC | 34 ms
9,884 KB |
testcase_08 | AC | 194 ms
29,132 KB |
testcase_09 | AC | 157 ms
19,484 KB |
testcase_10 | AC | 80 ms
13,684 KB |
testcase_11 | AC | 145 ms
21,000 KB |
testcase_12 | AC | 106 ms
15,820 KB |
testcase_13 | AC | 113 ms
22,144 KB |
testcase_14 | AC | 94 ms
14,012 KB |
testcase_15 | AC | 122 ms
22,068 KB |
testcase_16 | AC | 108 ms
14,596 KB |
testcase_17 | AC | 75 ms
19,348 KB |
testcase_18 | AC | 117 ms
22,400 KB |
testcase_19 | AC | 235 ms
29,796 KB |
testcase_20 | AC | 45 ms
11,328 KB |
testcase_21 | AC | 102 ms
16,284 KB |
testcase_22 | AC | 96 ms
14,472 KB |
testcase_23 | AC | 176 ms
25,984 KB |
testcase_24 | AC | 259 ms
33,640 KB |
testcase_25 | AC | 260 ms
33,504 KB |
testcase_26 | AC | 257 ms
33,596 KB |
testcase_27 | AC | 254 ms
33,512 KB |
testcase_28 | AC | 259 ms
33,508 KB |
testcase_29 | AC | 255 ms
33,508 KB |
testcase_30 | AC | 254 ms
33,380 KB |
testcase_31 | AC | 261 ms
33,504 KB |
testcase_32 | AC | 267 ms
33,476 KB |
testcase_33 | AC | 262 ms
33,504 KB |
testcase_34 | AC | 142 ms
17,840 KB |
testcase_35 | AC | 121 ms
17,084 KB |
testcase_36 | AC | 115 ms
17,132 KB |
testcase_37 | AC | 108 ms
15,360 KB |
testcase_38 | AC | 128 ms
17,660 KB |
testcase_39 | AC | 89 ms
14,208 KB |
testcase_40 | AC | 90 ms
16,300 KB |
testcase_41 | AC | 90 ms
14,464 KB |
testcase_42 | AC | 88 ms
16,032 KB |
testcase_43 | AC | 91 ms
13,952 KB |
testcase_44 | AC | 132 ms
29,104 KB |
testcase_45 | AC | 132 ms
28,964 KB |
testcase_46 | AC | 125 ms
29,156 KB |
testcase_47 | AC | 122 ms
28,996 KB |
ソースコード
#include <iostream> #include <cassert> #include <vector> using namespace std; typedef long long ll; template <typename T = int> struct edge { int from, to; T cost; int id; operator int() const { return to; } }; template <typename T = int> struct graph { int n, m; std::vector<std::vector<edge<T>>> g; graph() {} graph(int n) : n(n), m(0) { g.resize(n); } void add_directed_edge(int from, int to, T cost = 1) { assert(0 <= from && from < n); assert(0 <= to && to < n); g[from].push_back((edge<T>){from, to, cost, m++}); } void add_undirected_edge(int from, int to, T cost = 1) { assert(0 <= from && from < n); assert(0 <= to && to < n); g[from].push_back((edge<T>){from, to, cost, m}); g[to].push_back((edge<T>){to, from, cost, m++}); } int size() { return n; } int edge_size() { return m; } inline const std::vector<edge<T>> &operator[](const int &u) const { return g[u]; } inline std::vector<edge<T>> &operator[](const int &u) { return g[u]; } }; int main() { int n, m; cin >> n >> m; ll h[100005]; for (int u = 0; u < n; u++) { cin >> h[u]; } graph<ll> g(n * 2), r(n * 2); for (int u = 0; u < n; u++) { g.add_directed_edge(u * 2, u * 2 + 1, 0); r.add_directed_edge(u * 2 + 1, u * 2, 0); } for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; if (x > y) { swap(x, y); } if (h[x] < h[y]) { g.add_directed_edge(x * 2, y * 2 + 1, h[y] - h[x]); r.add_directed_edge(y * 2, x * 2 + 1, 0); } else { g.add_directed_edge(x * 2 + 1, y * 2, 0); r.add_directed_edge(y * 2 + 1, x * 2, h[x] - h[y]); } } ll d0[200005], d1[200005]; for (int u = 0; u < n * 2; u++) { d0[u] = d1[u] = -1; } d0[0] = 0; for (int u = 0; u < n * 2; u++) { if (d0[u] == -1) { continue; } for (edge<ll> e : g[u]) { d0[e.to] = max(d0[e.to], d0[u] + e.cost); } } cout << d0[n * 2 - 1] << endl; d1[n * 2 - 1] = 0; for (int u = n * 2 - 1; u >= 0; u--) { if (d1[u] == -1) { continue; } for (edge<ll> e : r[u]) { d1[e.to] = max(d1[e.to], d1[u] + e.cost); } } cout << d1[0] << endl; }