답안 #100979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100979 2019-03-15T16:35:36 Z Alexa2001 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int Nmax = 2e5 + 5;

int a[Nmax][3], s[3], wait[3], n;
ll ans = 0;

void read()
{
    int x, y, i;

    cin >> n;
    for(i=1; i<=2*n; ++i)
    {
        cin >> x >> y;
        if(x < 1) ans += 1 - x, x = 1;
        if(x > n) ans += x - n, x = n;
        if(y < 1) ans += 1 - y, y = 1;
        if(y > 2) ans += y - 2, y = 2;

        ++a[x][y];
    }
}

void solve()
{
    int i, j, k1, k2;
    k1 = 1; k2 = 0;

    for(i=1; i<=n; ++i)
        for(j=0; j<a[i][1] + a[i][2]; ++j)
        {
            if(k1 < i) ans += i - k1;
                else if(k1 > i) ans += k1 - i;
            if(k2) ++k1;
            k2 ^= 1;
        }

    for(i=1; i<=n; ++i)
    {
        ++wait[1];
        ++wait[2];

        while(wait[1] && a[i][1]) --wait[1], --a[i][1];
        while(wait[2] && a[i][2]) --wait[2], --a[i][2];

        while(wait[1] && a[i][2]) --wait[1], --a[i][2], ++ans;
        while(wait[2] && a[i][1]) --wait[2], --a[i][1], ++ans;

        while(wait[1] && s[1]) --wait[1], --s[1];
        while(wait[2] && s[2]) --wait[2], --s[2];
        while(wait[1] && s[2]) --wait[1], --s[2], ++ans;
        while(wait[2] && s[1]) --wait[2], --s[1], ++ans;

        s[1] += a[i][1]; s[2] += a[i][2];
    }
    cout << ans << '\n';
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    read();
    solve();

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