이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5005;
int n, q, a[N], inv[N][N], invr[N][N], S[N], Dp[N];
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = a[i]; j <= n; ++j) {
++S[j];
}
for (int x = a[i] + 1; x <= n; ++x) {
inv[a[i]][x] = S[n] - S[x - 1];
invr[a[i]][x] = (x - a[i]) - (S[x] - S[a[i]]);
}
}
ll U;
for (int r = 1; r <= n; ++r) {
Dp[r] = 1e9, U = 0;
for (int l = r; l >= 1; --l) {
U += inv[l][r + 1] + invr[l][r];
if (Dp[r] > Dp[l - 1] + U)
Dp[r] = Dp[l - 1] + U;
}
}
cout << Dp[n] << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:11:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main () {
| ^
# | 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... |