Submission #591255

# Submission time Handle Problem Language Result Execution time Memory
591255 2022-07-07T07:00:10 Z piOOE Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 408 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, 1));
    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];
    }
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 408 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 408 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 408 KB Output isn't correct
7 Halted 0 ms 0 KB -