제출 #1174374

#제출 시각아이디문제언어결과실행 시간메모리
1174374Hamed_GhaffariGroup Photo (JOI21_ho_t3)C++20
100 / 100
61 ms492 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define all(x) x.begin(), x.end() #define pb push_back const int MXN = 5005; int n, inv[MXN], pos[MXN], a[MXN], dp[MXN]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=n-1; i>=1; i--) { int lst=0; for(int j=1; j<=n; j++) if(a[j]>=i) pos[a[j]] = lst++; for(int j=i+1; j<=n; j++) if(pos[j]<pos[i]) inv[j]++; int cur=0; dp[i] = 2e9; for(int j=i; j<=n; j++) { cur += pos[j] - inv[j]; dp[i] = min(dp[i], cur+dp[j+1]); } } cout << dp[1] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...