이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define int ll
using namespace std;
const int N = 5e3 + 3,inf = 1e18;
int a[N],dp[N],id[N],b[N];
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin >> a[i],dp[i] = inf,id[a[i]] = i;
//neli
for (int i = 1; i <= n; i++){
for (int k = 1; k <= i; k++){
int cost = 0;
for (int j = 1; j <= n; j++)
if (a[j] > i) b[j] = 1;
else b[j] = 0;
//marcxniv ramdenia i-ze meti
for (int j = i; j >= i - k + 1; j--)
for (int w = 1; w <= id[j]; w++)
cost += b[w];
//anti inverse ebis raodenoba [i - k + 1, i] shualedshi
for (int j = 1; j <= n; j++)
b[j] = 0;
for (int j = i; j >= i - k + 1; j--){
b[id[j]] = 1;
for (int w = id[j] + 1; w <= n; w++)
cost += b[w];
}
dp[i] = min(dp[i],dp[i - k] + cost);
}
}
cout<<dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |