Submission #1012829

#TimeUsernameProblemLanguageResultExecution timeMemory
1012829LuvidiBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
670 ms293960 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 i=0;i<=l1;i++){ ll x=(l1-i)/k; dp1[i]+=l*x; } for(ll i=0;i<=l2;i++){ ll x=(l2-i)/k; dp2[i]+=l*x; } for(ll i=l1;i&&i>l1-k+1;i--){ ll j=-i+l2-k+2+l1; if(j<1)continue; ll x1=1e18,x2=1e18; for(ll z=i;z>0;z-=k)x1=min(x1,dp1[z-1]); for(ll z=j;z>0;z-=k)x2=min(x2,dp2[z-1]); ans=min(ans,x1+x2+l); } 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...