結果
問題 | No.1095 Smallest Kadomatsu Subsequence |
ユーザー | cn_449 |
提出日時 | 2020-06-26 21:28:06 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 374 ms / 2,000 ms |
コード長 | 1,773 bytes |
コンパイル時間 | 1,100 ms |
コンパイル使用メモリ | 118,852 KB |
実行使用メモリ | 13,400 KB |
最終ジャッジ日時 | 2023-09-18 03:00:57 |
合計ジャッジ時間 | 5,539 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 9 ms
4,380 KB |
testcase_14 | AC | 10 ms
4,376 KB |
testcase_15 | AC | 10 ms
4,376 KB |
testcase_16 | AC | 9 ms
4,376 KB |
testcase_17 | AC | 10 ms
4,380 KB |
testcase_18 | AC | 9 ms
4,380 KB |
testcase_19 | AC | 9 ms
4,376 KB |
testcase_20 | AC | 9 ms
4,376 KB |
testcase_21 | AC | 9 ms
4,380 KB |
testcase_22 | AC | 9 ms
4,376 KB |
testcase_23 | AC | 353 ms
13,400 KB |
testcase_24 | AC | 355 ms
13,336 KB |
testcase_25 | AC | 374 ms
13,396 KB |
testcase_26 | AC | 346 ms
13,336 KB |
testcase_27 | AC | 353 ms
13,360 KB |
testcase_28 | AC | 178 ms
13,348 KB |
testcase_29 | AC | 173 ms
13,352 KB |
testcase_30 | AC | 252 ms
13,052 KB |
testcase_31 | AC | 251 ms
13,024 KB |
testcase_32 | AC | 246 ms
13,400 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int ans = inf; set<int> left, right; left.insert(inf); right.insert(inf); for (int i = 1; i < n; i++) right.insert(a[i]); rep(i, n) { auto itr = right.lower_bound(a[i]); auto itl = left.lower_bound(a[i]); if (*itr != inf && *itl != inf) chmin(ans, *itr + *itl + a[i]); itr = left.begin(); itl = right.begin(); if (*itr < a[i] && *itl < a[i]) chmin(ans, *itr + *itl + a[i]); left.insert(a[i]); if (i != n - 1) right.erase(a[i + 1]); } if (ans == inf) cout << "-1\n"; else cout << ans << '\n'; }