結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー nanophoto12nanophoto12
提出日時 2020-06-26 22:18:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 208,396 KB
実行使用メモリ 13,960 KB
最終ジャッジ日時 2023-09-18 05:34:29
合計ジャッジ時間 7,607 ms
ジャッジサーバーID
(参考情報)
judge12 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 12 ms
4,376 KB
testcase_23 AC 407 ms
13,848 KB
testcase_24 AC 398 ms
13,832 KB
testcase_25 AC 407 ms
13,800 KB
testcase_26 AC 401 ms
13,860 KB
testcase_27 AC 402 ms
13,836 KB
testcase_28 AC 234 ms
13,952 KB
testcase_29 AC 232 ms
13,948 KB
testcase_30 AC 298 ms
13,860 KB
testcase_31 AC 294 ms
13,844 KB
testcase_32 AC 299 ms
13,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:1:9: 警告: #pragma once がメインファイルにあります
    1 | #pragma once
      |         ^~~~

ソースコード

diff #

#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;
}
0