結果
| 問題 | No.1095 Smallest Kadomatsu Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-28 15:58:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 309 ms / 2,000 ms |
| コード長 | 577 bytes |
| 記録 | |
| コンパイル時間 | 1,971 ms |
| コンパイル使用メモリ | 202,016 KB |
| 最終ジャッジ日時 | 2025-01-11 13:21:50 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | int n; scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int main(){
int n; scanf("%d",&n);
vector<int> a(n);
rep(i,n) scanf("%d",&a[i]);
int ans=INF;
set<int> L={a[0]},R(a.begin()+1,a.end());
for(int i=1;i<n-1;i++){
R.erase(a[i]);
auto itl=L.lower_bound(a[i]);
auto itr=R.lower_bound(a[i]);
if(itl!=L.end() && itr!=R.end() ) ans=min(ans,a[i]+*itl+*itr);
if(itl!=L.begin() && itr!=R.begin()) ans=min(ans,a[i]+*L.begin()+*R.begin());
L.emplace(a[i]);
}
printf("%d\n",ans<INF?ans:-1);
return 0;
}