#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e3+5;
const ll INF=1e15+9;
vector<pair<ll, ll> > v[2];
ll dp[MAXN][MAXN];
int n;
ll dist(int a, int b, ll x) {
if(b>=v[a].size()) return INF;
ll resp=0;
auto ponto=v[a][b];
resp+=llabs(ponto.first-x);
resp+=min(llabs(ponto.second-2), llabs(ponto.second-1));
return resp;
}
ll fazdp(int a, int b) {
if(a==v[0].size()&&b==v[1].size()) return 0;
if(a>v[0].size()||b>v[1].size()) return INF;
if(dp[a][b]!=-1) return dp[a][b];
// printf("calc %d %d\n", a, b);
ll ind=(a+b)/2+1;
dp[a][b]=INF;
ll &cur=dp[a][b];
cur=min(cur, fazdp(a+2, b)+dist(0, a, ind)+dist(0, a+1, ind)+1);
cur=min(cur, fazdp(a, b+2)+dist(1, b, ind)+dist(1, b+1, ind)+1);
cur=min(cur, fazdp(a+1, b+1)+dist(0, a, ind)+dist(1, b, ind));
// printf("%d %d >> %lld\n", a, b, cur);
return cur;
}
int main() {
scanf("%d", &n); n*=2;
memset(dp, -1, sizeof(dp));
for(int i=1; i<=n; i++) {
int a, b; scanf("%d %d", &a, &b);
if(b>=2) v[0].push_back({a, b});
else v[1].push_back({a, b});
}
sort(v[0].begin(), v[0].end());
sort(v[1].begin(), v[1].end());
ll respf=fazdp(0, 0);
printf("%lld\n", respf);
}
Compilation message
joi2019_ho_t4.cpp: In function 'll dist(int, int, ll)':
joi2019_ho_t4.cpp:12:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(b>=v[a].size()) return INF;
~^~~~~~~~~~~~~
joi2019_ho_t4.cpp: In function 'll fazdp(int, int)':
joi2019_ho_t4.cpp:21:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(a==v[0].size()&&b==v[1].size()) return 0;
~^~~~~~~~~~~~~
joi2019_ho_t4.cpp:21:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(a==v[0].size()&&b==v[1].size()) return 0;
~^~~~~~~~~~~~~
joi2019_ho_t4.cpp:22:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(a>v[0].size()||b>v[1].size()) return INF;
~^~~~~~~~~~~~
joi2019_ho_t4.cpp:22:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(a>v[0].size()||b>v[1].size()) return INF;
~^~~~~~~~~~~~
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n); n*=2;
~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int a, b; scanf("%d %d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
31864 KB |
Output is correct |
2 |
Correct |
28 ms |
31736 KB |
Output is correct |
3 |
Correct |
28 ms |
31864 KB |
Output is correct |
4 |
Correct |
28 ms |
31736 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31736 KB |
Output is correct |
7 |
Correct |
28 ms |
31736 KB |
Output is correct |
8 |
Correct |
28 ms |
31864 KB |
Output is correct |
9 |
Correct |
28 ms |
31864 KB |
Output is correct |
10 |
Correct |
33 ms |
31736 KB |
Output is correct |
11 |
Correct |
33 ms |
31736 KB |
Output is correct |
12 |
Correct |
33 ms |
31736 KB |
Output is correct |
13 |
Correct |
30 ms |
31736 KB |
Output is correct |
14 |
Correct |
28 ms |
31736 KB |
Output is correct |
15 |
Correct |
28 ms |
31864 KB |
Output is correct |
16 |
Correct |
33 ms |
31736 KB |
Output is correct |
17 |
Correct |
28 ms |
31864 KB |
Output is correct |
18 |
Correct |
28 ms |
31864 KB |
Output is correct |
19 |
Correct |
28 ms |
31736 KB |
Output is correct |
20 |
Correct |
28 ms |
31864 KB |
Output is correct |
21 |
Correct |
28 ms |
31736 KB |
Output is correct |
22 |
Correct |
28 ms |
31812 KB |
Output is correct |
23 |
Correct |
28 ms |
31864 KB |
Output is correct |
24 |
Correct |
28 ms |
31736 KB |
Output is correct |
25 |
Correct |
28 ms |
31736 KB |
Output is correct |
26 |
Correct |
28 ms |
31740 KB |
Output is correct |
27 |
Correct |
28 ms |
31864 KB |
Output is correct |
28 |
Correct |
28 ms |
31864 KB |
Output is correct |
29 |
Correct |
28 ms |
31864 KB |
Output is correct |
30 |
Correct |
28 ms |
31736 KB |
Output is correct |
31 |
Correct |
28 ms |
31864 KB |
Output is correct |
32 |
Correct |
28 ms |
31736 KB |
Output is correct |
33 |
Correct |
28 ms |
31736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
31864 KB |
Output is correct |
2 |
Correct |
28 ms |
31736 KB |
Output is correct |
3 |
Correct |
28 ms |
31864 KB |
Output is correct |
4 |
Correct |
28 ms |
31736 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31736 KB |
Output is correct |
7 |
Correct |
28 ms |
31736 KB |
Output is correct |
8 |
Correct |
28 ms |
31864 KB |
Output is correct |
9 |
Correct |
28 ms |
31864 KB |
Output is correct |
10 |
Correct |
33 ms |
31736 KB |
Output is correct |
11 |
Correct |
33 ms |
31736 KB |
Output is correct |
12 |
Correct |
33 ms |
31736 KB |
Output is correct |
13 |
Correct |
30 ms |
31736 KB |
Output is correct |
14 |
Correct |
28 ms |
31736 KB |
Output is correct |
15 |
Correct |
28 ms |
31864 KB |
Output is correct |
16 |
Correct |
33 ms |
31736 KB |
Output is correct |
17 |
Correct |
28 ms |
31864 KB |
Output is correct |
18 |
Correct |
28 ms |
31864 KB |
Output is correct |
19 |
Correct |
28 ms |
31736 KB |
Output is correct |
20 |
Correct |
28 ms |
31864 KB |
Output is correct |
21 |
Correct |
28 ms |
31736 KB |
Output is correct |
22 |
Correct |
28 ms |
31812 KB |
Output is correct |
23 |
Correct |
28 ms |
31864 KB |
Output is correct |
24 |
Correct |
28 ms |
31736 KB |
Output is correct |
25 |
Correct |
28 ms |
31736 KB |
Output is correct |
26 |
Correct |
28 ms |
31740 KB |
Output is correct |
27 |
Correct |
28 ms |
31864 KB |
Output is correct |
28 |
Correct |
28 ms |
31864 KB |
Output is correct |
29 |
Correct |
28 ms |
31864 KB |
Output is correct |
30 |
Correct |
28 ms |
31736 KB |
Output is correct |
31 |
Correct |
28 ms |
31864 KB |
Output is correct |
32 |
Correct |
28 ms |
31736 KB |
Output is correct |
33 |
Correct |
28 ms |
31736 KB |
Output is correct |
34 |
Correct |
54 ms |
31896 KB |
Output is correct |
35 |
Correct |
29 ms |
31816 KB |
Output is correct |
36 |
Correct |
54 ms |
31864 KB |
Output is correct |
37 |
Correct |
54 ms |
31864 KB |
Output is correct |
38 |
Correct |
55 ms |
31864 KB |
Output is correct |
39 |
Correct |
55 ms |
31992 KB |
Output is correct |
40 |
Correct |
55 ms |
31864 KB |
Output is correct |
41 |
Correct |
54 ms |
31868 KB |
Output is correct |
42 |
Correct |
54 ms |
31864 KB |
Output is correct |
43 |
Correct |
54 ms |
31996 KB |
Output is correct |
44 |
Correct |
55 ms |
31864 KB |
Output is correct |
45 |
Correct |
54 ms |
31964 KB |
Output is correct |
46 |
Correct |
54 ms |
31864 KB |
Output is correct |
47 |
Correct |
54 ms |
31936 KB |
Output is correct |
48 |
Correct |
55 ms |
31964 KB |
Output is correct |
49 |
Correct |
54 ms |
31948 KB |
Output is correct |
50 |
Correct |
54 ms |
31864 KB |
Output is correct |
51 |
Correct |
54 ms |
31864 KB |
Output is correct |
52 |
Correct |
57 ms |
31836 KB |
Output is correct |
53 |
Correct |
29 ms |
31964 KB |
Output is correct |
54 |
Correct |
38 ms |
31992 KB |
Output is correct |
55 |
Correct |
38 ms |
31992 KB |
Output is correct |
56 |
Correct |
29 ms |
31892 KB |
Output is correct |
57 |
Correct |
39 ms |
31996 KB |
Output is correct |
58 |
Correct |
53 ms |
31992 KB |
Output is correct |
59 |
Correct |
50 ms |
31992 KB |
Output is correct |
60 |
Correct |
51 ms |
31864 KB |
Output is correct |
61 |
Correct |
53 ms |
31864 KB |
Output is correct |
62 |
Correct |
53 ms |
31992 KB |
Output is correct |
63 |
Correct |
51 ms |
31992 KB |
Output is correct |
64 |
Correct |
47 ms |
31992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
31864 KB |
Output is correct |
2 |
Correct |
28 ms |
31736 KB |
Output is correct |
3 |
Correct |
28 ms |
31864 KB |
Output is correct |
4 |
Correct |
28 ms |
31736 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31736 KB |
Output is correct |
7 |
Correct |
28 ms |
31736 KB |
Output is correct |
8 |
Correct |
28 ms |
31864 KB |
Output is correct |
9 |
Correct |
28 ms |
31864 KB |
Output is correct |
10 |
Correct |
33 ms |
31736 KB |
Output is correct |
11 |
Correct |
33 ms |
31736 KB |
Output is correct |
12 |
Correct |
33 ms |
31736 KB |
Output is correct |
13 |
Correct |
30 ms |
31736 KB |
Output is correct |
14 |
Correct |
28 ms |
31736 KB |
Output is correct |
15 |
Correct |
28 ms |
31864 KB |
Output is correct |
16 |
Correct |
33 ms |
31736 KB |
Output is correct |
17 |
Correct |
28 ms |
31864 KB |
Output is correct |
18 |
Correct |
28 ms |
31864 KB |
Output is correct |
19 |
Correct |
28 ms |
31736 KB |
Output is correct |
20 |
Correct |
28 ms |
31864 KB |
Output is correct |
21 |
Correct |
28 ms |
31736 KB |
Output is correct |
22 |
Correct |
28 ms |
31812 KB |
Output is correct |
23 |
Correct |
28 ms |
31864 KB |
Output is correct |
24 |
Correct |
28 ms |
31736 KB |
Output is correct |
25 |
Correct |
28 ms |
31736 KB |
Output is correct |
26 |
Correct |
28 ms |
31740 KB |
Output is correct |
27 |
Correct |
28 ms |
31864 KB |
Output is correct |
28 |
Correct |
28 ms |
31864 KB |
Output is correct |
29 |
Correct |
28 ms |
31864 KB |
Output is correct |
30 |
Correct |
28 ms |
31736 KB |
Output is correct |
31 |
Correct |
28 ms |
31864 KB |
Output is correct |
32 |
Correct |
28 ms |
31736 KB |
Output is correct |
33 |
Correct |
28 ms |
31736 KB |
Output is correct |
34 |
Correct |
54 ms |
31896 KB |
Output is correct |
35 |
Correct |
29 ms |
31816 KB |
Output is correct |
36 |
Correct |
54 ms |
31864 KB |
Output is correct |
37 |
Correct |
54 ms |
31864 KB |
Output is correct |
38 |
Correct |
55 ms |
31864 KB |
Output is correct |
39 |
Correct |
55 ms |
31992 KB |
Output is correct |
40 |
Correct |
55 ms |
31864 KB |
Output is correct |
41 |
Correct |
54 ms |
31868 KB |
Output is correct |
42 |
Correct |
54 ms |
31864 KB |
Output is correct |
43 |
Correct |
54 ms |
31996 KB |
Output is correct |
44 |
Correct |
55 ms |
31864 KB |
Output is correct |
45 |
Correct |
54 ms |
31964 KB |
Output is correct |
46 |
Correct |
54 ms |
31864 KB |
Output is correct |
47 |
Correct |
54 ms |
31936 KB |
Output is correct |
48 |
Correct |
55 ms |
31964 KB |
Output is correct |
49 |
Correct |
54 ms |
31948 KB |
Output is correct |
50 |
Correct |
54 ms |
31864 KB |
Output is correct |
51 |
Correct |
54 ms |
31864 KB |
Output is correct |
52 |
Correct |
57 ms |
31836 KB |
Output is correct |
53 |
Correct |
29 ms |
31964 KB |
Output is correct |
54 |
Correct |
38 ms |
31992 KB |
Output is correct |
55 |
Correct |
38 ms |
31992 KB |
Output is correct |
56 |
Correct |
29 ms |
31892 KB |
Output is correct |
57 |
Correct |
39 ms |
31996 KB |
Output is correct |
58 |
Correct |
53 ms |
31992 KB |
Output is correct |
59 |
Correct |
50 ms |
31992 KB |
Output is correct |
60 |
Correct |
51 ms |
31864 KB |
Output is correct |
61 |
Correct |
53 ms |
31864 KB |
Output is correct |
62 |
Correct |
53 ms |
31992 KB |
Output is correct |
63 |
Correct |
51 ms |
31992 KB |
Output is correct |
64 |
Correct |
47 ms |
31992 KB |
Output is correct |
65 |
Runtime error |
142 ms |
72528 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
66 |
Halted |
0 ms |
0 KB |
- |