제출 #122935

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

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, ll >
#define pii pair < int, pi >
#define vii vector < pi >

const int N = 3e5 + 7;
const int INF = 1e9 + 7;

int a[N][3];
int n;
ll ans;

void close (ll &v, int r){
    if (v < 1){
        ans += abs(1 - v);
        v = 1;
    }
    if (v > r){
        ans += abs(r - v);
        v = r;
    }
}

main(){
    cin >> n;
    ll x, y;
    for (int i = 1; i <= 2 * n; i++){
        scanf("%lld%lld", &x, &y);
        close(x, n);
        close(y, 2);
        a[x][y]++;
    }
    for (int i = 1; i <= n; i++){
        a[i][1]--; a[i][2]--;
        if (min(a[i][1], a[i][2]) < 0 && max(a[i][1], a[i][2]) > 0){
            int t = min(abs(a[i][1]), abs(a[i][2]));
            ans += t;
            if (a[i][1] > a[i][2]){
                a[i][1] -= t;
                a[i][2] += t;
            }
            else {
                a[i][1] += t;
                a[i][2] -= t;
            }
        }
        ans += abs(a[i][1]) + abs(a[i][2]);
        a[i + 1][1] += a[i][1];
        a[i + 1][2] += a[i][2];
    }
    cout << ans;
}

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

joi2019_ho_t4.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...