結果

問題 No.1867 Partitions and Inversions
ユーザー SSRSSSRS
提出日時 2022-03-04 23:50:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,611 ms / 5,000 ms
コード長 988 bytes
コンパイル時間 3,762 ms
コンパイル使用メモリ 222,332 KB
実行使用メモリ 38,892 KB
最終ジャッジ日時 2023-09-26 03:16:21
合計ジャッジ時間 63,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1,528 ms
38,808 KB
testcase_03 AC 1,467 ms
38,760 KB
testcase_04 AC 1,502 ms
38,704 KB
testcase_05 AC 1,574 ms
38,740 KB
testcase_06 AC 1,562 ms
38,708 KB
testcase_07 AC 1,533 ms
38,584 KB
testcase_08 AC 1,510 ms
38,888 KB
testcase_09 AC 1,443 ms
38,648 KB
testcase_10 AC 1,417 ms
38,684 KB
testcase_11 AC 1,472 ms
38,692 KB
testcase_12 AC 1,484 ms
38,576 KB
testcase_13 AC 1,510 ms
38,596 KB
testcase_14 AC 1,448 ms
38,696 KB
testcase_15 AC 1,462 ms
38,892 KB
testcase_16 AC 1,517 ms
38,600 KB
testcase_17 AC 1,611 ms
38,644 KB
testcase_18 AC 1,563 ms
38,596 KB
testcase_19 AC 1,547 ms
38,720 KB
testcase_20 AC 1,578 ms
38,720 KB
testcase_21 AC 1,518 ms
38,888 KB
testcase_22 AC 1,589 ms
38,676 KB
testcase_23 AC 1,520 ms
38,864 KB
testcase_24 AC 1,431 ms
38,692 KB
testcase_25 AC 1,482 ms
38,648 KB
testcase_26 AC 1,419 ms
38,592 KB
testcase_27 AC 1,439 ms
38,688 KB
testcase_28 AC 1,444 ms
38,676 KB
testcase_29 AC 1,464 ms
38,792 KB
testcase_30 AC 1,453 ms
38,844 KB
testcase_31 AC 1,562 ms
38,788 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 8 ms
4,384 KB
testcase_39 AC 8 ms
4,380 KB
testcase_40 AC 8 ms
4,484 KB
testcase_41 AC 8 ms
4,380 KB
testcase_42 AC 8 ms
4,388 KB
testcase_43 AC 430 ms
19,000 KB
testcase_44 AC 420 ms
19,112 KB
testcase_45 AC 426 ms
19,064 KB
testcase_46 AC 423 ms
19,088 KB
testcase_47 AC 419 ms
19,300 KB
testcase_48 AC 423 ms
19,008 KB
testcase_49 AC 424 ms
19,104 KB
testcase_50 AC 410 ms
19,000 KB
testcase_51 AC 419 ms
19,104 KB
testcase_52 AC 424 ms
19,200 KB
testcase_53 AC 420 ms
19,204 KB
testcase_54 AC 431 ms
18,988 KB
testcase_55 AC 431 ms
18,988 KB
testcase_56 AC 429 ms
18,992 KB
testcase_57 AC 421 ms
19,060 KB
testcase_58 AC 418 ms
19,276 KB
testcase_59 AC 420 ms
19,088 KB
testcase_60 AC 419 ms
19,148 KB
testcase_61 AC 428 ms
19,180 KB
testcase_62 AC 419 ms
19,004 KB
testcase_63 AC 1,456 ms
38,696 KB
testcase_64 AC 2 ms
4,376 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 2 ms
4,376 KB
testcase_67 AC 1,495 ms
38,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#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> dp(N + 1, -INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++){
    vector<int> dp2(N + 1, -INF);
    for (int j = i; j < N; j++){
      for (int k = j + 1; k <= N; k++){
        dp2[k] = max(dp2[k], dp[j] + S[j][k]);
      }
    }
    cout << S[0][N] - dp2[N] << endl;
    swap(dp, dp2);
  }
}
0