結果

問題 No.1095 Smallest Kadomatsu Subsequence
コンテスト
ユーザー 🍮かんプリン
提出日時 2020-06-26 21:26:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 626 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 160,408 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 19:38:23
合計ジャッジ時間 3,028 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 2 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n;cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 1000000000;
    for (int i = 0; i < n-2; i++)
    {
        if (a[i] < a[i + 1] && a[i + 1] > a[i + 2]) {
            ans = min(ans,a[i] + a[i + 1] + a[i +2]);
        }
        else if (a[i] > a[i + 1] && a[i + 1] < a[i + 2]) {
            ans = min(ans,a[i] + a[i  +1] + a[i  +2]);
        }
    }
    if (ans == 1000000000) {
        cout<< -1 << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}
0