제출 #1361811

#제출 시각아이디문제언어결과실행 시간메모리
1361811gayCoin 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;
        }
    }
    vector<vector<ll>> cnt(n, vector<ll>(2));
    for (int i = 0; i < 2 * n; i++) {
        cnt[a[i].first - 1][a[i].second - 1]++;
    }
    ll f = 0;
    ll c1 = 0, c2 = 0;
    for (ll i = 0; i < n; i++) {
        f += cnt[i][0] + cnt[i][1];
        c1 += cnt[i][0], c2 += cnt[i][1];
        ans += abs(f - (i + 1) * 2);
    }
    ans += (abs(n - c1) + abs(n - c2)) / 2;
    cout << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…