Submission #1205299

#TimeUsernameProblemLanguageResultExecution timeMemory
1205299chikien2009Coin Collecting (JOI19_ho_t4)C++20
100 / 100
52 ms1608 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, x, y, a[200001][3], b, c;
long long res;

int main()
{
    setup();

    cin >> n;
    for (int i = 0; i < 2 * n; ++i)
    {
        cin >> x >> y;
        b = max(1, min(x, n));
        c = max(1, min(y, 2));
        a[b][c]++;
        res += abs(x - b) + abs(y - c);
    }
    b = c = 0;
    for (int i = 1; i <= n; ++i)
    {
        b += a[i][1] - 1;
        c += a[i][2] - 1;
        while (b < 0 && c > 0)
        {
            res++;
            b++;
            c--;
        }
        while (b > 0 && c < 0)
        {
            res++;
            b--;
            c++;
        }
        res += abs(b + c);
    }
    cout << res;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...