結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kotatsugamekotatsugame
提出日時 2020-06-26 21:24:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 435 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 76,828 KB
実行使用メモリ 13,780 KB
最終ジャッジ日時 2023-09-18 02:54:11
合計ジャッジ時間 6,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 415 ms
13,488 KB
testcase_24 AC 411 ms
13,636 KB
testcase_25 AC 404 ms
13,780 KB
testcase_26 AC 410 ms
13,520 KB
testcase_27 AC 435 ms
13,496 KB
testcase_28 AC 233 ms
13,556 KB
testcase_29 AC 232 ms
13,488 KB
testcase_30 AC 306 ms
13,476 KB
testcase_31 AC 307 ms
13,572 KB
testcase_32 AC 306 ms
13,664 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int N;
int A[2<<17];
main()
{
	cin>>N;
	int INF=2e9;
	int ans=INF;
	set<int>L,R;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		R.insert(A[i]);
	}
	R.erase(A[0]);
	L.insert(A[0]);
	for(int i=1;i<N-1;i++)
	{
		R.erase(A[i]);
		set<int>::iterator it,jt;
		it=L.lower_bound(A[i]);
		jt=R.lower_bound(A[i]);
		if(it!=L.begin()&&jt!=R.begin())
		{
			ans=min(ans,A[i]+*L.begin()+*R.begin());
		}
		if(it!=L.end()&&jt!=R.end())
		{
			ans=min(ans,A[i]+*it+*jt);
		}
		L.insert(A[i]);
	}
	if(ans==INF)ans=-1;
	cout<<ans<<endl;
}
0