제출 #968595

#제출 시각아이디문제언어결과실행 시간메모리
968595alex_2008선물상자 (IOI15_boxes)C++14
컴파일 에러
0 ms0 KiB
#include "boxes.h" #include <iostream> #include <vector> #include <algorithm> typedef long long ll; using namespace std; ll delivery(int n, int k, int l, vector <int> pos) { vector <int> a, b; vector <ll> dp_a, dp_b; for (int i = 0; i < n; i++) { if (pos[i] <= (l / 2)) a.push_back(pos[i]); else b.push_back(pos[i]); } reverse(b.begin(), b.end()); for (auto &it : b) { it = l - it; } dp_a.resize((int)a.size()); dp_b.resize((int)b.size()); for (int i = 0; i < (int)dp_a.size(); i++) { if (i < k) { dp_a[i] = 2 * a[i]; } else { dp_a[i] = dp_a[i - k] + 2 * a[i]; } } for (int i = 0; i < (int)dp_b.size(); i++) { if (i < k) { dp_b[i] = 2 * b[i]; } else { dp_b[i] = dp_b[i - k] + 2 * b[i]; } } int ind1 = 0, ind2 = 0; ll ans = l * 1ll * ((n + k - 1) / k); ll cur = 0; for (int i = 1; i <= n; i++) { if (ind1 == dp_a.size()) { if (ind2) cur -= dp_b[ind2 - 1]; cur += dp_b[ind2]; ind2++; } else if (ind2 == dp_b.size()) { if (ind1) cur -= dp_a[ind1 - 1]; cur += dp_a[ind1]; ind1++; } else { ll diff1 = dp_a[ind1]; if (ind1) diff1 -= dp_a[ind1 - 1]; ll diff2 = dp_b[ind2]; if (ind2) diff2 -= dp_b[ind2 - 1]; if (diff1 <= diff2) { cur += diff1; ind1++; } else { cur += diff2; ind2++; } } ans = min(ans, ((n - i + k - 1) / k * 1ll * l) + cur); } return ans; } /* int main() { cout << delivery(3, 2, 8, { 1, 2, 5 }) << "\n"; }*/

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

boxes.cpp: In function 'll delivery(int, int, int, std::vector<int>)':
boxes.cpp:40:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if (ind1 == dp_a.size()) {
      |       ~~~~~^~~~~~~~~~~~~~
boxes.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   else if (ind2 == dp_b.size()) {
      |            ~~~~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccVE5DHl.o: in function `main':
grader.c:(.text.startup+0x1ef): undefined reference to `delivery(int, int, int, int*)'
collect2: error: ld returned 1 exit status