#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (int)2e3+10;
const int LINF = (int)2e18;
int n, dp[N][N];
array<int,2> a[2][N], loc[N];
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n; n*=2;
for(int i = 1; i <= n; i++)
cin >> loc[i][0] >> loc[i][1];
sort(loc+1,loc+n+1);
for(int i = 1; i <= n/2; i++)
a[0][i] = {i,1}, a[1][i] = {i,2};
for(int i = 0; i <= n/2; i++)
for(int j = 0; j <= n/2; j++)
dp[i][j]=LINF;
dp[0][0] = 0;
for(int i = 0; i <= n/2; i++){
for(int j = 0; j <= n/2; j++){
if(i) dp[i][j] = min(dp[i][j], dp[i-1][j]
+abs(i-loc[i+j][0])+abs(1-loc[i+j][1]));
if(j) dp[i][j] = min(dp[i][j], dp[i][j-1]
+abs(j-loc[i+j][0])+abs(2-loc[i+j][1]));
}
}
cout << dp[n/2][n/2] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2552 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2552 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2552 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2552 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2552 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2552 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2552 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2552 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2384 KB |
Output is correct |
34 |
Correct |
7 ms |
16976 KB |
Output is correct |
35 |
Correct |
7 ms |
17144 KB |
Output is correct |
36 |
Correct |
7 ms |
16976 KB |
Output is correct |
37 |
Correct |
7 ms |
16976 KB |
Output is correct |
38 |
Correct |
7 ms |
16976 KB |
Output is correct |
39 |
Correct |
7 ms |
16976 KB |
Output is correct |
40 |
Correct |
8 ms |
16976 KB |
Output is correct |
41 |
Correct |
8 ms |
16976 KB |
Output is correct |
42 |
Correct |
8 ms |
17124 KB |
Output is correct |
43 |
Correct |
7 ms |
17048 KB |
Output is correct |
44 |
Correct |
8 ms |
16976 KB |
Output is correct |
45 |
Correct |
8 ms |
16976 KB |
Output is correct |
46 |
Correct |
7 ms |
17144 KB |
Output is correct |
47 |
Correct |
7 ms |
16976 KB |
Output is correct |
48 |
Correct |
7 ms |
16976 KB |
Output is correct |
49 |
Correct |
7 ms |
16976 KB |
Output is correct |
50 |
Correct |
7 ms |
16976 KB |
Output is correct |
51 |
Correct |
7 ms |
16976 KB |
Output is correct |
52 |
Correct |
7 ms |
16976 KB |
Output is correct |
53 |
Correct |
7 ms |
17052 KB |
Output is correct |
54 |
Correct |
7 ms |
17144 KB |
Output is correct |
55 |
Correct |
7 ms |
16976 KB |
Output is correct |
56 |
Correct |
8 ms |
16976 KB |
Output is correct |
57 |
Correct |
8 ms |
16976 KB |
Output is correct |
58 |
Correct |
8 ms |
17048 KB |
Output is correct |
59 |
Correct |
7 ms |
16988 KB |
Output is correct |
60 |
Correct |
7 ms |
16976 KB |
Output is correct |
61 |
Correct |
7 ms |
16976 KB |
Output is correct |
62 |
Correct |
7 ms |
16976 KB |
Output is correct |
63 |
Correct |
7 ms |
16976 KB |
Output is correct |
64 |
Correct |
7 ms |
16976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2552 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2552 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2552 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2552 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2384 KB |
Output is correct |
34 |
Correct |
7 ms |
16976 KB |
Output is correct |
35 |
Correct |
7 ms |
17144 KB |
Output is correct |
36 |
Correct |
7 ms |
16976 KB |
Output is correct |
37 |
Correct |
7 ms |
16976 KB |
Output is correct |
38 |
Correct |
7 ms |
16976 KB |
Output is correct |
39 |
Correct |
7 ms |
16976 KB |
Output is correct |
40 |
Correct |
8 ms |
16976 KB |
Output is correct |
41 |
Correct |
8 ms |
16976 KB |
Output is correct |
42 |
Correct |
8 ms |
17124 KB |
Output is correct |
43 |
Correct |
7 ms |
17048 KB |
Output is correct |
44 |
Correct |
8 ms |
16976 KB |
Output is correct |
45 |
Correct |
8 ms |
16976 KB |
Output is correct |
46 |
Correct |
7 ms |
17144 KB |
Output is correct |
47 |
Correct |
7 ms |
16976 KB |
Output is correct |
48 |
Correct |
7 ms |
16976 KB |
Output is correct |
49 |
Correct |
7 ms |
16976 KB |
Output is correct |
50 |
Correct |
7 ms |
16976 KB |
Output is correct |
51 |
Correct |
7 ms |
16976 KB |
Output is correct |
52 |
Correct |
7 ms |
16976 KB |
Output is correct |
53 |
Correct |
7 ms |
17052 KB |
Output is correct |
54 |
Correct |
7 ms |
17144 KB |
Output is correct |
55 |
Correct |
7 ms |
16976 KB |
Output is correct |
56 |
Correct |
8 ms |
16976 KB |
Output is correct |
57 |
Correct |
8 ms |
16976 KB |
Output is correct |
58 |
Correct |
8 ms |
17048 KB |
Output is correct |
59 |
Correct |
7 ms |
16988 KB |
Output is correct |
60 |
Correct |
7 ms |
16976 KB |
Output is correct |
61 |
Correct |
7 ms |
16976 KB |
Output is correct |
62 |
Correct |
7 ms |
16976 KB |
Output is correct |
63 |
Correct |
7 ms |
16976 KB |
Output is correct |
64 |
Correct |
7 ms |
16976 KB |
Output is correct |
65 |
Runtime error |
146 ms |
66224 KB |
Execution killed with signal 11 |
66 |
Halted |
0 ms |
0 KB |
- |