結果

問題 No.711 競技レーティング単調増加
ユーザー しらっ亭しらっ亭
提出日時 2017-05-23 00:49:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 923 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 179,248 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 14:24:40
合計ジャッジ時間 6,157 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// O(n^2) のTLE解を unordered_map にして、定数倍高速化したやつ
#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];

  unordered_map<int, int> q1, q2;
  auto &cur = q1;
  auto &nex = q2;

  cur[0] = 0;

  for (int i = 0; i < n; i++) {
    for (auto cl : cur) {
      int c = cl.first;
      int l = cl.second;

      if (l < A[i]) {
        if (nex.count(c) == 0 || nex[c] > A[i]) {
          nex[c] = A[i];
        }
      }
      if (nex.count(c + 1) == 0 || nex[c + 1] > l + 1) {
        nex[c + 1] = l + 1;
      }
    }
    swap(cur, nex);
    nex.clear();
  }

  int ans = 1e9;
  for (auto cl : cur) {
    ans = min(ans, cl.first);
  }
  return ans;
  //return cur.begin()->fst;  // mapならこちら
}

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