結果
| 問題 |
No.1095 Smallest Kadomatsu Subsequence
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2020-06-26 22:18:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 385 ms / 2,000 ms |
| コード長 | 1,357 bytes |
| コンパイル時間 | 2,688 ms |
| コンパイル使用メモリ | 201,092 KB |
| 最終ジャッジ日時 | 2025-01-11 11:43:19 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
ソースコード
#pragma once
//https://atcoder.jp/contests/dp/tasks/dp_t
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846 // pi
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;
#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)
#include <bits/stdc++.h>
using namespace std;
static const ll INF = 1e15;
static const ll mod = 1e9 + 7;
ll solve(const vector<ll>& as) {
ll res = -INF;
ll s = 0;
rep(j, as.size()) {
s = max(s + as[j], as[j]);
res = max(res, s);
}
return res;
}
int main() {
int n;
cin >> n;
vector<ll> vs(n);
rep(i, n) cin >> vs[i];
set<ll> right;
rep(i, n) right.insert(vs[i]);
set<ll> left;
left.insert(vs[0]);
right.erase(vs[0]);
ll lower = INF;
for (int i = 1; i < n-1; i++) {
ll c = vs[i];
right.erase(c);
auto l = left.lower_bound(vs[i]);
auto r = right.lower_bound(vs[i]);
if (l != left.end() && r != right.end()) {
lower = min(lower, *l + *r + c);
}
if (*left.begin() < c && *right.begin() < c) {
lower = min(lower, *left.begin() + *right.begin() + c);
}
left.insert(c);
}
if (lower != INF) {
cout << lower << endl;
}
else {
cout << -1 << endl;
}
return 0;
}
nanophoto12