제출 #98851

#제출 시각아이디문제언어결과실행 시간메모리
98851bogdan10bosCoin Collecting (JOI19_ho_t4)C++14
100 / 100
109 ms4984 KiB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;
typedef pair<int, int> pii;

int N;
int cnt[100005][3];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    LL pre = 0, ans = 0;
    scanf("%d", &N);
    for(int i = 1; i <= 2 * N; i++)
    {
        int x, y, nx, ny;
        scanf("%d%d", &x, &y);

        if(y <= 1)  ny = 1;
        else    ny = 2;

        if(1 <= x && x <= N)    nx = x;
        else if(x < 1)  nx = 1;
        else    nx = N;

        cnt[nx][ny]++;
        pre += 1LL * abs(nx - x) + 1LL * abs(ny - y);
    }

    int up = 0, down = 0, sum = 0;
    for(int i = 1; i <= N; i++)
    {
        up += cnt[i][2] - 1;
        down += cnt[i][1] - 1;
        sum += cnt[i][1] + cnt[i][2];

        ans += abs(sum - 2 * i);
        if(up > 0 && down < 0)
        {
            int add = min(up, -down);
            ans += add;
            down += add, up -= add;
        }
        if(down > 0 && up < 0)
        {
            int add = min(-up, down);
            ans += add;
            down -= add, up += add;
        }
    }

    printf("%lld\n", pre + ans);
    /*printf("%lld\n", ans);
    for(int i = 1; i <= 2; i++)
        for(int j = 1; j <= N; j++)
            printf("%d%c", cnt[j][i], " \n"[j == N]);*/

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...