結果
問題 | No.1095 Smallest Kadomatsu Subsequence |
ユーザー | shimarut |
提出日時 | 2021-05-04 21:39:59 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,019 bytes |
コンパイル時間 | 3,719 ms |
コンパイル使用メモリ | 188,408 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-07-23 16:56:34 |
合計ジャッジ時間 | 7,937 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | WA | - |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | WA | - |
testcase_13 | AC | 9 ms
6,940 KB |
testcase_14 | AC | 9 ms
6,940 KB |
testcase_15 | WA | - |
testcase_16 | AC | 9 ms
6,944 KB |
testcase_17 | WA | - |
testcase_18 | AC | 9 ms
6,940 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 9 ms
6,940 KB |
testcase_23 | AC | 251 ms
14,976 KB |
testcase_24 | AC | 253 ms
14,976 KB |
testcase_25 | AC | 243 ms
14,976 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 153 ms
14,976 KB |
testcase_29 | AC | 155 ms
15,104 KB |
testcase_30 | AC | 192 ms
14,976 KB |
testcase_31 | AC | 193 ms
15,104 KB |
testcase_32 | AC | 192 ms
15,104 KB |
ソースコード
#pragma region #define _USE_MATH_DEFINES #include <iostream> #include <string> #include <algorithm> #include <cmath> #include <cstdlib> #include <vector> #include <map> #include <queue> #include <stack> #include <set> #include <list> #include <iomanip> #include <cstdint> #include <bitset> #include <sstream> #include <regex> #include <fstream> #include <array> #include <atcoder/all> using namespace atcoder; using mint = modint1000000007; //using mint = modint998244353; //using mint = modint; using namespace std; typedef long long ll; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pint = pair<int, int>; using pll = pair<ll, ll>; using vpint = vector<pint>; using vvpint = vector<vpint>; using vmint = vector<mint>; using vvmint = vector<vmint>; //#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i)) #define rep(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i)) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #pragma region GCD ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a % b); } #pragma endregion #pragma region LCM ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } #pragma endregion #pragma region chmin template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #pragma endregion #pragma region chmax template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } #pragma endregion #pragma region グリッド内チェック bool out(int x, int y, int h, int w) { if (x < 0 || h <= x || y < 0 || w <= y)return true; else return false; } #pragma endregion #pragma region Dijkstra vl dijkstra(vector<vector<pair<int, ll>>> v, int s) { ll INF = 1e18; int MAX = 1e6; vl res(MAX, INF); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q; q.push({ 0,s }); while (!q.empty()) { int now; ll d; tie(d, now) = q.top(); q.pop(); if (!chmin(res[now], d))continue; for (auto p : v[now]) { int next; ll c; tie(next, c) = p; if (res[next] <= res[now] + c)continue; q.push({ res[now] + c,next }); } } return res; } #pragma endregion #pragma endregion int main() { int n; cin >> n; vi a(n); rep(i, n)cin >> a[i]; vi lsmall(n), rsmall(n); lsmall[0] = a[0]; rsmall[n - 1] = a[n - 1]; for (int i = 1; i < n; ++i)lsmall[i] = min(lsmall[i - 1], a[i]); rrep(i, n - 1)rsmall[i] = min(rsmall[i + 1], a[i]); int res = 1e9; for (int i = 1; i < n - 1; ++i) { if (a[i] > lsmall[i - 1] && a[i] > rsmall[i + 1]) { chmin(res, a[i] + lsmall[i - 1] + rsmall[i + 1]); } } set<int> l, r; l.insert(a[0]); rep(i, n - 1)r.insert(a[i + 1]); for (int i = 1; i < n - 1; ++i) { r.erase(a[i]); auto lit = l.lower_bound(a[i]); auto rit = r.lower_bound(a[i]); if (lit == l.end() || rit == r.end())continue; chmin(res, *lit + a[i] + *rit); } if (res == 1e9)cout << -1 << endl; else cout << res << endl; }