제출 #1361790

#제출 시각아이디문제언어결과실행 시간메모리
1361790gayCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using ll = long long;

const ll INF = 3e18, MOD = 1e9 + 7;

void solve();

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q = 1;
    while (q--) {
        solve();
    }
}

void solve() {
    ll n; cin >> n;
    vector<pair<ll, ll>> a(2 * n);
    ll ans = 0;
    for (int i = 0; i < 2 * n; i++) {
        cin >> a[i].first >> a[i].second;
        if (abs(1 - a[i].second) < abs(2 - a[i].second)) {
            ans += abs(1 - a[i].second);
            a[i].second = 1;
        } else {
            ans += abs(2 - a[i].second);
            a[i].second = 2;
        }
        if (a[i].first < 1) {
            ans += (1 - a[i].first);
            a[i].first = 1;
        }
        if (a[i].first > n) {
            ans += (a[i].first - n);
            a[i].first = n;
        }
    }
    sort(a.begin(), a.end());
    ll c1 = 0, c2 = 0;
    for (int i = 0; i < 2 * n; i++) {
        ll cur = (i + 2) / 2;
        ans += abs(cur - a[i].first);
        if (a[i].second == 1) c1++;
        else c2++;
    }
    if (c2 > n) {
        ans += c2 - n;
    } else {
        ans += c1 - n;
    }
    cout << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…