Submission #931972

#TimeUsernameProblemLanguageResultExecution timeMemory
931972Art_ogoBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
438 ms293996 KiB
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <algorithm> #include <utility> #include <vector> #include <iostream> #include "boxes.h" #define ll long long #define ve vector using namespace std; int dst(int x, int L){ return min(x, L - x); } long long delivery(int N, int K, int L, int p[]) { ve<ll> dpl(N), dpr(N); int cnt = 1; for(int i = 0; i < N; i++){ if(i - K >= 0) dpl[i] = p[i] - p[i - K] + dpl[i - K] + 2*p[i - K]; else dpl[i] = p[i]; } for(int i = N - 1; i >= 0; i--){ if(i + K < N) dpr[i] = p[i + K] - p[i] + dpr[i + K] + 2*(L - p[i + K]); else dpr[i] = L - p[i]; } ll res = min(dpl[N - 1] + dst(p[N - 1], L), dpr[0] + dst(p[0], L)); for(int i = 0; i < N - 1; i++) res = min(res, dpl[i] + dst(p[i], L) + dpr[i + 1] + dst(p[i + 1], L)); return res; } // //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 x; // std::cin >> x; // return x; //} // //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(); // } // cout << delivery(N, K, L, p); // return 0; //}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:22:9: warning: unused variable 'cnt' [-Wunused-variable]
   22 |     int cnt = 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...