結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー kwm_tkwm_t
提出日時 2022-10-15 12:48:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,193 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 209,740 KB
実行使用メモリ 21,512 KB
最終ジャッジ日時 2023-09-09 02:27:43
合計ジャッジ時間 7,204 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 85 ms
16,352 KB
testcase_05 AC 64 ms
13,456 KB
testcase_06 AC 12 ms
5,460 KB
testcase_07 AC 15 ms
6,156 KB
testcase_08 AC 81 ms
18,484 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 57 ms
13,596 KB
testcase_12 WA -
testcase_13 AC 51 ms
13,876 KB
testcase_14 WA -
testcase_15 AC 51 ms
14,144 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 50 ms
14,120 KB
testcase_19 AC 98 ms
18,984 KB
testcase_20 AC 20 ms
6,680 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 74 ms
16,288 KB
testcase_24 AC 106 ms
21,264 KB
testcase_25 WA -
testcase_26 AC 109 ms
21,324 KB
testcase_27 WA -
testcase_28 AC 113 ms
21,248 KB
testcase_29 WA -
testcase_30 AC 109 ms
21,116 KB
testcase_31 WA -
testcase_32 AC 107 ms
21,244 KB
testcase_33 AC 109 ms
21,124 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 60 ms
19,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<long long,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct Edge {
	int to;
	long long cost;
	Edge(int _to, long long _cost) :to(_to), cost(_cost) {}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector<int>h(n);
	vector<vector<Edge>>g0(n), g1(n);
	rep(i, n)cin >> h[i];
	rep(i, m) {
		int x, y; cin >> x >> y; x--, y--;
		if (x > y)swap(x, y);
		g0[x].emplace_back(y, max(0, h[y] - h[x]));
		g1[y].emplace_back(x, max(0, h[x] - h[y]));
	}
	{
		vector<vector<long long>> dp(n, vector<long long>(2, -1));
		dp[0][1] = 0;
		rep(i, n)rep(j, 2) {
			if (-1 == dp[i][j])continue;
			for (Edge e : g0[i]) {
				long long nval = dp[i][j] + e.cost;
				int npos = e.to;
				if (0 == j) {
					if (e.cost < 0) chmax(dp[npos][1], nval);
				}
				else {
					if (e.cost > 0) chmax(dp[npos][0], nval);
					else chmax(dp[npos][1], nval);
				}
			}
		}
		cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;
	}
	{
		vector<vector<long long>> dp(n, vector<long long>(2, -1));
		dp[n - 1][1] = 0;
		rrep(i, n)rep(j, 2) {
			if (-1 == dp[i][j])continue;
			for (Edge e : g0[i]) {
				long long nval = dp[i][j] + e.cost;
				int npos = e.to;
				if (0 == j) {
					if (e.cost < 0) chmax(dp[npos][1], nval);
				}
				else {
					if (e.cost > 0) chmax(dp[npos][0], nval);
					else chmax(dp[npos][1], nval);
				}
			}
		}
		cout << max(dp[0][0], dp[0][1]) << endl;
	}
	return 0;
}
0