답안 #878779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878779 2023-11-25T08:13:38 Z frostray8653 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
#define int long long
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a, I = b; i <= I; i++)
using namespace std;
using pii = pair<int, int>;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) { cout << a << " "; dbg(b...); }
void ent() { cout << "\n"; }

const int N = 200005;
pii a[N];

int mp[N][3];

signed main() {
    IO;

    int n;
    cin >> n;
    FOR(i, 1, 2 * n) cin >> a[i].first >> a[i].second;
    
    int ans = 0;
    FOR(i, 1, 2 * n) {
        auto [x, y] = a[i];
        int tarx, tary;
        if (x <= 1) tarx = 1;
        else if (x >= n) tarx = n;
        else tarx = x;

        if (y <= 1) tary = 1;
        else tary = 2;

        ans += abs(tarx - x) + abs(tary - y);
        mp[tarx][tary] += 1;
    }
    
    int U_cnt = 0;
    int D_cnt = 0;
    FOR(i, 1, n) {
        if (mp[i][1] == 0) {
            if (mp[i][2] > 1) {
                mp[i][2] -= 1;
                mp[i][1] += 1;
                ans += 1;
            } else {
                D_cnt += 1;
            }
        }
        if (mp[i][2] == 0) {
            if (mp[i][1] > 1) {
                mp[i][1] -= 1;
                mp[i][2] += 1;
                ans += 1;
            } else {
                U_cnt += 1;
            }
        }
        if (mp[i][1] > 1) {
            if (D_cnt > 0) {
                int dif = min(mp[i][1] - 1, D_cnt);
                D_cnt -= dif;
                mp[i][1] -= dif;
            }
        }
        if (mp[i][2] > 1) {
            if (U_cnt > 0) {
                int dif = min(mp[i][2] - 1, U_cnt);
                U_cnt -= dif;
                mp[i][2] -= dif;
            }
        }
        if (mp[i][1] > 1) {
            if (U_cnt > 0) {
                int dif = min(mp[i][1] - 1, U_cnt);
                U_cnt -= dif;
                mp[i][1] -= dif;
                ans += dif;
            }
        }
        if (mp[i][2] > 1) {
            if (D_cnt > 0) {
                int dif = min(mp[i][2] - 1, D_cnt);
                D_cnt -= dif;
                mp[i][2] -= dif;
                ans += dif;
            }
        }
        if (mp[i][1] > 1) {
            ans += mp[i][1] - 1;
            mp[i + 1][1] += mp[i][1] - 1;
            mp[i][1] = 1;
        }
        if (mp[i][2] > 1) {
            ans += mp[i][2] - 1;
            mp[i + 1][2] += mp[i][2] - 1;
            mp[i][2] = 1;
        }
        ans += U_cnt + D_cnt;
    }
    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Incorrect 1 ms 2396 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Incorrect 1 ms 2396 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Incorrect 1 ms 2396 KB Output isn't correct
10 Halted 0 ms 0 KB -