제출 #1148083

#제출 시각아이디문제언어결과실행 시간메모리
1148083montes_joseCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms324 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<pair<int, int>> coins(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        cin >> coins[i].first >> coins[i].second;
    }

    sort(coins.begin(), coins.end());

    long long total = 0;
    for (int i = 0; i < n; ++i) {
        int x = i + 1;
        pair<int, int> coin1 = coins[2 * i];
        pair<int, int> coin2 = coins[2 * i + 1];

        int h_cost = abs(coin1.first - x) + abs(coin2.first - x);

        int y1 = coin1.second;
        int y2 = coin2.second;

        int option1 = abs(y1 - 1) + abs(y2 - 2);
        int option2 = abs(y1 - 2) + abs(y2 - 1);
        int v_cost = min(option1, option2);

        total += h_cost + v_cost;
    }

    cout << total << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...