結果
| 問題 |
No.1095 Smallest Kadomatsu Subsequence
|
| コンテスト | |
| ユーザー |
Dente
|
| 提出日時 | 2020-06-26 21:59:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 412 ms / 2,000 ms |
| コード長 | 927 bytes |
| コンパイル時間 | 2,005 ms |
| コンパイル使用メモリ | 200,340 KB |
| 最終ジャッジ日時 | 2025-01-11 11:26:37 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
signed main() {
int n;
cin >> n;
set<int> L, R;
int a[n];
rep(i, n) {
cin >> a[i];
if (i) R.emplace(a[i]);
}
L.emplace(a[0]);
int ans = INF;
for (int i = 1; i < n - 1; i++) {
auto litr = L.upper_bound(a[i]);
auto ritr = R.upper_bound(a[i]);
if(litr != L.end() && ritr != R.end()){
ans = min(ans, *litr + a[i] + *ritr);
}
if(*L.begin() < a[i] && a[i] > *R.begin()){
ans = min(ans, *L.begin() + a[i] + *R.begin());
}
L.emplace(a[i]);
R.erase(a[i]);
}
cout << (ans != INF ? ans : -1) << endl;
return 0;
}
Dente