結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー forest3forest3
提出日時 2020-06-28 16:43:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 167,100 KB
実行使用メモリ 8,040 KB
最終ジャッジ日時 2023-09-22 03:46:39
合計ジャッジ時間 4,106 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 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 4 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 74 ms
7,772 KB
testcase_24 AC 75 ms
8,040 KB
testcase_25 AC 75 ms
7,728 KB
testcase_26 AC 75 ms
7,896 KB
testcase_27 AC 74 ms
7,912 KB
testcase_28 AC 74 ms
7,772 KB
testcase_29 AC 74 ms
7,724 KB
testcase_30 AC 75 ms
7,728 KB
testcase_31 AC 74 ms
7,844 KB
testcase_32 AC 74 ms
7,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	const long long INF = INT64_MAX / 2;
	vector<long long> mib( N );
	long long mi = INF;
	for( int i = 0; i < N; i++ ) {
		mi = min( mi, A[i] );
		mib[i] = mi;
	}
	vector<long long> mia( N );
	mi = INF;
	for( int i = N - 1; i >= 0; i-- ) {
		mi = min( mi, A[i] );
		mia[i] = mi;
	}
	long long ans = INF;
	for( int i = 1; i < N - 1; i++ ) {
		long long n = A[i];
		if( mib[i - 1] > n && mia[i + 1] > n ) {
			n += mib[i - 1] + mia[i + 1];
		}
		else if( mib[i - 1] < n && mia[i + 1] < n ) {
			n += mib[i - 1] + mia[i + 1];
		}
		else continue;
		ans = min( ans, n );
	}
	if( ans == INF ) ans = -1;

	cout << ans << endl;
}
0