제출 #646817

#제출 시각아이디문제언어결과실행 시간메모리
646817Alex_tz307선물상자 (IOI15_boxes)C++17
100 / 100
513 ms293768 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; /* static char _buffer[1024]; static int _currentChar = 0; static int _charsNumber = 0; static FILE *_inputFile, *_outputFile; static inline int _read() { if (_charsNumber < 0) { exit(1); } if (!_charsNumber || _currentChar == _charsNumber) { _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile); _currentChar = 0; } if (_charsNumber <= 0) { return -1; } return _buffer[_currentChar++]; } static inline int _readInt() { int c, x, s; c = _read(); while (c <= 32) c = _read(); x = 0; s = 1; if (c == '-') { s = -1; c = _read(); } while (c > 32) { x *= 10; x += c - '0'; c = _read(); } if (s < 0) x = -x; return x; } */ const int64_t INF = 1e18L; void minSelf(int64_t &x, int64_t y) { if (y < x) { x = y; } } long long delivery(int n, int k, int L, int p[]) { vector<int64_t> l(n + 1), r(n + 2); /// l[i] =def= costul minim sa livrez 1..i mergand doar la dreapta cand livrez si intorcandu-ma la inceput in ce directie vreau /// Analog r[i] in sens invers for (int i = 1; i <= n; ++i) { int last = max(0, i - k); l[i] = l[last] + p[i - 1] + min(p[i - 1], L - p[i - 1]); } for (int i = n; i > 0; --i) { int nxt = min(n + 1, i + k); r[i] = r[nxt] + (L - p[i - 1]) + min(p[i - 1], L - p[i - 1]); } int64_t best = INF; for (int i = 0; i <= n; ++i) { minSelf(best, l[i] + r[i + 1]); } /// Observatie: Va fi maxim o tura de impartit cadouri in care parcurg cercul complet si aia va fi /// ultima, in care voi imparti toate cadourile ramase, asa ca fixez si variantele in care am k /// cadouri ramase si la final si parcurg tot cercul for (int i = 0; i <= n - k; ++i) { minSelf(best, l[i] + r[i + k + 1] + L); } return best; } /* int main() { _inputFile = fopen("boxes.in", "rb"); _outputFile = fopen("boxes.out", "w"); int N, K, L, i; N = _readInt(); K = _readInt(); L = _readInt(); int *p = (int*)malloc(sizeof(int) * (unsigned int)N); for (i = 0; i < N; i++) { p[i] = _readInt(); } fprintf(_outputFile, "%lld\n", delivery(N, K, L, p)); return 0; } */
#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...