Submission #720998

#TimeUsernameProblemLanguageResultExecution timeMemory
720998PringCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1076 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; const int MXN = 200005; int N, n, ans = LLONG_MAX, c[MXN][2]; pii a[MXN], p[MXN]; int DIS(pii &a, pii &b) { return abs(a.first - b.first) + abs(a.second - b.second); } void solve() { int ans0 = 0; for (int i = 0; i < N; i++) ans0 += DIS(p[i], a[i]); ans = min(ans, ans0); // for (int i = 0; i < N; i++) cout << p[i].first << ' ' << p[i].second << ' '; // cout << endl; // cout << ans0 << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; N = n * 2; for (int i = 0; i < N; i++) { cin >> a[i].first >> a[i].second; } for (int i = 0; i < n; i++) { // p[i] = {i + 1, 1}; // p[i + n] = {i + 1, 2}; p[i * 2] = {i + 1, 1}; p[i * 2 + 1] = {i + 1, 2}; } do { solve(); } while (next_permutation(p, p + N)); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...