結果
| 問題 |
No.1095 Smallest Kadomatsu Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-05 05:19:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,641 bytes |
| コンパイル時間 | 982 ms |
| コンパイル使用メモリ | 106,288 KB |
| 最終ジャッジ日時 | 2025-01-11 15:50:46 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 WA * 1 |
ソースコード
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;
template<class _T> static void getval(_T& a) {
std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
std::cin >> a >> b >> c;
}
static void exec();
int main()
{
exec();
fflush(stdout);
return 0;
}
static void exec()
{
int N;
getval(N);
int INF = 300000001;
int minVal = INF;
int minIdx = -1;
std::vector<int> ai(N);
for (int i = 0; i < N; i++) {
getval(ai[i]);
if (minVal > ai[i]) {
minVal = ai[i];
minIdx = i;
}
}
LLONG ans = 0;
int fMin = INF, fPeak = INF, fFst = INF;
std::set<int> fs;
for (int i = minIdx - 1; i >= 0; i--) {
if (fMin > ai[i]) {
fMin = ai[i];
}
if (fFst > ai[i]) {
auto f = fs.lower_bound(ai[i]);
if (f != fs.end()) {
fFst = ai[i];
fPeak = *f;
}
}
fs.insert(ai[i]);
}
fs.erase(fs.begin(), fs.end());
int lMin = INF, lPeak = INF, lLast = INF;
for (int i = minIdx + 1; i < N; i++) {
if (lMin > ai[i]) {
lMin = ai[i];
}
if (lLast > ai[i]) {
auto l = fs.lower_bound(ai[i]);
if (l != fs.end()) {
lLast = ai[i];
lPeak = *l;
}
}
fs.insert(ai[i]);
}
ans = std::min({ fMin + minVal + lMin, fFst + fPeak + minVal, minVal + lPeak + lLast });
if (ans > INF) ans = -1;
printf("%lld\n", ans);
}