답안 #574323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
574323 2022-06-08T10:23:59 Z benson1029 Group Photo (JOI21_ho_t3) C++14
100 / 100
356 ms 67540 KB
#include<bits/stdc++.h>
using namespace std;

int n;
int a[5005];
int par[5005][5005];
int dp[5005];

int main() {
	cin >> n;
	for(int i=1; i<=n; i++) cin >> a[i];
	
	int ans = 0;
	for(int i=1; i<=n; i++) {
		for(int j=i+1; j<=n; j++) {
			if(a[i] > a[j]) {
				par[a[j]][a[i]]++;
				ans++;
			}
		}
	}
	
	for(int l=0; l<n; l++) {
		for(int i=1; i<=n-l; i++) {
			int j = i+l;
			par[i][j] += par[i+1][j] + par[i][j-1] - par[i+1][j-1];
		}
	}
	
	for(int i=1; i<=n; i++) {
		dp[i] = -1e9;
		for(int j=0; j<i; j++) {
			dp[i] = max(dp[i], dp[j] + 2*par[j+1][i] - (i-j)*(i-j-1)/2);
		}
	}
	
	cout << ans-dp[n] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1076 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1068 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1076 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1068 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 5 ms 4692 KB Output is correct
32 Correct 4 ms 4788 KB Output is correct
33 Correct 4 ms 4692 KB Output is correct
34 Correct 6 ms 4692 KB Output is correct
35 Correct 5 ms 4692 KB Output is correct
36 Correct 5 ms 4692 KB Output is correct
37 Correct 5 ms 4688 KB Output is correct
38 Correct 5 ms 4692 KB Output is correct
39 Correct 5 ms 4692 KB Output is correct
40 Correct 5 ms 4788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 1076 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1068 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 5 ms 4692 KB Output is correct
32 Correct 4 ms 4788 KB Output is correct
33 Correct 4 ms 4692 KB Output is correct
34 Correct 6 ms 4692 KB Output is correct
35 Correct 5 ms 4692 KB Output is correct
36 Correct 5 ms 4692 KB Output is correct
37 Correct 5 ms 4688 KB Output is correct
38 Correct 5 ms 4692 KB Output is correct
39 Correct 5 ms 4692 KB Output is correct
40 Correct 5 ms 4788 KB Output is correct
41 Correct 313 ms 67216 KB Output is correct
42 Correct 345 ms 67276 KB Output is correct
43 Correct 304 ms 67284 KB Output is correct
44 Correct 323 ms 67308 KB Output is correct
45 Correct 302 ms 67308 KB Output is correct
46 Correct 319 ms 67540 KB Output is correct
47 Correct 313 ms 67312 KB Output is correct
48 Correct 316 ms 67216 KB Output is correct
49 Correct 310 ms 67236 KB Output is correct
50 Correct 310 ms 67404 KB Output is correct
51 Correct 356 ms 67328 KB Output is correct
52 Correct 324 ms 67324 KB Output is correct
53 Correct 342 ms 67236 KB Output is correct
54 Correct 311 ms 67432 KB Output is correct
55 Correct 339 ms 67428 KB Output is correct