結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー 👑 kmjpkmjp
提出日時 2022-10-14 23:08:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,738 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 203,096 KB
実行使用メモリ 22,448 KB
最終ジャッジ日時 2023-09-08 23:32:47
合計ジャッジ時間 6,967 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,052 KB
testcase_01 AC 5 ms
14,112 KB
testcase_02 AC 4 ms
13,832 KB
testcase_03 AC 4 ms
14,104 KB
testcase_04 AC 62 ms
18,376 KB
testcase_05 AC 48 ms
17,600 KB
testcase_06 AC 12 ms
14,688 KB
testcase_07 AC 14 ms
15,108 KB
testcase_08 AC 56 ms
19,420 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 48 ms
17,624 KB
testcase_12 WA -
testcase_13 AC 35 ms
17,592 KB
testcase_14 WA -
testcase_15 AC 37 ms
17,576 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 35 ms
17,816 KB
testcase_19 AC 67 ms
19,552 KB
testcase_20 AC 18 ms
15,176 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 52 ms
18,536 KB
testcase_24 AC 76 ms
20,340 KB
testcase_25 WA -
testcase_26 AC 75 ms
20,316 KB
testcase_27 WA -
testcase_28 AC 81 ms
20,204 KB
testcase_29 WA -
testcase_30 AC 79 ms
20,228 KB
testcase_31 WA -
testcase_32 AC 72 ms
20,320 KB
testcase_33 AC 75 ms
20,360 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 AC 45 ms
22,040 KB
testcase_47 AC 47 ms
22,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int H[202020];

vector<int> X[202020];
vector<int> Y[202020];

ll dp[202020][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>H[i];
	FOR(i,M) {
		cin>>x>>y;
		X[x-1].push_back(y-1);
		Y[y-1].push_back(x-1);
	}
	
	FOR(i,N) dp[i][0]=dp[i][1]=-1LL<<60;
	dp[0][0]=0;
	FOR(i,N) {
		FORR(e,X[i]) {
			if(H[e]>H[i]) {
				dp[e][1]=max(dp[e][1],dp[i][0]+H[e]-H[i]);
			}
			if(H[e]<H[i]) {
				dp[e][0]=max(dp[e][0],dp[i][0]);
				dp[e][1]=max(dp[e][0],dp[i][1]);
			}
		}
	}
	ll ret=max(dp[N-1][0],dp[N-1][1]);
	if(ret<=-1LL<<59) ret=-1;
	cout<<ret<<endl;
	
	FOR(i,N) dp[i][0]=dp[i][1]=-1LL<<60;
	dp[N-1][0]=0;
	for(i=N-1;i>=0;i--) {
		FORR(e,Y[i]) {
			if(H[e]>H[i]) {
				dp[e][1]=max(dp[e][1],dp[i][0]+H[e]-H[i]);
			}
			if(H[e]<H[i]) {
				dp[e][0]=max(dp[e][0],dp[i][0]);
				dp[e][1]=max(dp[e][0],dp[i][1]);
			}
		}
	}
	ret=max(dp[0][0],dp[0][1]);
	if(ret<=-1LL<<59) ret=-1;
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0