結果
| 問題 | No.1095 Smallest Kadomatsu Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 21:44:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 2,000 ms |
| コード長 | 526 bytes |
| 記録 | |
| コンパイル時間 | 1,841 ms |
| コンパイル使用メモリ | 197,152 KB |
| 最終ジャッジ日時 | 2025-01-11 11:10:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0),ios::sync_with_stdio(false);
int n; cin>>n;
vector<int>a(n); for(auto&&i:a)cin>>i;
vector<int>lm(n),rm(n); lm.front()=a.front(); rm.back()=a.back();
for(int i=1;i<n;++i)lm.at(i)=min(lm.at(i-1),a.at(i));
for(int i=n-2;i>=0;--i)rm.at(i)=min(rm.at(i+1),a.at(i));
int ans=1e9;
for(int i=1;i<n-1;++i){
int&l=lm.at(i-1),&m=a.at(i),&r=rm.at(i+1);
if(max({l,m,r})!=m&&min({l,m,r})!=m)continue;
ans=min(ans,l+m+r);
}
cout<<(ans!=1e9?ans:-1)<<"\n"s;
}