제출 #63787

#제출 시각아이디문제언어결과실행 시간메모리
63787Kubalionzzale선물상자 (IOI15_boxes)C++14
0 / 100
2 ms376 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; keepleft[0] = p[0]; 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; keepright[n - 1] = p[n - 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; long long int curleft = keepleft[here - 1]; cur = leftleft; bool flag = false; for (int i = here; i < n; ++i) { if (cur == 0) { curleft += p[i] * 2LL + keepright[i]; if (i == here) { curleft += (l - p[i]) * 1LL - p[i - 1]; } else { curleft += p[i - 1] - p[i] * 1LL; } flag = true; break; } else { if (i == here) { curleft += (l - p[i]) * 1LL - p[i - 1]; } else { curleft += p[i - 1] - p[i] * 1LL; } --cur; } } if (!flag) { curleft += p[n - 1] * 1LL; } if (leftleft == 0) curleft = 1e17; curmin = std::min(curmin, curleft); long long int curright = keepright[here]; cur = leftright; flag = false; for (int i = here - 1; i >= 0; --i) { if (cur == 0) { curright += p[i] * 2LL + keepleft[i]; if (i + 1 == here) { curright += (l - p[i + 1] * 1LL) - p[i]; } else { curright += p[i + 1] - p[i] * 1LL; } flag = true; break; } else { if (i + 1 == here) { curright += (l - p[i + 1] * 1LL) - p[i]; } else { curright += p[i + 1] - p[i] * 1LL; } --cur; } } if (!flag) { curright += p[0] * 1LL; } if (leftright == 0) curright = 1e17; curmin = std::min(curmin, curright); std::cout << curmin << " " << curleft << " " << curright << "\n"; return curmin; }

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:118:11: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     cur = leftleft;
           ^~~~~~~~
boxes.cpp:163:11: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     cur = leftright;
           ^~~~~~~~~
#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...