답안 #378387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378387 2021-03-16T16:07:48 Z astoria Group Photo (JOI21_ho_t3) C++14
100 / 100
431 ms 98568 KB
#include "bits/stdc++.h"
using namespace std;

int mn(int i, int j){
	if(i!=-1&&j!=-1) return min(i,j);
	else return max(i,j);
}

int main() {
	int n; cin>>n;
	int h[n+5];
	for(int i=0; i<n; i++){ cin>>h[i]; h[i]=h[i]-1;}
	int ord[n+5];
	for(int i=0; i<n; i++) ord[h[i]] = i;

	int supp[n+5][n+5];  //cntup[pos][num] = count #(position > pos && number >= num)
	memset(supp,0,sizeof(supp));
	for(int j=n-1; j>=1; j--) {
		for(int i=0; i<=h[j]; i++) supp[j-1][i]=supp[j][i]+1;
		for(int i=h[j]+1; i<=n; i++) supp[j-1][i]=supp[j][i];
	}

	int dp[n+5]; memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	for(int i=1; i<=n; i++) {
		int trans=0;
		for(int j=i-1; j>=0; j--){
			trans += (supp[ord[j]][j]-(2*supp[ord[j]][i])+(n-i));
			dp[i]=mn(dp[i],dp[j]+trans);
		}
	}
	cout<<dp[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 5 ms 2944 KB Output is correct
32 Correct 4 ms 2796 KB Output is correct
33 Correct 4 ms 2796 KB Output is correct
34 Correct 4 ms 2796 KB Output is correct
35 Correct 5 ms 2796 KB Output is correct
36 Correct 4 ms 2796 KB Output is correct
37 Correct 6 ms 2796 KB Output is correct
38 Correct 4 ms 2796 KB Output is correct
39 Correct 5 ms 2796 KB Output is correct
40 Correct 4 ms 2796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 5 ms 2944 KB Output is correct
32 Correct 4 ms 2796 KB Output is correct
33 Correct 4 ms 2796 KB Output is correct
34 Correct 4 ms 2796 KB Output is correct
35 Correct 5 ms 2796 KB Output is correct
36 Correct 4 ms 2796 KB Output is correct
37 Correct 6 ms 2796 KB Output is correct
38 Correct 4 ms 2796 KB Output is correct
39 Correct 5 ms 2796 KB Output is correct
40 Correct 4 ms 2796 KB Output is correct
41 Correct 391 ms 98284 KB Output is correct
42 Correct 396 ms 98284 KB Output is correct
43 Correct 431 ms 98412 KB Output is correct
44 Correct 404 ms 98540 KB Output is correct
45 Correct 406 ms 98540 KB Output is correct
46 Correct 403 ms 98540 KB Output is correct
47 Correct 394 ms 98540 KB Output is correct
48 Correct 404 ms 98412 KB Output is correct
49 Correct 398 ms 98560 KB Output is correct
50 Correct 408 ms 98540 KB Output is correct
51 Correct 419 ms 98568 KB Output is correct
52 Correct 404 ms 98432 KB Output is correct
53 Correct 398 ms 98432 KB Output is correct
54 Correct 393 ms 98444 KB Output is correct
55 Correct 398 ms 98540 KB Output is correct