結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー okok
提出日時 2020-06-26 21:51:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 95,524 KB
実行使用メモリ 14,296 KB
最終ジャッジ日時 2023-09-18 04:12:24
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 9 ms
4,376 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 383 ms
13,844 KB
testcase_24 AC 383 ms
14,212 KB
testcase_25 AC 386 ms
13,844 KB
testcase_26 AC 397 ms
13,944 KB
testcase_27 AC 390 ms
13,928 KB
testcase_28 AC 187 ms
13,852 KB
testcase_29 AC 185 ms
13,788 KB
testcase_30 AC 263 ms
13,808 KB
testcase_31 AC 255 ms
13,788 KB
testcase_32 AC 259 ms
14,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = INF;
	vector<int> A;
	map<int,int> mp;
	set<int> s1, s2;
	
	cin>>N;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		
		if(i){
			s2.insert(A[i]);
		}
	}
	
	for(int i = 1; i + 1 < N; i++){
		s1.insert(A[i-1]);
		s2.erase(A[i]);
		
		{
			auto it1 = s1.begin();
			auto it2 = s2.begin();
			
			if(it1 != s1.end() && it2 != s2.end() &&
				*it1 < A[i] && *it2 < A[i]
			) {
				ans = min(ans, *it1 + A[i] + *it2);
			}
		}
		
		{
			auto it1 = s1.upper_bound(A[i]);
			auto it2 = s2.upper_bound(A[i]);
			
			if(it1 != s1.end() && it2 != s2.end() &&
				*it1 > A[i] && *it2 > A[i]
			) {
				ans = min(ans, *it1 + A[i] + *it2);
			}
		}
		
	}
	
	if(ans != INF) cout<<ans<<endl;
	else cout<<-1<<endl;
	
	return 0;
}
0