結果
問題 |
No.1095 Smallest Kadomatsu Subsequence
|
ユーザー |
|
提出日時 | 2020-06-26 21:32:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 391 ms / 2,000 ms |
コード長 | 839 bytes |
コンパイル時間 | 1,839 ms |
コンパイル使用メモリ | 201,276 KB |
最終ジャッジ日時 | 2025-01-11 10:52:39 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> int main(){ int N; while(std::cin >> N){ std::vector<int> A(N); for(int i = 0; i < N; ++i) std::cin >> A[i]; int ans = INT_MAX; std::set<int> right, left; for(int i = 0; i < N; ++i) right.insert(A[i]); for(int i = 0; i < N; ++i){ int b = A[i]; right.erase(b); if(left.size() and right.size()){ if(*left.begin() < b and *right.begin() < b){ ans = std::min(ans, *left.begin() + b + *right.begin()); } } { auto lit = left.lower_bound(b); auto rit = right.lower_bound(b); if(lit != left.end() and rit != right.end()){ ans = std::min(ans, *lit + b + *rit); } } left.insert(b); } std::cout << (ans == INT_MAX ? -1 : ans) << "\n"; } return 0; }