#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct pos{
ll x,y;
bool operator<(const pos &o) const{
return x!=o.x?x<o.x:y<o.y;
}
};
ll dis(pos a, pos b){
return abs(a.x-b.x)+abs(a.y-b.y);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
vector<pos> a(n*2);
for(pos &o : a) cin >> o.x >> o.y;
sort(a.begin(),a.end());
ll ans = 0;
vector<pos> b(n*2);
for(ll i = 0;i<n;i++){
b[i<<1] = {i+1,1};
b[i<<1|1] = {i+1,2};
}
if (n>10) return 0;
ll n2 = n*2;
vector<ll> dp(1<<n2,1e18);
dp[0] = 0;
for(ll i = 1;i<=n2;i++){
for(ll j = 1;j<(1<<n2);j++){
if (__builtin_popcountll(j)==i){
for(ll k = 0;k<n2;k++){
if (j>>k&1){
dp[j] = min(dp[j],dp[j^(1<<k)]+dis(b[i-1],a[k]));
}
}
}
}
}
cout << dp[(1<<n2)-1] << "\n";
}
Compilation message
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:20:8: warning: unused variable 'ans' [-Wunused-variable]
20 | ll ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
127 ms |
8540 KB |
Output is correct |
5 |
Correct |
123 ms |
8536 KB |
Output is correct |
6 |
Correct |
124 ms |
8540 KB |
Output is correct |
7 |
Correct |
127 ms |
8540 KB |
Output is correct |
8 |
Correct |
122 ms |
8540 KB |
Output is correct |
9 |
Correct |
122 ms |
8540 KB |
Output is correct |
10 |
Correct |
123 ms |
8536 KB |
Output is correct |
11 |
Correct |
131 ms |
8540 KB |
Output is correct |
12 |
Correct |
123 ms |
8536 KB |
Output is correct |
13 |
Correct |
123 ms |
8648 KB |
Output is correct |
14 |
Correct |
125 ms |
8552 KB |
Output is correct |
15 |
Correct |
128 ms |
8536 KB |
Output is correct |
16 |
Correct |
123 ms |
8536 KB |
Output is correct |
17 |
Correct |
122 ms |
8540 KB |
Output is correct |
18 |
Correct |
123 ms |
8540 KB |
Output is correct |
19 |
Correct |
127 ms |
8536 KB |
Output is correct |
20 |
Correct |
123 ms |
8540 KB |
Output is correct |
21 |
Correct |
127 ms |
8540 KB |
Output is correct |
22 |
Correct |
123 ms |
8540 KB |
Output is correct |
23 |
Correct |
124 ms |
8540 KB |
Output is correct |
24 |
Correct |
122 ms |
8536 KB |
Output is correct |
25 |
Correct |
127 ms |
8540 KB |
Output is correct |
26 |
Correct |
123 ms |
8540 KB |
Output is correct |
27 |
Correct |
123 ms |
8536 KB |
Output is correct |
28 |
Correct |
124 ms |
8536 KB |
Output is correct |
29 |
Correct |
122 ms |
8540 KB |
Output is correct |
30 |
Correct |
126 ms |
8536 KB |
Output is correct |
31 |
Correct |
123 ms |
8540 KB |
Output is correct |
32 |
Correct |
131 ms |
8536 KB |
Output is correct |
33 |
Correct |
125 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
127 ms |
8540 KB |
Output is correct |
5 |
Correct |
123 ms |
8536 KB |
Output is correct |
6 |
Correct |
124 ms |
8540 KB |
Output is correct |
7 |
Correct |
127 ms |
8540 KB |
Output is correct |
8 |
Correct |
122 ms |
8540 KB |
Output is correct |
9 |
Correct |
122 ms |
8540 KB |
Output is correct |
10 |
Correct |
123 ms |
8536 KB |
Output is correct |
11 |
Correct |
131 ms |
8540 KB |
Output is correct |
12 |
Correct |
123 ms |
8536 KB |
Output is correct |
13 |
Correct |
123 ms |
8648 KB |
Output is correct |
14 |
Correct |
125 ms |
8552 KB |
Output is correct |
15 |
Correct |
128 ms |
8536 KB |
Output is correct |
16 |
Correct |
123 ms |
8536 KB |
Output is correct |
17 |
Correct |
122 ms |
8540 KB |
Output is correct |
18 |
Correct |
123 ms |
8540 KB |
Output is correct |
19 |
Correct |
127 ms |
8536 KB |
Output is correct |
20 |
Correct |
123 ms |
8540 KB |
Output is correct |
21 |
Correct |
127 ms |
8540 KB |
Output is correct |
22 |
Correct |
123 ms |
8540 KB |
Output is correct |
23 |
Correct |
124 ms |
8540 KB |
Output is correct |
24 |
Correct |
122 ms |
8536 KB |
Output is correct |
25 |
Correct |
127 ms |
8540 KB |
Output is correct |
26 |
Correct |
123 ms |
8540 KB |
Output is correct |
27 |
Correct |
123 ms |
8536 KB |
Output is correct |
28 |
Correct |
124 ms |
8536 KB |
Output is correct |
29 |
Correct |
122 ms |
8540 KB |
Output is correct |
30 |
Correct |
126 ms |
8536 KB |
Output is correct |
31 |
Correct |
123 ms |
8540 KB |
Output is correct |
32 |
Correct |
131 ms |
8536 KB |
Output is correct |
33 |
Correct |
125 ms |
8540 KB |
Output is correct |
34 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
127 ms |
8540 KB |
Output is correct |
5 |
Correct |
123 ms |
8536 KB |
Output is correct |
6 |
Correct |
124 ms |
8540 KB |
Output is correct |
7 |
Correct |
127 ms |
8540 KB |
Output is correct |
8 |
Correct |
122 ms |
8540 KB |
Output is correct |
9 |
Correct |
122 ms |
8540 KB |
Output is correct |
10 |
Correct |
123 ms |
8536 KB |
Output is correct |
11 |
Correct |
131 ms |
8540 KB |
Output is correct |
12 |
Correct |
123 ms |
8536 KB |
Output is correct |
13 |
Correct |
123 ms |
8648 KB |
Output is correct |
14 |
Correct |
125 ms |
8552 KB |
Output is correct |
15 |
Correct |
128 ms |
8536 KB |
Output is correct |
16 |
Correct |
123 ms |
8536 KB |
Output is correct |
17 |
Correct |
122 ms |
8540 KB |
Output is correct |
18 |
Correct |
123 ms |
8540 KB |
Output is correct |
19 |
Correct |
127 ms |
8536 KB |
Output is correct |
20 |
Correct |
123 ms |
8540 KB |
Output is correct |
21 |
Correct |
127 ms |
8540 KB |
Output is correct |
22 |
Correct |
123 ms |
8540 KB |
Output is correct |
23 |
Correct |
124 ms |
8540 KB |
Output is correct |
24 |
Correct |
122 ms |
8536 KB |
Output is correct |
25 |
Correct |
127 ms |
8540 KB |
Output is correct |
26 |
Correct |
123 ms |
8540 KB |
Output is correct |
27 |
Correct |
123 ms |
8536 KB |
Output is correct |
28 |
Correct |
124 ms |
8536 KB |
Output is correct |
29 |
Correct |
122 ms |
8540 KB |
Output is correct |
30 |
Correct |
126 ms |
8536 KB |
Output is correct |
31 |
Correct |
123 ms |
8540 KB |
Output is correct |
32 |
Correct |
131 ms |
8536 KB |
Output is correct |
33 |
Correct |
125 ms |
8540 KB |
Output is correct |
34 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |