結果

問題 No.1867 Partitions and Inversions
ユーザー 👑 NachiaNachia
提出日時 2022-03-04 23:58:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,434 ms / 5,000 ms
コード長 784 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 82,876 KB
実行使用メモリ 38,608 KB
最終ジャッジ日時 2023-09-26 03:41:01
合計ジャッジ時間 121,817 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3,064 ms
38,580 KB
testcase_03 AC 3,050 ms
38,292 KB
testcase_04 AC 3,105 ms
38,348 KB
testcase_05 AC 3,011 ms
38,348 KB
testcase_06 AC 3,060 ms
38,584 KB
testcase_07 AC 2,980 ms
38,324 KB
testcase_08 AC 3,128 ms
38,380 KB
testcase_09 AC 3,141 ms
38,340 KB
testcase_10 AC 3,178 ms
38,324 KB
testcase_11 AC 3,190 ms
38,288 KB
testcase_12 AC 3,156 ms
38,304 KB
testcase_13 AC 3,017 ms
38,292 KB
testcase_14 AC 3,158 ms
38,292 KB
testcase_15 AC 3,063 ms
38,568 KB
testcase_16 AC 3,160 ms
38,344 KB
testcase_17 AC 3,112 ms
38,348 KB
testcase_18 AC 3,208 ms
38,352 KB
testcase_19 AC 3,191 ms
38,288 KB
testcase_20 AC 3,165 ms
38,308 KB
testcase_21 AC 3,048 ms
38,320 KB
testcase_22 AC 3,123 ms
38,324 KB
testcase_23 AC 3,096 ms
38,372 KB
testcase_24 AC 3,157 ms
38,472 KB
testcase_25 AC 3,120 ms
38,304 KB
testcase_26 AC 3,220 ms
38,296 KB
testcase_27 AC 3,184 ms
38,344 KB
testcase_28 AC 3,189 ms
38,380 KB
testcase_29 AC 3,147 ms
38,608 KB
testcase_30 AC 3,108 ms
38,324 KB
testcase_31 AC 3,135 ms
38,332 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 16 ms
8,696 KB
testcase_39 AC 17 ms
8,508 KB
testcase_40 AC 16 ms
8,440 KB
testcase_41 AC 17 ms
8,516 KB
testcase_42 AC 17 ms
8,420 KB
testcase_43 AC 886 ms
27,888 KB
testcase_44 AC 887 ms
28,164 KB
testcase_45 AC 883 ms
27,868 KB
testcase_46 AC 889 ms
27,960 KB
testcase_47 AC 891 ms
27,908 KB
testcase_48 AC 882 ms
28,068 KB
testcase_49 AC 873 ms
27,892 KB
testcase_50 AC 889 ms
27,880 KB
testcase_51 AC 895 ms
27,968 KB
testcase_52 AC 880 ms
28,064 KB
testcase_53 AC 878 ms
27,868 KB
testcase_54 AC 892 ms
27,868 KB
testcase_55 AC 887 ms
27,956 KB
testcase_56 AC 886 ms
27,908 KB
testcase_57 AC 878 ms
27,928 KB
testcase_58 AC 898 ms
27,868 KB
testcase_59 AC 890 ms
27,864 KB
testcase_60 AC 889 ms
27,960 KB
testcase_61 AC 879 ms
27,868 KB
testcase_62 AC 895 ms
27,872 KB
testcase_63 AC 3,237 ms
38,296 KB
testcase_64 AC 1 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 1 ms
4,380 KB
testcase_67 AC 3,434 ms
30,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i64 = long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


int N;
int P[3001];
int I[3001][3001];
int dp[3001] = {};

int main(){
	int N; cin >> N;
	rep(i,N){ cin >> P[i]; P[i]--; }
	rep(i,N) rep(j,i) if(P[j] > P[i]) I[j][i+1]++;
	for(int l=N; l>=0; l--) for(int r=l+1; r<=N; r++) I[l][r] += I[l+1][r];
	for(int l=N; l>=0; l--) for(int r=l+1; r<=N; r++) I[l][r] += I[l][r-1];

	for(int k=0; k<N; k++){
	    const int n = N-k;
		for(int l=0; l<n; l++){
			dp[l] = 0;
			for(int r=l+1; r<=n; r++){
				dp[l] = max(dp[l], dp[r] + I[l][r]);
			}
		}
		cout << (I[0][N] - dp[0]) << '\n';
	}

	return 0;
}
0