結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー RR SinghRR Singh
提出日時 2020-06-27 19:02:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,185 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 166,016 KB
実行使用メモリ 11,292 KB
最終ジャッジ日時 2023-09-19 07:25:58
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define hell 1000000007
#define PI acos(-1.0)
#define S second
#define F first
#define pb push_back
#define endl '\n'
#define lli long long int
#define li long int
#define ld long double
#define all(v) v.begin(), v.end()
 
#define run(j, n) for(auto ii=j;ii!=n;ii++)
#define out(j, n) for(auto ii=j;ii!=n;ii++) cout<<(*ii)<<" ";
#define sout(ar, i, n) for(int j=i;j<n;j++) cout<<ar[j]<<" ";
 

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(11);
 
int n;cin>>n;
lli ar[n];run(0, n) cin>>ar[ii];

lli v1[2][n], v2[2][n];
v1[0][0]=ar[0];
v1[1][0]=ar[0];  

v2[0][n-1]=ar[n-1];
v2[1][n-1]=ar[n-1];
for(int i=1;i<n;i++)
{
  v1[0][i]=min(v1[0][i-1], ar[i]);
  v1[1][i]=max(v1[1][i-1], ar[i]);

}


for(int i=n-2;i>=0;i--)
{
  v2[0][i]=min(v2[0][i+1], ar[i]);
  v2[1][i]=max(v2[1][i+1], ar[i]);
}



lli ans = LLONG_MAX;

for(int i=0;i<n;i++)
{
  if(ar[i]!=v1[0][i] && ar[i]!=v2[0][i])
  {
    ans = min(ans, ar[i]+v1[0][i]+v2[0][i]);
  }
  if(ar[i]!=v1[1][i] && ar[i]!=v2[1][i])
  {
    ans = min(ans, ar[i]+v1[1][i]+v2[1][i]);
  }
}
if(ans==LLONG_MAX) ans = -1;
cout<<ans;
return 0;
}
0