結果

問題 No.1867 Partitions and Inversions
ユーザー SSRSSSRS
提出日時 2022-03-04 23:43:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,096 bytes
コンパイル時間 5,057 ms
コンパイル使用メモリ 203,512 KB
実行使用メモリ 78,084 KB
最終ジャッジ日時 2023-09-26 03:06:39
合計ジャッジ時間 43,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 2 ms
4,504 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 27 ms
5,616 KB
testcase_39 AC 27 ms
5,616 KB
testcase_40 AC 27 ms
5,376 KB
testcase_41 AC 27 ms
5,368 KB
testcase_42 AC 27 ms
5,356 KB
testcase_43 AC 1,495 ms
34,492 KB
testcase_44 AC 1,497 ms
34,548 KB
testcase_45 AC 1,488 ms
34,572 KB
testcase_46 AC 1,523 ms
34,580 KB
testcase_47 AC 1,496 ms
34,760 KB
testcase_48 AC 1,496 ms
34,752 KB
testcase_49 AC 1,502 ms
34,708 KB
testcase_50 AC 1,507 ms
34,484 KB
testcase_51 AC 1,495 ms
34,460 KB
testcase_52 AC 1,552 ms
34,516 KB
testcase_53 AC 1,514 ms
34,484 KB
testcase_54 AC 1,496 ms
34,484 KB
testcase_55 AC 1,506 ms
34,712 KB
testcase_56 AC 1,513 ms
34,716 KB
testcase_57 AC 1,517 ms
34,576 KB
testcase_58 AC 1,499 ms
34,404 KB
testcase_59 AC 1,493 ms
34,544 KB
testcase_60 AC 1,507 ms
34,456 KB
testcase_61 AC 1,527 ms
34,552 KB
testcase_62 AC 1,855 ms
34,400 KB
testcase_63 TLE -
testcase_64 AC 2 ms
4,572 KB
testcase_65 AC 2 ms
4,384 KB
testcase_66 AC 1 ms
4,380 KB
testcase_67 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
    P[i]--;
  }
  vector<vector<int>> S(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      if (P[i] > P[j]){
        S[i][j + 1]++;
      }
    }
  }  
  for (int i = 0; i <= N; i++){
    for (int j = 0; j < N; j++){
      S[i][j + 1] += S[i][j];
    }
  }
  for (int i = N; i >= 1; i--){
    for (int j = 0; j <= N; j++){
      S[i - 1][j] += S[i][j];
    }
  }
  vector<int> mx(N + 1, 0);
  for (int i = 0; i <= N; i++){
    for (int j = i; j <= N; j++){
      mx[j - i] = max(mx[j - i], S[i][j]);
      S[i][j] *= -1;
    }
  }
  vector<vector<int>> dp(N + 1, vector<int>(N + 1, INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; i++){
    for (int j = i; j < N; j++){
      for (int k = j + 1; k <= N; k++){
        dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + S[j][k]);
      }
    }
  }
  for (int i = 1; i <= N; i++){
    cout << -S[0][N] + dp[i][N] << endl;
  }
}
0