제출 #968599

#제출 시각아이디문제언어결과실행 시간메모리
968599alex_2008선물상자 (IOI15_boxes)C++17
컴파일 에러
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 == (int)dp_a.size()) { if (ind2) cur -= dp_b[ind2 - 1]; cur += dp_b[ind2]; ind2++; } else if (ind2 == (int)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() { int n, k, l; cin >> n >> k >> l; vector <int> v(n); for (auto &it : v) { cin >> it; } cout << delivery(n, k, l, v) << "\n"; }

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

/usr/bin/ld: /tmp/ccSlnO9q.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccBQoaxq.o:boxes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccSlnO9q.o: in function `main':
grader.c:(.text.startup+0x1ef): undefined reference to `delivery(int, int, int, int*)'
collect2: error: ld returned 1 exit status