제출 #791743

#제출 시각아이디문제언어결과실행 시간메모리
791743Josia선물상자 (IOI15_boxes)C++17
0 / 100
1 ms212 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;

long long delivery(int N, int K, int L, int p[]) {
    int res = 0;

    map<int, int> poss;

    for (int i = 0; i<N; i++) {
        poss[p[i]]++;
    }

    int cnt = 0;
    int startPos = (*poss.begin()).first;
    int dist;
    while (poss.size()) {
        dist = (*poss.begin()).first;
        poss[(*poss.begin()).first]--;
        if (poss[(*poss.begin()).first] == 0) poss.erase(poss.begin());
        cnt++;
        
        if (cnt == K) {
            if (dist > L/2 && startPos < L/2) res += L;
            else res += min(dist*2, (L-dist)*2);
            startPos = (*poss.begin()).first;
            cnt = 0;
        }
    }
    if (dist > L/2 && startPos < L/2) res += L;
    else res += min(dist*2, (L-dist)*2);
    startPos = (*poss.begin()).first;
    cnt = 0;

    // cerr << res << "\n";
    return res;
}

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:31:25: warning: 'dist' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     else res += min(dist*2, (L-dist)*2);
      |                     ~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...