Submission #285946

#TimeUsernameProblemLanguageResultExecution timeMemory
285946OzyBoxes with souvenirs (IOI15_boxes)C++17
0 / 100
1 ms384 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) vector<int> izq,der,arr; long long delivery(int N, int K, int L, int p[]) { int mitad,a,ini,fin,b,cont,Ma,Mb; long long int res,MIN,sum; res = 0; mitad = L/2; izq.clear(); der.clear(); arr.clear(); rep(i,0,N-1) { if (p[i] <= mitad) izq.push_back(p[i]); else der.push_back(-p[i]); } sort(izq.begin(),izq.end()); sort(der.begin(),der.end()); cont = 0; while ((izq.size() - cont) >= K) { rep(i,1,K-1) cont++; res += 2*(izq[cont]); cont++; } if (cont < izq.size()) Ma = izq[izq.size()-1]; for(int i = cont; i < izq.size(); i++) arr.push_back(izq[i]); cont = 0; while ((der.size() - cont) >= K) { rep(i,1,K-1) cont++; a = (L - der[cont]); res += 2*a; cont++; } if (cont < der.size()) Mb = -der[der.size()-1]; for(int i = cont; i < der.size(); i++) arr.push_back(-der[i]); sort(arr.begin(), arr.end()); if (!arr.empty() && arr.size() < K) { a = arr[0]; b = arr[arr.size()-1]; if (a > mitad) res += 2*(L-a); else if (b <= mitad) res += (2*b); else { Mb = L-Mb; a = min(L,(Ma+Mb)); res += a; } } else if(!arr.empty() && arr.size() >= K){ res += L; MIN = L; ini = -1; fin = K; rep(i,1,(arr.size()-K)+1) { a = 0; b = 0; if (ini >= 0) a = 2*arr[ini]; if (fin < arr.size()) b = 2*(L - arr[fin]); sum = a+b; MIN = min(sum,MIN); ini++; fin++; } res += MIN; } cerr << res; return res; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:26:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |     while ((izq.size() - cont) >= K) {
      |            ~~~~~~~~~~~~~~~~~~~~^~~~
boxes.cpp:31:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     if (cont < izq.size()) Ma = izq[izq.size()-1];
      |         ~~~~~^~~~~~~~~~~~
boxes.cpp:32:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = cont; i < izq.size(); i++) arr.push_back(izq[i]);
      |                       ~~^~~~~~~~~~~~
boxes.cpp:36:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     while ((der.size() - cont) >= K) {
      |            ~~~~~~~~~~~~~~~~~~~~^~~~
boxes.cpp:42:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     if (cont < der.size()) Mb = -der[der.size()-1];
      |         ~~~~~^~~~~~~~~~~~
boxes.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i = cont; i < der.size(); i++)
      |                       ~~^~~~~~~~~~~~
boxes.cpp:47:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |     if (!arr.empty() && arr.size() < K) {
      |                         ~~~~~~~~~~~^~~
boxes.cpp:60:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     else if(!arr.empty() && arr.size() >= K){
      |                             ~~~~~~~~~~~^~~~
boxes.cpp:4:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for (int i = (a); i <= (b); i++)
      |                                        ^
boxes.cpp:67:9: note: in expansion of macro 'rep'
   67 |         rep(i,1,(arr.size()-K)+1) {
      |         ^~~
boxes.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |              if (fin < arr.size()) b = 2*(L - arr[fin]);
      |                  ~~~~^~~~~~~~~~~~
boxes.cpp:54:16: warning: 'Mb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |             Mb = L-Mb;
      |             ~~~^~~~~~
boxes.cpp:56:26: warning: 'Ma' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |             a = min(L,(Ma+Mb));
      |                       ~~~^~~~
#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...