제출 #1105498

#제출 시각아이디문제언어결과실행 시간메모리
1105498salmonCoin Collecting (JOI19_ho_t4)C++14
100 / 100
47 ms7388 KiB
#include <bits/stdc++.h>
using namespace std;

int N;
int lst[200100][3];
vector<pair<int,int>> v;
int h1,h2;
long long int ans = 0;

int main(){

    scanf(" %d",&N);

    for(int i = 1; i <= N; i++){
        lst[i][1] = 0;
        lst[i][2] = 0;
    }

    for(int i = 0; i < N * 2; i++){
        scanf(" %d",&h1);
        scanf(" %d",&h2);

        if(h2 >= 2){
            ans += h2 - 2;
            h2 = 2;
        }
        else{
            ans += 1 - h2;
            h2 = 1;
        }

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

        lst[h1][h2]++;
    }

    int num = 0;
    long long int num1 = 0;

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

        if(num * num1 < 0){
            ans += min(abs(num),(int)abs(num1));
            int temp = min(abs(num),(int)abs(num1));

            num -= num/abs(num) * temp;
            num1 -= num1/abs(num1) * temp;
        }

        ans += abs(num) + abs(num1);
    }

    printf("%lld",ans);

}

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

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