結果

問題 No.1867 Partitions and Inversions
ユーザー 👑 Nachia
提出日時 2022-03-04 22:39:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 73,916 KB
最終ジャッジ日時 2025-01-28 05:50:24
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33 TLE * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[3000];
int I[3001][3001];
int dp[3001] = {};
int ans[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]++;
    rep(r,N+1) for(int l=r-1; l>=0; l--) I[l][r] += I[l+1][r];
    rep(r,N+1) for(int l=r-1; l>=0; l--) I[l][r] += I[l][r-1];

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

    return 0;
}





struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0