Submission #1310157

#TimeUsernameProblemLanguageResultExecution timeMemory
1310157zxzuamCoin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector <int> x(2 * n + 1), y(2 * n + 1), pref(2 * n + 1), cnt(3);
    int ans = 0;
    for(int i = 1; i <= 2 * n; i++) {
        cin >> x[i] >> y[i];
        if(1 <= x[i] && x[i] <= n) {
            if(y[i] >= 2) {
                ans += y[i] - 2;
                y[i] = 2;
            }
            else{
                ans += 1 - y[i];
                y[i] = 1;
            }
        }
        else{
            if(y[i] >= 2) {
                ans += y[i] - 2;
                y[i] = 2;
            }
            else{
                ans += 1 - y[i];
                y[i] = 1;
            }
            if(x[i] >= n) {
                ans += x[i] - n;
                x[i] = n;
            }
            else{
                ans += 1 - x[i];
                x[i] = 1;
            }
        }
        cnt[y[i]]++;
        pref[x[i]]++;
    }
    for(int i = 1; i <= n; i++) {
        pref[i] += pref[i - 1];
    }
    ans += n - min(cnt[1], cnt[2]);
    for(int i = 1; i <= n; i++) {
        ans += abs( (2 * i) - pref[i] );
    }
    cout << ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...