結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー NeccoliniNeccolini
提出日時 2020-09-30 00:57:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,257 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 168,120 KB
実行使用メモリ 8,036 KB
最終ジャッジ日時 2023-09-18 03:49:24
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 5 ms
4,384 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 4 ms
4,376 KB
testcase_23 AC 74 ms
8,036 KB
testcase_24 AC 74 ms
7,780 KB
testcase_25 AC 74 ms
7,728 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 75 ms
7,820 KB
testcase_29 AC 74 ms
7,824 KB
testcase_30 AC 73 ms
7,820 KB
testcase_31 AC 74 ms
7,892 KB
testcase_32 AC 74 ms
7,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 998244353;
inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int n;
VI a;

int main(){
   cin>>n;
   a.resize(n);
   rep(i,n)cin>>a[i];
   VI L(n+1),R(n+1);
   L[0]=INFTY,R[n]=INFTY;
   rep(i,n)L[i+1]=min(L[i],a[i]);
   for(int i=n-1;i>=0;i--){
      R[i]=min(R[i+1],a[i]);
   }
   ll ans=INFTY;
   for(int i=1;i<n-1;i++){
      ll sum=L[i]+a[i]+R[i+1];
      if(L[i]<a[i] && a[i]>R[i+1])chmin(ans,sum);
   }
   if(ans>=INFTY)cout<<-1<<endl;
   else cout<<ans<<endl;
}
0