Submission #481663

# Submission time Handle Problem Language Result Execution time Memory
481663 2021-10-21T09:53:39 Z Rainbowbunny Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200005;

int n;
long long ans;
long long cnt[MAXN][2];
long long X[MAXN], Y[MAXN];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= 2 * n; i++)
    {
        cin >> X[i] >> Y[i];
        if(X[i] <= 0)
        {
            ans += (1 - X[i]);
            X[i] = 1;
        }
        if(X[i] > n)
        {
            ans += abs(X[i] - n);
            X[i] = n;
        }
        if(X[i] >= 1 and X[i] <= n)
        {
            if(Y[i] <= 1)
            {
                ans += abs(Y[i] - 1);
                Y[i] = 1;
            }
            else
            {
                ans += abs(Y[i] - 2);
                Y[i] = 2;
            }
            cnt[X[i]][Y[i] - 1]++;
        }
    }
    int cur = 1, id = 0, lst = -1;
    for(int i = 1; i <= n; i++)
    {
        if(cnt[i][1] == 0 and cnt[i][0] == 0)
        {
            continue;
        }
        if(lst != -1)
        {
            ans += abs(lst - cur);
            ans += abs(i - cur);
            lst = -1;
            if(cnt[i][id ^ 1])
            {
                cnt[i][id ^ 1]--;
            }
            else
            {
                cnt[i][id]--;
                ans++;
            }
            cur++;
        }
        while(cnt[i][1] > 0 and cnt[i][0] > 0)
        {
            ans += abs(i - cur);
            ans += abs(i - cur);
            cnt[i][1]--;
            cnt[i][0]--;
            cur++;
        }
        while(cnt[i][0] > 1)
        {
            ans += abs(i - cur);
            ans += abs(i - cur);
            ans++;
            cur++;
            cnt[i][0] -= 2;
        }
        while(cnt[i][1] > 1)
        {
            ans += abs(i - cur);
            ans += abs(i - cur);
            ans++;
            cur++;
            cnt[i][1] -= 2;
        }
        if(cnt[i][0])
        {
            lst = i;
            id = 0;
        }
        if(cnt[i][1])
        {
            lst = i;
            id = 1;
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -