제출 #809008

#제출 시각아이디문제언어결과실행 시간메모리
809008annabeth9680Coin Collecting (JOI19_ho_t4)C++17
100 / 100
39 ms6476 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5+5;
ll anzahl[2][MAXN]; //German mode activated
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N; cin >> N;
    ll ans = 0;
    for(int i = 0;i<2*N;++i){
        int x,y; cin >> x >> y;
        if(x < 1){
            ans += 1-x;
            x = 1;
        }
        if(x > N){
            ans += x-N;
            x = N;
        }
        if(y < 1){
            ans += 1-y;
            y = 1;
        }
        if(y > 2){
            ans += y-2;
            y = 2;
        }
        anzahl[y-1][x]++;
    }
    for(int i = 1;i<=N;++i){ //BETRAG!
        anzahl[0][i]--; anzahl[1][i]--;
        if(1ll * anzahl[0][i] * anzahl[1][i] < 0){
            if(anzahl[0][i] < 0){
                ll x = min(abs(anzahl[0][i]),anzahl[1][i]);
                anzahl[0][i] += x; anzahl[1][i] -= x;
                ans += x;
            }
            else{
                ll x = min(abs(anzahl[1][i]),anzahl[0][i]);
                anzahl[1][i] += x; anzahl[0][i] -= x;
                ans += x;
            }
        }
        ans += abs(anzahl[0][i])+abs(anzahl[1][i]);
        anzahl[0][i+1] += anzahl[0][i]; anzahl[1][i+1] += anzahl[1][i];
    }
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...