結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー SmitMangukiyaSmitMangukiya
提出日時 2020-06-26 21:54:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,505 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 168,492 KB
実行使用メモリ 11,116 KB
最終ジャッジ日時 2023-09-18 04:19:31
合計ジャッジ時間 3,531 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 31 ms
10,912 KB
testcase_24 AC 31 ms
10,952 KB
testcase_25 AC 31 ms
11,052 KB
testcase_26 AC 31 ms
11,048 KB
testcase_27 AC 32 ms
11,048 KB
testcase_28 AC 31 ms
10,916 KB
testcase_29 AC 31 ms
10,952 KB
testcase_30 AC 31 ms
10,916 KB
testcase_31 AC 31 ms
11,028 KB
testcase_32 AC 31 ms
11,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int get(int a , int b , int c){
   if(b > a && b > c){
      return a + b + c;
   }
   if(b < a && b < c){
      return a + b + c;
   }
   return inf64;
}

void solve(){
   int n;
   cin >> n;

   int a[n];
   f(i,0,n) cin >> a[i];

   vi ps(n) , pb(n) , ss(n) , sb(n);

   ps[0] = a[0];
   pb[0] = a[0];

   f(i,1,n){
      ps[i] = min(ps[i-1] , a[i]);
      pb[i] = max(pb[i-1] , a[i]);
   }

   ss[n-1] = a[n-1];
   sb[n-1] = a[n-1];

   rf(i,n-2,0){
      ss[i] = min(ss[i+1] , a[i]);
      sb[i] = max(sb[i+1] , a[i]);
   }

   int ans = inf64;

   f(i,1,n-1){
      ans = min(ans , get(ps[i-1] , a[i] , ss[i+1]));
      ans = min(ans , get(ps[i-1] , a[i] , sb[i+1]));
      ans = min(ans , get(pb[i-1] , a[i] , ss[i+1]));
      ans = min(ans , get(pb[i-1] , a[i] , sb[i+1]));
   }

   if(ans  > inf) ans = -1;
   cout << ans << "\n";
}

int32_t main(){
   fast;
   int t = 1;
   // cin >> t;
   while(t--)  solve();   
}
0