Submission #961114

# Submission time Handle Problem Language Result Execution time Memory
961114 2024-04-11T14:06:41 Z happy_node Group Photo (JOI21_ho_t3) C++17
64 / 100
5000 ms 98320 KB
#include <bits/stdc++.h>
using namespace std;

const int MX=5005;

int N;
int H[MX], dp[MX], cnt[MX][MX], curCnt[MX], pos[MX];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin>>N;
	for(int i=1;i<=N;i++) cin>>H[i];

	for(int i=1;i<=N;i++) dp[i]=1e9;

	for(int i=1;i<=N;i++) {
		pos[H[i]]=i;
		for(int j=H[i];j<=N;j++) curCnt[j]++;
		for(int j=1;j<=N;j++) cnt[i][j]=curCnt[j];
	}

	for(int i=0;i<=N;i++) {
		for(int k=i+1;k<=N;k++) {
			int cost=0;
			for(int j=k;j>i;j--) {
				int cur=0;
				cur+=cnt[pos[j]][N];
				cur-=cnt[pos[j]][k];
				cur+=cnt[pos[j]][j-1];
				cur-=cnt[pos[j]][i];

				cost+=cur;
			}
			dp[k]=min(dp[k],dp[i]+cost);
		}
	}

	cout<<dp[N]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2480 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2480 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2480 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 4 ms 4444 KB Output is correct
22 Correct 4 ms 4444 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 4 ms 4700 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 5 ms 4444 KB Output is correct
29 Correct 3 ms 4444 KB Output is correct
30 Correct 3 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2480 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 4 ms 4444 KB Output is correct
22 Correct 4 ms 4444 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 4 ms 4700 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 5 ms 4444 KB Output is correct
29 Correct 3 ms 4444 KB Output is correct
30 Correct 3 ms 4444 KB Output is correct
31 Correct 222 ms 16936 KB Output is correct
32 Correct 237 ms 16944 KB Output is correct
33 Correct 217 ms 16728 KB Output is correct
34 Correct 220 ms 16732 KB Output is correct
35 Correct 235 ms 16984 KB Output is correct
36 Correct 217 ms 16948 KB Output is correct
37 Correct 216 ms 16728 KB Output is correct
38 Correct 218 ms 16944 KB Output is correct
39 Correct 224 ms 16732 KB Output is correct
40 Correct 236 ms 16944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2480 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 4 ms 4444 KB Output is correct
22 Correct 4 ms 4444 KB Output is correct
23 Correct 4 ms 4444 KB Output is correct
24 Correct 4 ms 4700 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 5 ms 4444 KB Output is correct
28 Correct 5 ms 4444 KB Output is correct
29 Correct 3 ms 4444 KB Output is correct
30 Correct 3 ms 4444 KB Output is correct
31 Correct 222 ms 16936 KB Output is correct
32 Correct 237 ms 16944 KB Output is correct
33 Correct 217 ms 16728 KB Output is correct
34 Correct 220 ms 16732 KB Output is correct
35 Correct 235 ms 16984 KB Output is correct
36 Correct 217 ms 16948 KB Output is correct
37 Correct 216 ms 16728 KB Output is correct
38 Correct 218 ms 16944 KB Output is correct
39 Correct 224 ms 16732 KB Output is correct
40 Correct 236 ms 16944 KB Output is correct
41 Execution timed out 5043 ms 98320 KB Time limit exceeded
42 Halted 0 ms 0 KB -