Submission #923669

#TimeUsernameProblemLanguageResultExecution timeMemory
923669AiperiiiBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
1036 ms349832 KiB
#include <bits/stdc++.h> #include "boxes.h" #define ll long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; long long delivery(int N, int K, int L, int p[]) { vector <ll> a,b,dpa,dpb; for(int i=0;i<N;i++){ if(p[i]<=L-p[i])a.pb(p[i]); else b.pb(L-p[i]); } a.pb(0);b.pb(0); dpa.pb(0);dpb.pb(0); sort(all(a));sort(all(b)); for(int i=1;i<a.size();i++){ if(i>=K)dpa.pb(dpa[i-K]+2*a[i]); else dpa.pb(2*a[i]); } for(int i=1;i<b.size();i++){ if(i>=K)dpb.pb(dpb[i-K]+2*b[i]); else dpb.pb(2*b[i]); } ll ans=dpa.back()+dpb.back(); for(int i=0;i<a.size();i++){ if((int)a.size()-i-1<=K){ int x=K-((int)a.size()-i-1); int pos=(int)b.size()-1-x; if(pos<0)pos=0; ans=min(ans,dpa[i]+dpb[pos]+L); } } return ans; } /* signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,k,l; cin>>n>>k>>l; int pos[n]; for(int i=0;i<n;i++)cin>>pos[i]; cout<<delivery(n,k,l,pos); } */

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |    for(int i=1;i<a.size();i++){
      |                ~^~~~~~~~~
boxes.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |    for(int i=1;i<b.size();i++){
      |                ~^~~~~~~~~
boxes.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |    for(int i=0;i<a.size();i++){
      |                ~^~~~~~~~~
#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...