結果
| 問題 | 
                            No.1095 Smallest Kadomatsu Subsequence
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-06-26 21:24:42 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 334 ms / 2,000 ms | 
| コード長 | 589 bytes | 
| コンパイル時間 | 718 ms | 
| コンパイル使用メモリ | 76,032 KB | 
| 実行使用メモリ | 13,568 KB | 
| 最終ジャッジ日時 | 2024-07-04 19:35:30 | 
| 合計ジャッジ時間 | 4,775 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~
            
            ソースコード
#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;
}