답안 #591252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591252 2022-07-07T06:57:41 Z piOOE Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> a(2, vector<int>(n)), b(2, vector<int>(n));
    ll ans = 0;
    for (int i = 0; i < 2 * n; ++i) {
        int x, y;
        cin >> x >> y;
        if (y >= 2) {
            ans += y - 2;
            y = 2;
        } else {
            ans += 1 - y;
            y = 1;
        }
        if (x < 1) {
            ans += 1 - x;
            x = 1;
        } else if (x > n) {
            ans += x - n;
            x = n;
        }
        ++a[y - 1][x - 1];
    }
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[i][j] > 0) {
                a[i][j] -= 1;
                b[i][j] = 0;
            } else {
                b[i][j] = 1;
            }
        }
    }
    array<int, 2> d{};
    for (int i = 0; i < n; ++i) {
        for (int t = 0; t < 2; ++t) {
            if (b[t][i]) {
                d[t] -= 1;
            }
            if (a[t][i]) {
                d[t] += 1;
            }
        }
        if (d[0] < 0 && d[1] > 0) {
            int mn = min(-d[0], d[1]);
            d[0] += mn;
            d[1] -= mn;
            ans += mn;
        } else if (d[1] < 0 && d[0] > 0) {
            int mn = min(-d[1], d[0]);
            d[1] += mn;
            d[0] -= mn;
            ans += mn;
        }
        ans += abs(d[0] + d[1]);
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -