This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define pb push_back
#define ll long long
long long delivery(int N, int K, int L, int p[]) {
vector<int> a;
vector<int> b;
int k=K;
long long res=1e18;
for (int i = 0; i < N; ++i)
{
if(p[i]==0) continue;
a.pb(p[i]);
b.pb(L-p[i]);
}
reverse(b.begin(),b.end());
ll cur=0;
int cnt=0;
vector<ll> l(a.size()),r(a.size());
for (int i = 0; i < a.size(); ++i)
{
cnt++;
if(cnt==k){
cur+=a[i]*2;
cnt=0;
l[i]=cur;
}
else{
l[i]=a[i]*2+cur;
}
}
cnt=0;
cur=0;
for (int i = 0; i < b.size(); ++i)
{
cnt++;
if(cnt==k){
cur+=b[i]*2;
cnt=0;
r[i]=cur;
}
else{
r[i]=b[i]*2+cur;
}
}
res=L+(a.size()>k ? r[a.size()-k-1] : 1ll*0);
for (int i = 0; i < a.size(); ++i)
{
res=min(res,l[i]+(a.size()>=i+2 ? r[a.size()-i-2] : 0));
res=min(res,l[i]-a[i]+L+(a.size()>i+k ? r[a.size()-k-i-1] : 1ll*0));
}
return res;
}
/*
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int N, K, L, i;
cin>>N>>K>>L;
int *p = (int*)malloc(sizeof(int) * (unsigned int)N);
for (i = 0; i < N; i++) {
cin>>p[i];
}
cout << delivery(N, K, L, p)<<endl;
return 0;
}*/
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < a.size(); ++i)
| ~~^~~~~~~~~~
boxes.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < b.size(); ++i)
| ~~^~~~~~~~~~
boxes.cpp:47:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | res=L+(a.size()>k ? r[a.size()-k-1] : 1ll*0);
| ~~~~~~~~^~
boxes.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < a.size(); ++i)
| ~~^~~~~~~~~~
boxes.cpp:50:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | res=min(res,l[i]+(a.size()>=i+2 ? r[a.size()-i-2] : 0));
| ~~~~~~~~^~~~~
boxes.cpp:51:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | res=min(res,l[i]-a[i]+L+(a.size()>i+k ? r[a.size()-k-i-1] : 1ll*0));
| ~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |