結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー FUN_era1FUN_era1
提出日時 2020-06-26 23:02:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,948 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 94,376 KB
実行使用メモリ 12,820 KB
最終ジャッジ日時 2023-09-18 07:10:14
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 4 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 4 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 79 ms
12,284 KB
testcase_24 AC 79 ms
12,768 KB
testcase_25 AC 79 ms
12,600 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 72 ms
6,188 KB
testcase_29 AC 71 ms
6,208 KB
testcase_30 AC 79 ms
12,628 KB
testcase_31 AC 78 ms
12,240 KB
testcase_32 AC 79 ms
12,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e18
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;



int main(){
   int n;
   cin >> n;
   ll res = INF;
   vector<ll> a(n), sa(n);
   
   bool f = true;
   int up = 0, down = 0;
   rep(i, n){
      cin >> a[i];
      if(i == 0)continue;
      if(a[i - 1] > a[i])down++;
      if(a[i - 1] < a[i])up++;
   }
   if(down == 0 || up == 0){
      cout << -1 << endl;
      return 0;
   }



   vector<ll> max_l(n), max_r(n), min_l(n), min_r(n);
   rep(i, n){
      if(i == 0){
         //max_l[i] = a[i];
         min_l[i] = a[i];
      }
      else {
         //max_l[i] = max(max_l[i - 1], a[i]);
         min_l[i] = min(min_l[i - 1], a[i]);
      }
   }
   reverse(ALL(a));
   rep(i, n){
      if(i == 0){
         //max_r[i] = a[i];
         min_r[i] = a[i];
      }
      else {
         //max_r[i] = max(max_r[i - 1], a[i]);
         min_r[i] = min(min_r[i - 1], a[i]);
      }
   }

   reverse(ALL(a));
   REP(i, 1, n - 2){
      ll am = INF, aM = INF;
      if(a[i] > min_l[i - 1] && a[i] > min_r[n - i - 2])am = a[i] + min_l[i - 1] + min_r[n - i - 2];
      //if(a[i] < max_l[i - 1] && a[i] < max_r[n - i - 1])aM = a[i] + max_l[i - 1] + max_r[n - i - 1];
      res = min({res, am, aM});
   }
   cout << res << endl;
}
0