結果

問題 No.2036 Max Middle
ユーザー simansiman
提出日時 2022-08-15 15:04:07
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,139 bytes
コンパイル時間 1,187 ms
コンパイル使用メモリ 144,104 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-10 02:10:26
合計ジャッジ時間 5,102 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

struct Node {
  int idx;
  int v;

  Node(int idx = -1, int v = -1) {
    this->idx = idx;
    this->v = v;
  }

  bool operator>(const Node &n) const {
    return v < n.v;
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  priority_queue <Node, vector<Node>, greater<Node>> pque;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (1 <= i && i <= N - 2) {
      pque.push(Node(i, A[i]));
    }
  }

  int ans = 0;

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();

    int left = node.idx - 1;
    int right = node.idx + 1;
    // fprintf(stderr, "(%d, %d, %d)\n", A[left], A[node.idx], A[right]);

    if (A[left] < A[node.idx] && A[node.idx] > A[right]) {
      int nv = min(A[left], A[right]) - 1;
      A[node.idx] = nv;
      ++ans;
      pque.push(Node(node.idx, nv));
    }
  }

  cout << ans << endl;

  return 0;
}
0