제출 #1341545

#제출 시각아이디문제언어결과실행 시간메모리
1341545nguyenkhangninh99Coin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms344 KiB

#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n; 
    vector<array<int, 3>> a(n + 1);

    int ans = 0, top = 0, bot = 0;
    for(int i = 1; i <= 2 * n; i++){
        int x, y; cin >> x >> y;
        if(y <= 1) ans += 1 - y, y = 1;
        else ans += y - 2, y = 2;
        if(x < 1) ans += 1 - x, x = 1;
        else if(x > n) ans += x - n, x = n;
        a[y][x]++;
    }
 
    for(int i = 1; i <= n; i++){
        top += a[1][i] - 1;
        bot += a[2][i] - 1;
 
        if((top < 0 && bot > 0) || (top > 0 && bot < 0)){
            if(abs(top) < abs(bot)){
                ans += abs(top);
                bot += top;
                top = 0;
            } else {
                ans += abs(bot);
                top += bot;
                bot = 0;
            }
        }
 
        ans += abs(top + bot);
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...