Submission #589859

#TimeUsernameProblemLanguageResultExecution timeMemory
589859FatihSolakBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
1 ms308 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int n, int k, int l, int p[]) { vector<int> a,b; for(int i = 0;i<n;i++){ if(2*p[i] <= l){ a.push_back(p[i]); } } for(int i = n-1;i>=0;i--){ if(2*(l-p[i]) < l){ b.push_back(p[i]); } } vector<long long> dpa(a.size(),0),dpb(b.size(),0); for(int i = 0;i<a.size();i++){ dpa[i] = 2 * a[i]; if(i - k >= 0){ dpa[i] += dpa[i-k]; } } for(int i = 0;i<b.size();i++){ dpb[i] = 2 * (l-b[i]); if(i - k >= 0){ dpb[i] += dpb[i-k]; } } if(b.empty())return dpa[a.size()-1]; if(a.empty())return dpb[b.size()-1]; long long ans = dpa[a.size()-1] + dpb[b.size()-1]; for(int i = a.size()-k;i<a.size();i++){ long long val = l; if(i >= 0){ val += dpa[i]; } if(b.size()-1 - (k-(a.size() - i - 1)) >= 0){ val += dpb[b.size()-1 - (k-(a.size() - i - 1))]; } ans = min(ans,val); } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 0;i<a.size();i++){
      |                   ~^~~~~~~~~
boxes.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0;i<b.size();i++){
      |                   ~^~~~~~~~~
boxes.cpp:32:25: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   32 |     for(int i = a.size()-k;i<a.size();i++){
      |                 ~~~~~~~~^~
boxes.cpp:32:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = a.size()-k;i<a.size();i++){
      |                            ~^~~~~~~~~
boxes.cpp:37:48: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
   37 |         if(b.size()-1 - (k-(a.size() - i - 1)) >= 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...