結果

問題 No.711 競技レーティング単調増加
ユーザー しらっ亭しらっ亭
提出日時 2017-05-25 04:11:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,133 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 170,072 KB
実行使用メモリ 9,756 KB
最終ジャッジ日時 2023-10-19 22:52:49
合計ジャッジ時間 6,696 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 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解
#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 + 1e6;
  vector<int> dp1(n+1), dp2(n+1);
  vector<int> &cur = dp1;
  vector<int> &nex = dp2;

  // dp[i][j] : A[i-1] までを狭義単調増加にするのに j 手かけたときの、A[i-1]の最小値。できないときは inf
  // cur = dp[i], nex = dp[i+1] です
  cur[0] = 0;

  for (int i = 0; i < n; i++) {
    fill(nex.begin(), nex.end(), inf);
    for (int j = 0; j < i + 1; j++) {
      if (cur[j] >= inf) continue;
      if (cur[j] < A[i]) {
        // dp[i][j] に A[i] を継ぎ足す
        nex[j] = min(nex[j], A[i]);
      }
      // dp[i][j] に A[i] を操作したものを継ぎ足す
      nex[j+1] = min(nex[j+1], cur[j] + 1);
    }
    swap(cur, nex);
  }

  for (int j = 0; j < n; j++) {
    if (cur[j] < inf) {
      // j 手でできていれば、それが答え
      return j;
    }
  }
  assert(false);
}

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