Submission #1086537

#TimeUsernameProblemLanguageResultExecution timeMemory
1086537PacybwoahBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
1 ms348 KiB
#include "boxes.h" #include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long ll; long long delivery(int N, int K, int L, int p[]) { vector<int> vec; for(int i = 0; i < N; i++) if(p[i] != 0) vec.push_back(p[i]); int n = vec.size(); if(n == 0) return 0; int k = K; int trips = n / k; //if(n % k != 0) trips++; auto calc = [&](int l, int r){ if(l > r) return 0; return min(min(vec[r] * 2, (L - vec[l]) * 2), L); }; vector<ll> pre(trips + 1); for(int i = 0; i < trips; i++){ if(i == 0) pre[i] = calc(0, k - 1); else pre[i] = pre[i - 1] + calc(i * k, i * k + k - 1); } ll suf = 0; int lnow = trips * k, rnow = n - 1, prenow = trips - 1; ll ans = 1e18; while(prenow >= 0){ ans = min(ans, suf + pre[prenow] + calc(lnow, rnow)); prenow--; lnow -= k; rnow -= k; suf += calc(rnow + 1, rnow + k); } ans = min(ans, suf + calc(lnow, rnow)); return ans; } // g++ -std=c++17 -o run -Wshadow -Wall -Wextra -fsanitize=undefined -fsanitize=address boxes.cpp grader.cpp

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:11:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   11 |     int n = vec.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...