제출 #674833

#제출 시각아이디문제언어결과실행 시간메모리
674833benjaminkleyn선물상자 (IOI15_boxes)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; typedef long long ll; ll delivery(int n, int k, int l, int p[]) { vector<ll> L, R; for (int i = 0; i < n; i++) else if (l - p[i] < p[i]) L.push_back(l - p[i]); else R.push_back(p[i]); sort(L.rbegin(), L.rend()); sort(R.rbegin(), R.rend()); ll ans = 0; while (L.size() >= k) { for (int i = 0; i < k - 1; i++) L.pop_back(); ans += 2 * L.back(); L.pop_back(); } while (R.size() >= k) { for (int i = 0; i < k - 1; i++) R.pop_back(); ans += 2 * R.back(); R.pop_back(); } if (L.size() == 0) ans += 2 * R.back(); else if (R.size() == 0) ans += 2 * L.back(); else if (L.size() + R.size() <= k) ans += l; else ans += l + min(R[k - L.size()], L[k - R.size()]); return ans; }

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

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:10:9: error: expected primary-expression before 'else'
   10 |         else if (l - p[i] < p[i])
      |         ^~~~
boxes.cpp:12:9: error: 'else' without a previous 'if'
   12 |         else
      |         ^~~~
boxes.cpp:13:27: error: 'i' was not declared in this scope
   13 |             R.push_back(p[i]);
      |                           ^
boxes.cpp:20:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     while (L.size() >= k)
      |            ~~~~~~~~~^~~~
boxes.cpp:22:18: warning: declaration of 'i' shadows a previous local [-Wshadow]
   22 |         for (int i = 0; i < k - 1; i++)
      |                  ^
boxes.cpp:13:27: note: shadowed declaration is here
   13 |             R.push_back(p[i]);
      |                           ^
boxes.cpp:27:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while (R.size() >= k)
      |            ~~~~~~~~~^~~~
boxes.cpp:29:18: warning: declaration of 'i' shadows a previous local [-Wshadow]
   29 |         for (int i = 0; i < k - 1; i++)
      |                  ^
boxes.cpp:13:27: note: shadowed declaration is here
   13 |             R.push_back(p[i]);
      |                           ^
boxes.cpp:38:34: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |     else if (L.size() + R.size() <= k)
      |              ~~~~~~~~~~~~~~~~~~~~^~~~