結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー kyushu1996kyushu1996
提出日時 2022-10-27 02:29:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,592 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 113,548 KB
実行使用メモリ 23,952 KB
最終ジャッジ日時 2023-09-17 19:33:35
合計ジャッジ時間 10,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 180 ms
19,532 KB
testcase_05 AC 136 ms
16,416 KB
testcase_06 AC 13 ms
5,512 KB
testcase_07 AC 18 ms
6,328 KB
testcase_08 AC 121 ms
19,040 KB
testcase_09 AC 158 ms
16,560 KB
testcase_10 WA -
testcase_11 AC 99 ms
15,128 KB
testcase_12 WA -
testcase_13 AC 51 ms
12,960 KB
testcase_14 WA -
testcase_15 AC 62 ms
13,768 KB
testcase_16 WA -
testcase_17 AC 27 ms
10,008 KB
testcase_18 AC 55 ms
13,196 KB
testcase_19 AC 205 ms
21,932 KB
testcase_20 AC 26 ms
7,216 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 125 ms
17,704 KB
testcase_24 AC 220 ms
23,792 KB
testcase_25 WA -
testcase_26 AC 213 ms
23,796 KB
testcase_27 WA -
testcase_28 AC 216 ms
23,796 KB
testcase_29 AC 219 ms
23,916 KB
testcase_30 AC 233 ms
23,952 KB
testcase_31 WA -
testcase_32 AC 238 ms
23,644 KB
testcase_33 AC 227 ms
23,836 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 55 ms
19,088 KB
testcase_47 AC 54 ms
19,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>
#define ll long long
#define endl '\n'
using namespace std;
// category : 

int main() {
    ios_base::sync_with_stdio(false);
    
    int n,m; cin>>n>>m;

	vector<vector<int>> dp1(2,vector<int>(n+1,0));
	vector<vector<int>> dp2(2,vector<int>(n+1,0));

	vector<vector<bool>> flag1(2,vector<bool>(n+1,0));
	vector<vector<bool>> flag2(2,vector<bool>(n+1,0));

	flag1[0][1]=true;
	flag2[0][n]=true;
	
	int h[n+1]={}; for(int i=1;i<=n;i++) cin>>h[i];

	vector<set<int>> v(n+1);
	for(int i=0;i<m;i++){
		int x,y; cin>>x>>y;
		v[x].insert(y);
		v[y].insert(x);
	}

	for(int i=2;i<=n;i++){
		for(auto j : v[i]){
			if(!(flag1[0][j]|flag1[1][j])) continue;
			
			if(h[i]>h[j]){
				if(flag1[0][j]==true){
					dp1[1][i]=max(dp1[1][i],dp1[0][j]+h[i]-h[j]);
					flag1[1][i]=true;
				}
				else continue;
			}
			else{
				dp1[0][i]=max({dp1[0][i],dp1[0][j],dp1[1][j]});
				flag1[0][i]=true;
			}
		}
	}
	if(flag1[0][n]|flag1[1][n])cout<<max(dp1[0][n],dp1[1][n])<<endl;
	else cout<<-1<<endl;

	for(int i=n-1;i>=1;i--){
		for(auto j : v[i]){
			if(!(flag2[0][j]|flag2[1][j])) continue;
			
			if(h[i]>h[j]){
				if(flag2[0][j]==true){
					dp2[1][i]=max(dp2[1][i],dp2[0][j]+h[i]-h[j]);
					flag2[1][i]=true;
				}
				else continue;
			}
			else{
				dp2[0][i]=max({dp2[0][i],dp2[0][j],dp2[1][j]});
				flag2[0][i]=true;
			}
		}
	}
	if(flag2[0][1]|flag2[1][1]) cout<<max(dp2[0][1],dp2[1][1])<<endl;
	else cout<<-1<<endl;

	return 0;
}
0