Submission #63773

#TimeUsernameProblemLanguageResultExecution timeMemory
63773KubalionzzaleBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
2 ms380 KiB
#include "boxes.h" #include <map> #include <iostream> #include <algorithm> long long int keepleft[10000010] = { 0 }, keepright[10000010] = { 0 }; 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) { int cur = k - 1; long long int sum = p[n - 1]; for (int i = n - 2; i >= 0; --i) { if (cur == 0) { sum += p[i + 1] * 2LL + p[i] - p[i + 1]; cur = k - 1; } else { sum += p[i] - p[i + 1] * 1LL; --cur; } } return sum + p[0] * 1LL; } else if (here == n) { int cur = k - 1; long long int sum = p[0]; for (int i = 1; i < n; ++i) { if (cur == 0) { sum += p[i - 1] * 2LL + p[i] - p[i - 1]; cur = k - 1; } else { sum += p[i] - p[i - 1] * 1LL; --cur; } } return sum + p[n - 1] * 1LL; } long long int sumleft = p[0], leftleft = -1; int cur = k - 1; for (int i = 1; i < here; ++i) { if (cur == 0) { sumleft += p[i - 1] * 2LL + p[i] - p[i - 1]; cur = k - 1; } else { sumleft += p[i] - p[i - 1] * 1LL; --cur; } keepleft[i] = sumleft; } sumleft += p[here - 1]; leftleft = cur; long long int sumright = p[n - 1], leftright = -1; cur = k - 1; for (int i = n - 2; i >= here; --i) { if (cur == 0) { sumright += p[i + 1] * 2LL + p[i] - p[i + 1]; cur = k - 1; } else { sumright += p[i] - p[i + 1] * 1LL; --cur; } keepright[i] = sumright; } sumright += p[here]; leftright = cur; long long int curmin = sumleft + sumright; return curmin; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:69:35: warning: variable 'leftleft' set but not used [-Wunused-but-set-variable]
     long long int sumleft = p[0], leftleft = -1;
                                   ^~~~~~~~
boxes.cpp:91:40: warning: variable 'leftright' set but not used [-Wunused-but-set-variable]
     long long int sumright = p[n - 1], leftright = -1;
                                        ^~~~~~~~~
#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...