結果
問題 |
No.1867 Partitions and Inversions
|
ユーザー |
👑 ![]() |
提出日時 | 2022-03-04 22:38:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,064 bytes |
コンパイル時間 | 626 ms |
コンパイル使用メモリ | 74,524 KB |
最終ジャッジ日時 | 2025-01-28 05:45:01 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 21 TLE * 13 OLE * 31 |
ソースコード
#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]; rep(l,N+1){ rep(r,N+1) cout << I[l][r] << " "; cout << endl; } cout << endl; 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;