This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n; n <<= 1;
vector<ar<int, 2>> a(n), b(n);
for(int i=0;i<n;i++){
cin>>a[i][0]>>a[i][1];
b[i][0] = i / 2 + 1, b[i][1] = (i&1) + 1;
}
vector<int> dp(1 << n, 1e15);
dp[0] = 0;
for(int mask=1;mask < (1 << n);mask++){
int in = __builtin_popcount(mask) - 1;
for(int i=0;i<n;i++){
if(mask >> i & 1){
dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] +
abs(a[i][0] - b[in][0]) + abs(a[i][1] - b[in][1]));
}
}
}
cout<<dp[(1 << n) - 1]<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |