結果

問題 No.1077 Noelちゃんと星々4
ユーザー rxoxixyxdrxoxixyxd
提出日時 2020-06-12 21:52:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,383 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 167,756 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 10:17:07
合計ジャッジ時間 2,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

ll calc(vector<int>& a) {
  ll ans = 0;
  int n = a.size();
  for (int i = 0; i < a.size()-2; i++) {
    if (a[i] < a[i+1] && a[i+1] > a[i+2]) {  // a < b > c -> b を max(a,c) にする
      ans += a[i+1] - max(a[i], a[i+2]);
      a[i+1] = max(a[i], a[i+2]);
    } else if (a[i] > a[i+1]) {
      ans += a[i] - a[i+1];
      a[i+1] = a[i];
    }
  }
  if (a[n-1] < a[n-2]) {
    ans += a[n-2] - a[n-1];
    a[n-1] = a[n-2];
  }
  return ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll ans = INFLL;
  for (int i = 0; i < 1000; i++) {
    auto b = a;
    ll tmp = i;
    b[0] -= i;
    tmp += calc(b);
    chmin(ans, tmp);
  }


  cout << ans << endl;

  return 0;
}
0