Submission #1005040

#TimeUsernameProblemLanguageResultExecution timeMemory
1005040GrayBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
0 ms348 KiB
#include "boxes.h" #include <cassert> #include <vector> #include <algorithm> #define ll long long #define ff first #define ss second #define ln "\n" using namespace std; vector<ll> pos; ll n, k, l; long long delivery(int N, int K, int L, int p[]) { n=N; k=K; l=L; pos.resize(n); vector<pair<ll, ll>> dist(n); for (ll i=0; i<n; i++){ pos[i] = p[i]; dist[i] = {min((ll)p[i], l-p[i]), i}; } sort(dist.begin(), dist.end()); vector<ll> lsi, rsi; ll li=2e18, ri=0; for (ll i=dist.size()-k; i<(ll)dist.size(); i++){ li=min(li, pos[dist[i].ss]); ri=max(ri, pos[dist[i].ss]); } for (ll i=0; i<(ll)dist.size(); i++){ if (pos[dist[i].ss]<=l/2){ lsi.push_back(dist[i].ss); }else{ rsi.push_back(dist[i].ss); } } for (ll i=1; i<lsi.size(); i++){ if (pos[lsi[i]]<pos[lsi[i-1]]) assert(false); } for (ll i=1; i<rsi.size(); i++){ if (pos[rsi[i]]>pos[rsi[i-1]]) assert(false); } ll ans=l; ll aans=0; for (ll i=lsi.size()-1; i>=0; i-=k){ aans+=pos[lsi[i]]*2; } for (ll i=rsi.size()-1; i>=0; i-=k){ aans+=(l-pos[rsi[i]])*2; } while (!lsi.empty() and pos[lsi.back()]>=li) {lsi.pop_back();} // cout << ln; while (!rsi.empty() and pos[rsi.back()]<=ri) {rsi.pop_back();} // cout << ln; // cout << li << " " << ri << ln; for (ll i=lsi.size()-1; i>=0; i-=k){ ans+=pos[lsi[i]]*2; } for (ll i=rsi.size()-1; i>=0; i-=k){ ans+=(l-pos[rsi[i]])*2; } // cout << aans << " " << ans << ln; return aans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:34:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (ll i=1; i<lsi.size(); i++){
      |                  ~^~~~~~~~~~~
boxes.cpp:37:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (ll i=1; i<rsi.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...