Submission #429191

# Submission time Handle Problem Language Result Execution time Memory
429191 2021-06-15T18:33:30 Z Berted Coin Collecting (JOI19_ho_t4) C++14
37 / 100
71 ms 34724 KB
#include <iostream>
#include <algorithm>
#define pii pair<int, int>
#define fst first
#define snd second
#define ll long long

using namespace std;

const ll INF = 1e18;

int N;
pii A[100001];
ll DP[2001][1001];

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < 2 * N; i++) cin >> A[i].fst >> A[i].snd;
	sort(A, A + 2 * N);
	
	for (int i = 1; i <= N; i++) DP[0][i] = INF;
	DP[0][0] = 0;

	for (int i = 1; i <= 2 * N; i++)
	{
		for (int j = 0; j <= N; j++) DP[i][j] = INF;
		for (int j = max(0, i - N); j <= i && j <= N; j++)
		{
			DP[i][j] = min(DP[i][j], DP[i - 1][j] + abs(A[i - 1].fst - i + j) + abs(A[i - 1].snd - 1));
			if (j) DP[i][j] = min(DP[i][j], DP[i - 1][j - 1] + abs(A[i - 1].fst - j) + abs(A[i - 1].snd - 2));
		}
	}

	cout << DP[2 * N][N] << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 13 ms 15964 KB Output is correct
35 Correct 13 ms 16072 KB Output is correct
36 Correct 12 ms 15948 KB Output is correct
37 Correct 12 ms 15940 KB Output is correct
38 Correct 13 ms 15948 KB Output is correct
39 Correct 16 ms 15948 KB Output is correct
40 Correct 12 ms 15956 KB Output is correct
41 Correct 12 ms 16024 KB Output is correct
42 Correct 15 ms 15972 KB Output is correct
43 Correct 12 ms 16032 KB Output is correct
44 Correct 15 ms 15948 KB Output is correct
45 Correct 13 ms 16056 KB Output is correct
46 Correct 12 ms 15956 KB Output is correct
47 Correct 15 ms 15948 KB Output is correct
48 Correct 14 ms 15948 KB Output is correct
49 Correct 12 ms 15928 KB Output is correct
50 Correct 15 ms 15952 KB Output is correct
51 Correct 18 ms 15948 KB Output is correct
52 Correct 13 ms 15980 KB Output is correct
53 Correct 13 ms 15948 KB Output is correct
54 Correct 18 ms 15972 KB Output is correct
55 Correct 17 ms 15976 KB Output is correct
56 Correct 14 ms 16016 KB Output is correct
57 Correct 14 ms 15948 KB Output is correct
58 Correct 14 ms 15944 KB Output is correct
59 Correct 13 ms 15948 KB Output is correct
60 Correct 16 ms 16040 KB Output is correct
61 Correct 17 ms 15952 KB Output is correct
62 Correct 17 ms 16036 KB Output is correct
63 Correct 14 ms 15948 KB Output is correct
64 Correct 15 ms 15924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 13 ms 15964 KB Output is correct
35 Correct 13 ms 16072 KB Output is correct
36 Correct 12 ms 15948 KB Output is correct
37 Correct 12 ms 15940 KB Output is correct
38 Correct 13 ms 15948 KB Output is correct
39 Correct 16 ms 15948 KB Output is correct
40 Correct 12 ms 15956 KB Output is correct
41 Correct 12 ms 16024 KB Output is correct
42 Correct 15 ms 15972 KB Output is correct
43 Correct 12 ms 16032 KB Output is correct
44 Correct 15 ms 15948 KB Output is correct
45 Correct 13 ms 16056 KB Output is correct
46 Correct 12 ms 15956 KB Output is correct
47 Correct 15 ms 15948 KB Output is correct
48 Correct 14 ms 15948 KB Output is correct
49 Correct 12 ms 15928 KB Output is correct
50 Correct 15 ms 15952 KB Output is correct
51 Correct 18 ms 15948 KB Output is correct
52 Correct 13 ms 15980 KB Output is correct
53 Correct 13 ms 15948 KB Output is correct
54 Correct 18 ms 15972 KB Output is correct
55 Correct 17 ms 15976 KB Output is correct
56 Correct 14 ms 16016 KB Output is correct
57 Correct 14 ms 15948 KB Output is correct
58 Correct 14 ms 15944 KB Output is correct
59 Correct 13 ms 15948 KB Output is correct
60 Correct 16 ms 16040 KB Output is correct
61 Correct 17 ms 15952 KB Output is correct
62 Correct 17 ms 16036 KB Output is correct
63 Correct 14 ms 15948 KB Output is correct
64 Correct 15 ms 15924 KB Output is correct
65 Runtime error 71 ms 34724 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -