結果

問題 No.711 競技レーティング単調増加
ユーザー しらっ亭
提出日時 2017-05-23 00:48:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 978 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 177,028 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-09-19 10:30:59
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 1 TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

// O(n^2) のTLE解を枝刈りしたやつ。まあまあ早い
#include <bits/stdc++.h>
using namespace std;

int solve() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];

  const int inf = 1e9;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q1, q2;
  auto &cur = q1;
  auto &nex = q2;

  cur.emplace(0, 0);

  for (int i = 0; i < n; i++) {
    int las = inf;
    int pre = inf;
    while (!cur.empty()) {
      int c, l;
      tie(c, l) = cur.top();
      cur.pop();

      if (l > pre) continue;
      pre = l;

      if (l < A[i]) {
        if (A[i] < las) {
          nex.emplace(c, A[i]);
          las = A[i];
        }
      }
      if (l + 1 < las) {
        nex.emplace(c + 1, l + 1);
        las = l + 1;
      }
    }
    swap(cur, nex);
  }

  int ans = cur.top().first;

  return ans;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cout << solve() << endl;
  return 0;
}
0