Submission #771297

#TimeUsernameProblemLanguageResultExecution timeMemory
771297caganyanmazBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; long long delivery(int N, int K, int L, int positions[]) { vector<long long> lpos, rpos; int middle = 0; for (int i = 0; i < N; i++) if (positions[i] < (L / 2)) lpos.pb(positions[i]); else if (positions[i] > (L / 2)) rpos.pb(-positions[i]); else middle++; sort(lpos.begin(), lpos.end()); sort(rpos.begin(), rpos.end()); vector<int> ldp(lpos.size()+1), rdp(rpos.size()+1); for (int i = 1; i <= lpos.size(); i++) { if (i >= K) ldp[i] += ldp[i-K]; ldp[i] += static_cast<long long>(lpos[i-1]) * 2; } for (int i = 1; i <= rpos.size(); i++) { if (i >= K) rdp[i] += rdp[i-K]; rdp[i] += static_cast<long long>(L+rpos[i-1]) * 2; } long long result = ldp[lpos.size()] + rdp[rpos.size()] + (middle / K) * L; if (middle%K) result += L; for (int i = 1; i <= 4; i++) { long long remainder = K * i - (middle % K); for (int lremainder = 0; lremainder <= remainder; lremainder++) if (lpos.size() >= lremainder && rpos.size() >= remainder-lremainder) result = min(result, ldp[lpos.size()-lremainder] + rdp[rpos.size()-remainder+lremainder] + ((middle + remainder) / K) * L); } return result; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:20:27: 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 <= lpos.size(); i++)
      |                         ~~^~~~~~~~~~~~~~
boxes.cpp:24:63: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   24 |                 ldp[i] += static_cast<long long>(lpos[i-1]) * 2;
      |                                                               ^
boxes.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i = 1; i <= rpos.size(); i++)
      |                         ~~^~~~~~~~~~~~~~
boxes.cpp:30:65: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   30 |                 rdp[i] += static_cast<long long>(L+rpos[i-1]) * 2;
      |                                                                 ^
boxes.cpp:39:41: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |                         if (lpos.size() >= lremainder && rpos.size() >= remainder-lremainder)
      |                             ~~~~~~~~~~~~^~~~~~~~~~~~~
boxes.cpp:39:70: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   39 |                         if (lpos.size() >= lremainder && rpos.size() >= remainder-lremainder)
      |                                                          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...