結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー NewGardenNewGarden
提出日時 2020-06-27 20:46:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 517 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 173,472 KB
実行使用メモリ 13,212 KB
最終ジャッジ日時 2023-09-19 09:34:11
合計ジャッジ時間 7,691 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 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 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 12 ms
4,376 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 517 ms
13,036 KB
testcase_24 AC 511 ms
13,056 KB
testcase_25 AC 490 ms
13,080 KB
testcase_26 AC 498 ms
13,084 KB
testcase_27 AC 506 ms
13,196 KB
testcase_28 AC 232 ms
13,208 KB
testcase_29 AC 236 ms
13,148 KB
testcase_30 AC 342 ms
13,080 KB
testcase_31 AC 335 ms
13,212 KB
testcase_32 AC 340 ms
13,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> c(n);
  set<int> str,stl;
  rep(i,n){
    cin >> c[i];
    str.insert(c[i]);
  }
  int ans = inf;
  stl.insert(c[0]);
  str.erase(c[0]);
  REP(i,1,n-1){
    str.erase(c[i]);
    auto posl = stl.lower_bound(c[i]);
    auto posr = str.lower_bound(c[i]);
    if(posl!=stl.begin() && posr!=str.begin()){
      ans = min(ans, c[i]+*stl.begin()+*str.begin());
    }
    if(posl!=stl.end() && posr!=str.end()){
      ans = min(ans, c[i]+*posl+*posr);
    }
    stl.insert(c[i]);
  }
  if(ans==inf) ans = -1;
  cout << ans << ln;
  return 0;
}
0