답안 #511032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
511032 2022-01-15T04:41:46 Z blue Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 204 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;

    vvi A(1+2, vi(1+N, 0));

    ll ans = 0;

    for(int i = 1; i <= 2*N; i++)
    {
        int X, Y;
        cin >> X >> Y;

        if(Y <= 1)
        {
            ans += 1-Y;
            Y = 1;
        }
        else
        {
            ans += Y-2;
            Y = 2;
        }

        if(X < 1)
        {
            ans += 1-X;
            X = 1;
        }
        else if(X > N)
        {
            ans += X-N;
            X = N;
        }

        A[Y][X]++;
    }

    for(int i = 1; i <= N; i++)
    {
        A[1][i]--;
        A[2][i]--;

        ll mov = 0;

        if(A[1][i] >= 0 && A[2][i] < 0)
        {
            mov = min(A[1][i], -A[2][i]);
        }
        else if(A[1][i] < 0 && A[2][i] >= 0)
        {
            mov = max(A[1][i], -A[2][i]);
        }

        // A[1][i] -= mov;
        // A[2][i] += mov;
        // ans += abs(mov);

        if(i < N)
        {
            A[1][i+1] += A[1][i];
            A[2][i+1] += A[2][i];
            ans += abs(A[1][i]);
            ans += abs(A[2][i]);
        }
    }

    cout << ans << '\n';
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:57:12: warning: variable 'mov' set but not used [-Wunused-but-set-variable]
   57 |         ll mov = 0;
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -