結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー furafura
提出日時 2020-06-28 15:58:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 208,328 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-09-22 02:25:19
合計ジャッジ時間 9,293 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 398 ms
13,040 KB
testcase_24 AC 392 ms
13,456 KB
testcase_25 AC 383 ms
13,096 KB
testcase_26 AC 384 ms
13,036 KB
testcase_27 AC 382 ms
13,452 KB
testcase_28 AC 153 ms
13,048 KB
testcase_29 AC 189 ms
13,120 KB
testcase_30 AC 290 ms
13,144 KB
testcase_31 AC 260 ms
13,548 KB
testcase_32 AC 253 ms
13,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int ans=INF;
	set<int> L={a[0]},R(a.begin()+1,a.end());
	for(int i=1;i<n-1;i++){
		R.erase(a[i]);

		auto itl=L.lower_bound(a[i]);
		auto itr=R.lower_bound(a[i]);
		if(itl!=L.end()   && itr!=R.end()  ) ans=min(ans,a[i]+*itl+*itr);
		if(itl!=L.begin() && itr!=R.begin()) ans=min(ans,a[i]+*L.begin()+*R.begin());

		L.emplace(a[i]);
	}
	printf("%d\n",ans<INF?ans:-1);

	return 0;
}
0