Submission #1086561

#TimeUsernameProblemLanguageResultExecution timeMemory
1086561PacybwoahBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
515 ms411324 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 cut = n; for(int i = 0; i < n; i++){ if(vec[i] > L / 2){ cut = i; break; } } vector<ll> dpp(n + 1, 1e18), dps(n + 2, 1e18); dpp[0] = 0; for(int i = 1; i <= cut; i++){ dpp[i] = dpp[max(0, i - k)] + 2 * vec[i - 1]; } dps[n + 1] = 0; for(int i = n; i > cut; i--){ dps[i] = dps[min(n + 1, i + k)] + 2 * (L - vec[i - 1]); } if(cut == n){ return dpp[n]; } if(cut == 0){ return dps[1]; } ll ans = dpp[cut] + dps[cut + 1]; vector<ll> pre(n + 2, 1e18); for(int i = cut + 1; i <= n + 1; i++) pre[i] = min(pre[i - 1], dps[i]); for(int i = max(0, cut - k + 1); i <= cut; i++) ans = min(ans, dpp[i] + L + pre[min(n + 1, i + k + 1)]); //for(int i = 1; i <= n; i++) cout << dpp[i] << " " << dps[i] << "\n"; 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:10:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   10 |     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...