#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(4e15) + ll(2e15);
const double EPS = 1e-9;
static int LamyIsCute = []() {
EmiliaMyWife
return 48763;
}();
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,tune=native")
signed main() {
int n;
cin >> n;
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, LINF));
vector<pair<ll, ll>> arr(n * 2);
for(int i = 0; i < n * 2; i++)
cin >> arr[i].first >> arr[i].second;
sort(arr.begin(), arr.end());
dp[0][0] = 0;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
int x = i + j;
if(i < n)
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + abs(arr[x].first - (i + 1)) + abs(arr[x].second - 2));
if(j < n)
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + abs(arr[x].first - (j + 1)) + abs(arr[x].second - 1));
}
}
cout << dp[n][n] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
27 ms |
8216 KB |
Output is correct |
35 |
Correct |
29 ms |
8224 KB |
Output is correct |
36 |
Correct |
26 ms |
8140 KB |
Output is correct |
37 |
Correct |
29 ms |
8140 KB |
Output is correct |
38 |
Correct |
25 ms |
8228 KB |
Output is correct |
39 |
Correct |
24 ms |
8140 KB |
Output is correct |
40 |
Correct |
24 ms |
8260 KB |
Output is correct |
41 |
Correct |
29 ms |
8140 KB |
Output is correct |
42 |
Correct |
23 ms |
8140 KB |
Output is correct |
43 |
Correct |
27 ms |
8140 KB |
Output is correct |
44 |
Correct |
29 ms |
8140 KB |
Output is correct |
45 |
Correct |
27 ms |
8140 KB |
Output is correct |
46 |
Correct |
26 ms |
8228 KB |
Output is correct |
47 |
Correct |
23 ms |
8140 KB |
Output is correct |
48 |
Correct |
24 ms |
8140 KB |
Output is correct |
49 |
Correct |
24 ms |
8140 KB |
Output is correct |
50 |
Correct |
26 ms |
8140 KB |
Output is correct |
51 |
Correct |
26 ms |
8140 KB |
Output is correct |
52 |
Correct |
27 ms |
8140 KB |
Output is correct |
53 |
Correct |
27 ms |
8140 KB |
Output is correct |
54 |
Correct |
29 ms |
8140 KB |
Output is correct |
55 |
Correct |
23 ms |
8132 KB |
Output is correct |
56 |
Correct |
24 ms |
8208 KB |
Output is correct |
57 |
Correct |
24 ms |
8140 KB |
Output is correct |
58 |
Correct |
26 ms |
8140 KB |
Output is correct |
59 |
Correct |
25 ms |
8140 KB |
Output is correct |
60 |
Correct |
24 ms |
8140 KB |
Output is correct |
61 |
Correct |
30 ms |
8140 KB |
Output is correct |
62 |
Correct |
26 ms |
8140 KB |
Output is correct |
63 |
Correct |
27 ms |
8232 KB |
Output is correct |
64 |
Correct |
27 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
27 ms |
8216 KB |
Output is correct |
35 |
Correct |
29 ms |
8224 KB |
Output is correct |
36 |
Correct |
26 ms |
8140 KB |
Output is correct |
37 |
Correct |
29 ms |
8140 KB |
Output is correct |
38 |
Correct |
25 ms |
8228 KB |
Output is correct |
39 |
Correct |
24 ms |
8140 KB |
Output is correct |
40 |
Correct |
24 ms |
8260 KB |
Output is correct |
41 |
Correct |
29 ms |
8140 KB |
Output is correct |
42 |
Correct |
23 ms |
8140 KB |
Output is correct |
43 |
Correct |
27 ms |
8140 KB |
Output is correct |
44 |
Correct |
29 ms |
8140 KB |
Output is correct |
45 |
Correct |
27 ms |
8140 KB |
Output is correct |
46 |
Correct |
26 ms |
8228 KB |
Output is correct |
47 |
Correct |
23 ms |
8140 KB |
Output is correct |
48 |
Correct |
24 ms |
8140 KB |
Output is correct |
49 |
Correct |
24 ms |
8140 KB |
Output is correct |
50 |
Correct |
26 ms |
8140 KB |
Output is correct |
51 |
Correct |
26 ms |
8140 KB |
Output is correct |
52 |
Correct |
27 ms |
8140 KB |
Output is correct |
53 |
Correct |
27 ms |
8140 KB |
Output is correct |
54 |
Correct |
29 ms |
8140 KB |
Output is correct |
55 |
Correct |
23 ms |
8132 KB |
Output is correct |
56 |
Correct |
24 ms |
8208 KB |
Output is correct |
57 |
Correct |
24 ms |
8140 KB |
Output is correct |
58 |
Correct |
26 ms |
8140 KB |
Output is correct |
59 |
Correct |
25 ms |
8140 KB |
Output is correct |
60 |
Correct |
24 ms |
8140 KB |
Output is correct |
61 |
Correct |
30 ms |
8140 KB |
Output is correct |
62 |
Correct |
26 ms |
8140 KB |
Output is correct |
63 |
Correct |
27 ms |
8232 KB |
Output is correct |
64 |
Correct |
27 ms |
8140 KB |
Output is correct |
65 |
Runtime error |
105 ms |
274436 KB |
Execution killed with signal 9 |
66 |
Halted |
0 ms |
0 KB |
- |