# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
699835 | bdl | Group Photo (JOI21_ho_t3) | C++17 | 292 ms | 98380 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
const int N = 5e3;
int main() {
int n;
scanf("%d", &n);
static int o[N + 1];
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
o[a] = i;
}
static int s[N + 1][N + 1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (i < j && o[i] > o[j]);
auto inv = [&](int i1, int i2, int j1, int j2) {
return s[i2][j2] - s[i1 - 1][j2] - s[i2][j1 - 1] + s[i1 - 1][j1 - 1];
};
auto ninv = [&](int i, int j) {
return (j - i + 1) * (j - i) / 2 - inv(i, j, i, j);
};
static int f[N + 1];
for (int i = 1; i <= n; i++) {
f[i] = ninv(1, i);
for (int j = 1; j < i; j++)
f[i] = min(f[i], f[j] + inv(1, j, j + 1, i) + ninv(j + 1, i));
}
printf("%d\n", f[n]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |