Submission #301817

#TimeUsernameProblemLanguageResultExecution timeMemory
301817square1001Boxes with souvenirs (IOI15_boxes)C++14
100 / 100
610 ms255060 KiB
#include "boxes.h" #include <vector> #include <algorithm> using namespace std; long long delivery(int N, int K, int L, int p[]) { vector<int> pl, pr; for(int i = 0; i < N; ++i) { if(p[i] * 2 <= L) { pl.push_back(p[i]); } else { pr.push_back(L - p[i]); } } reverse(pr.begin(), pr.end()); int NL = pl.size(), NR = pr.size(); vector<long long> dpl(NL + 1), dpr(NR + 1); for(int i = 0; i < NL; ++i) { dpl[i + 1] = dpl[max(i - K + 1, 0)] + pl[i]; } for(int i = 0; i < NR; ++i) { dpr[i + 1] = dpr[max(i - K + 1, 0)] + pr[i]; } long long ans = dpl[NL] * 2 + dpr[NR] * 2; for(int i = 0; i <= NL; ++i) { int t = N - i - K; if(0 <= t && t <= NR) { ans = min(ans, dpl[i] * 2 + dpr[t] * 2 + L); } } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:16:18: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   16 |  int NL = pl.size(), NR = pr.size();
      |           ~~~~~~~^~
boxes.cpp:16:34: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   16 |  int NL = pl.size(), NR = pr.size();
      |                           ~~~~~~~^~
#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...