結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー snrnsidysnrnsidy
提出日時 2021-05-13 03:33:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 210,492 KB
実行使用メモリ 14,260 KB
最終ジャッジ日時 2023-10-24 21:35:54
合計ジャッジ時間 8,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 10 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 10 ms
4,348 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 287 ms
14,260 KB
testcase_24 AC 283 ms
14,260 KB
testcase_25 AC 286 ms
14,260 KB
testcase_26 AC 284 ms
14,260 KB
testcase_27 AC 283 ms
14,260 KB
testcase_28 AC 178 ms
14,260 KB
testcase_29 AC 182 ms
14,260 KB
testcase_30 AC 236 ms
14,260 KB
testcase_31 AC 236 ms
14,260 KB
testcase_32 AC 238 ms
14,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long int res = 1e18;
	int n;
	long long int t;
	set <long long int> l, r;
	vector <long long int> v;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		v.push_back(t);
		r.insert(t);
	}

	for (int i = 0; i < n; i++)
	{
		r.erase(v[i]);
		if (l.size() > 0 && r.size() > 0)
		{
			long long int a = *l.begin();
			long long int b = *r.begin();
			if (a < v[i] && b < v[i])
			{
				res = min(res, a + b + v[i]);
			}
			auto it1 = l.lower_bound(v[i]);
			auto it2 = r.lower_bound(v[i]);
			if (it1 != l.end() && it2 != r.end())
			{
				a = *it1;
				b = *it2;
				res = min(res, a + b + v[i]);
			}
		}
		l.insert(v[i]);
	}

	if (res >= 1e18)
	{
		res = -1;
	}

	cout << res << '\n';

	return 0;
}
0