Submission #1012811

#TimeUsernameProblemLanguageResultExecution timeMemory
1012811LuvidiBoxes with souvenirs (IOI15_boxes)C++17
50 / 100
2056 ms29628 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back long long delivery(int N, int K, int L, int p[]) { ll n=N,k=K,l=L; vector<ll> v1,v2; for(int i=0;i<n;i++){ if(p[i]<=l/2)v1.pb(p[i]); else v2.pb(l-p[i]); } int l1=v1.size(),l2=v2.size(); sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end()); ll dp1[l1+1],dp2[l2+1]; dp1[0]=dp2[0]=0; for(int i=0;i<l1;i++){ if(i<k)dp1[i+1]=2*v1[i]; else dp1[i+1]=2*v1[i]+dp1[i-k+1]; } for(int i=0;i<l2;i++){ if(i<k)dp2[i+1]=2*v2[i]; else dp2[i+1]=2*v2[i]+dp2[i-k+1]; } ll ans=dp1[l1]+dp2[l2]; ans=min(ans,(n+k-1)/k*l); for(ll x=1;x<=n/k;x++){ for(ll i=1;i<=l1;i++){ if(i+x*k<=l1)continue; ll j=l2-(i+x*k-l1-2); if(j<1)continue; ans=min(ans,x*l+dp1[i-1]+dp2[j-1]); } } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:15:19: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   15 |     int l1=v1.size(),l2=v2.size();
      |            ~~~~~~~^~
boxes.cpp:15:32: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   15 |     int l1=v1.size(),l2=v2.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...