Submission #921400

# Submission time Handle Problem Language Result Execution time Memory
921400 2024-02-03T18:57:12 Z TAhmed33 Group Photo (JOI21_ho_t3) C++
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
int n, a[5001], dp[5001], pos[501];
int main () {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		dp[i] = 1e9;
		int sze = 0;
		memset(pos, 0, sizeof(pos));
		for (int j = 1; j <= n; j++) {
			if (a[j] <= i) {
				pos[a[j]] = ++sze;
			}
		}
		for (int j = i; j >= 1; j--) {
			int sum = 0;
			int cnt = j;
			for (int l = i; l >= j; l--) {
				sum += abs(cnt - pos[l]);
				cnt++;
			}
			sum += dp[j - 1];
			dp[i] = min(dp[i], sum);
		}
	}
	//for (int i = 1; i <= n; i++) cout << dp[i] << " ";
	//cout << '\n';
	cout << dp[n] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -