Submission #1294480

#TimeUsernameProblemLanguageResultExecution timeMemory
1294480ghammazhassanBoxes with souvenirs (IOI15_boxes)C++20
10 / 100
1 ms580 KiB
#include "boxes.h" #include <iostream> #include <cmath> #include <algorithm> #include <map> #include <unordered_map> #include <vector> #include <iomanip> #include <string> #include <queue> #include <set> #include <deque> 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; // } int n,k,l; int dis(int x){ return min(x,l-x); } long long delivery(int N,int K,int L, int b[]){ n=N,k=K,l=L; deque<int>a; for (int i=0;i<n;i++){ a.push_back(b[i]); } int c=0; k--; while (a.size()){ int p; if (dis(a.front())<=dis(a.back())){ p=a.front(); a.pop_front(); c+=dis(p); for (int i=0;i<k;i++){ if (!a.size())break; if (dis(a.front())+dis(p)<=abs(p-a.front())){ break; } c+=abs(p-a.front()); p=a.front(); a.pop_front(); } c+=dis(p); } else{ p=a.back(); a.pop_back(); c+=dis(p); for (int i=0;i<k;i++){ if (!a.size())break; if (dis(a.back())+dis(p)<=abs(p-a.back())){ break; } c+=abs(p-a.back()); p=a.back(); a.pop_back(); } c+=dis(p); } } return c; } // int main() { // _inputFile = fopen("input.txt", "rb"); // _outputFile = fopen("output.txt", "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...