Submission #720998

# Submission time Handle Problem Language Result Execution time Memory
720998 2023-04-10T02:33:53 Z Pring Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1000 ms 212 KB
#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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 1076 ms 212 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 1076 ms 212 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 1076 ms 212 KB Time limit exceeded
5 Halted 0 ms 0 KB -