Submission #64032

#TimeUsernameProblemLanguageResultExecution timeMemory
64032KubalionzzaleBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
2 ms380 KiB
#include "boxes.h" #include <map> #include <iostream> #include <algorithm> long long delivery(int n, int k, int l, int p[]) { if (n == 1) { return std::min(p[0] * 2LL, (l - p[0]) * 2LL); } int here = n; for (int i = 0; i < n; ++i) { if (p[i] > l - p[i] && here == n) { here = i; } if (i >= here) { p[i] = l - p[i]; } } if (here == 0) { long long int sumleft = p[0], leftleft = -1; int cur = k - 1; for (int i = 1; i < n; ++i) { if (cur == 0) { sumleft += p[i - 1] + p[i] * 1LL; cur = k - 1; } else { sumleft += p[i - 1] - p[i] * 1LL; --cur; } } sumleft += p[n - 1] * 1LL; return sumleft; } else if (here == n) { long long int sumright = p[here - 1], leftright = -1; int cur = k - 1; for (int i = here - 2; i >= 0; --i) { if (cur == 0) { sumright += p[i + 1] + p[i] * 1LL; cur = k - 1; } else { sumright += p[i + 1] - p[i] * 1LL; --cur; } } sumright += p[0] * 1LL; return sumright; } long long int sumleft = p[here - 1], leftleft = -1; int cur = k - 1; for (int i = here - 2; i >= 0; --i) { if (cur == 0) { sumleft += p[i + 1] + p[i] * 1LL; cur = k - 1; } else { sumleft += p[i + 1] - p[i] * 1LL; --cur; } } sumleft += p[0] * 1LL; long long int sumright = p[here], leftright = -1; cur = k - 1; for (int i = here + 1; i < n; ++i) { if (cur == 0) { sumright += p[i - 1] + p[i] * 1LL; cur = k - 1; } else { sumright += p[i - 1] - p[i] * 1LL; --cur; } } sumright += p[n - 1] * 1LL; leftright = cur; long long int curmin = sumleft + sumright; if (k == 1) return curmin; long long int curval, min = 1e17; /* int where = std::max(here - k + 1, 0), start; for (int i = std::max(here - k + 1, 0);; ++i) { if (i >= here) break; if (i + k - 1 >= n) break; curval = l; if (i != 0) { start = i - 1; curval += p[start] * 1LL; while (1) { curval += p[start] * 2LL; if (start - k >= 0) { curval += p[start] - p[start - k] * 1LL; start -= k; } else { curval += p[start]; break; } } } if (i + k - 1 < n - 1) { start = i + k; curval += p[start] * 1LL; while (1) { curval += p[start] * 2LL; if (start + k < n) { curval += p[start] - p[start + k] * 1LL; start -= k; } else { curval += p[start]; break; } } } if (curval < min) min = curval; }*/ return std::min(curmin, min); }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:39: warning: unused variable 'leftleft' [-Wunused-variable]
         long long int sumleft = p[0], leftleft = -1;
                                       ^~~~~~~~
boxes.cpp:51:47: warning: unused variable 'leftright' [-Wunused-variable]
         long long int sumright = p[here - 1], leftright = -1;
                                               ^~~~~~~~~
boxes.cpp:73:42: warning: unused variable 'leftleft' [-Wunused-variable]
     long long int sumleft = p[here - 1], leftleft = -1;
                                          ^~~~~~~~
boxes.cpp:92:39: warning: variable 'leftright' set but not used [-Wunused-but-set-variable]
     long long int sumright = p[here], leftright = -1;
                                       ^~~~~~~~~
boxes.cpp:117:19: warning: unused variable 'curval' [-Wunused-variable]
     long long int curval, min = 1e17;
                   ^~~~~~
#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...