Submission #619043

#TimeUsernameProblemLanguageResultExecution timeMemory
619043HazemBoxes with souvenirs (IOI15_boxes)C++14
20 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define LL long long using namespace std; const LL LINF = 1e18; LL a[100010]; vector<LL>vec[2]; long long delivery(int N, int K, int L, int p[]) { int n = N,k = K; LL L1 = L; for(int i=1;i<=n;i++) a[i] = p[i-1]; sort(a+1,a+n+1); for(int i=1;i<=n;i++){ if(a[i]<=L/2) vec[0].push_back(a[i]); else vec[1].push_back(a[i]); } reverse(vec[0].begin(),vec[0].end()); LL ans = 0; while(vec[0].size()>=k){ ans += vec[0][vec[0].size()-k]*2; for(int i=0;i<k;i++) vec[0].pop_back(); } while(vec[1].size()>=k){ ans += (L-vec[1][vec[1].size()-k])*2; for(int i=0;i<k;i++) vec[1].pop_back(); } reverse(vec[0].begin(),vec[0].end()); for(int i=0;i<vec[1].size();i++) vec[0].push_back(vec[1][i]); LL ans1 = LINF; if(vec[0].empty()) ans1 = 0; for(int i=0;i<=min(k,(int)vec[0].size());i++){ if(vec[0].size()-i>k) continue; ans1 = min(ans1,min(L1,i?vec[0][i-1]*2:0)+min(L1,i!=vec[0].size()?(L-vec[0][i])*2:0)); } return ans+ans1; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     while(vec[0].size()>=k){
      |           ~~~~~~~~~~~~~^~~
boxes.cpp:34:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |     while(vec[1].size()>=k){
      |           ~~~~~~~~~~~~~^~~
boxes.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<vec[1].size();i++)
      |                 ~^~~~~~~~~~~~~~
boxes.cpp:49:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         if(vec[0].size()-i>k)
      |            ~~~~~~~~~~~~~~~^~
boxes.cpp:52:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         ans1 = min(ans1,min(L1,i?vec[0][i-1]*2:0)+min(L1,i!=vec[0].size()?(L-vec[0][i])*2: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...