結果
| 問題 |
No.3385 Up Down Hiking (C++)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-18 22:53:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 2,000 ms |
| コード長 | 1,006 bytes |
| コンパイル時間 | 1,961 ms |
| コンパイル使用メモリ | 207,288 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2025-11-22 12:33:39 |
| 合計ジャッジ時間 | 8,056 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 43 |
ソースコード
#include"bits/stdc++.h"
using namespace std;
int main() {
int n,m;
cin>>n>>m;
vector<int>h(n);
vector<vector<int>>g(n);
for(auto &x:h)cin>>x;
vector<pair<int,int>>hs;
for(int i=0;i<n;i++)hs.push_back({h[i],i});
sort(hs.begin(),hs.end());
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;a--,b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int>up(n,-n),down(n,-n);
up[0]=down[n-1]=1;
for(auto[hi,v]:hs){
if(up[v]<0)continue;
for(auto to:g[v]){
if(h[v]<h[to]){
up[to]=max(up[to],up[v]+1);
}
}
}
for(auto[hi,v]:hs){
if(down[v]<0)continue;
for(auto to:g[v]){
if(h[v]<h[to]){
down[to]=max(down[to],down[v]+1);
}
}
}
int k=-1,mid=-1;
for(int i=0;i<n;i++){
int len=up[i]+down[i]-1;
if(len>k){
k=len;mid=i;
}
}
cout<<k<<endl;
return 0;
}