#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
static long long sum1[10000010];
static long long sum2[10000010];
static long long gonext[10000010];
long long delivery(int N, int K, int L, int p[]) {
long long i;
long long ans=1000000000000000000ll;
for(i=0;i<N;i++)
{
gonext[i]=i;
sum1[i]=p[i]*2;
if(i>=K)
sum1[i]+=sum1[i-K];
}
for(i=N-1;i>=0;i--)
{
sum2[i]=(L-p[i])*2;
if(i+K<=N-1)
sum2[i]+=sum2[i+K];
}
for(i=0;i<N;i++)
{
if(p[i]>L/2) break;
}
int las=i-1;
for(i=0;i<=las;i++)
{
gonext[las-i]=las+((K-i)%K+K)%K;
}
/*for(i=0;i<N;i++)
printf("%lld ",gonext[i]);
puts("");*/
long long temp=L*gonext[0];
if(gonext[0]<N)
temp+=sum2[gonext[0]];
ans=min(ans,temp);
i=-1;
//printf("%lld %lld %lld %lld %lld\n",i,0,L*(gonext[i+1]-(i+1)),gonext[i+1]<N?sum2[gonext[i+1]]:-1,temp);
for(i=0;i<N&&p[i]<=L/2;i++)
{
long long temp=sum1[i]+L*(gonext[i+1]-(i+1));
if(gonext[i+1]<N)
temp+=sum2[gonext[i+1]];
//printf("%lld %lld %lld %lld %lld\n",i,sum1[i],L*(gonext[i+1]-(i+1)),gonext[i+1]<N?sum2[gonext[i+1]]:-1,temp);
ans=min(ans,temp);
}
return ans;
}
/*
#include "boxes.h"
#include <stdio.h>
#include <stdlib.h>
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
static inline int _read() {
if (_charsNumber < 0) {
exit(1);
}
if (!_charsNumber || _currentChar == _charsNumber) {
_charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
_currentChar = 0;
}
if (_charsNumber <= 0) {
return -1;
}
return _buffer[_currentChar++];
}
static inline int _readInt() {
int c, x, s;
c = _read();
while (c <= 32) c = _read();
x = 0;
s = 1;
if (c == '-') {
s = -1;
c = _read();
}
while (c > 32) {
x *= 10;
x += c - '0';
c = _read();
}
if (s < 0) x = -x;
return x;
}
int main() {
_inputFile = fopen("boxes.in", "rb");
_outputFile = fopen("boxes.out", "w");
int N, K, L, i;
N = _readInt();
K = _readInt();
L = _readInt();
int *p = (int*)malloc(sizeof(int) * (unsigned int)N);
for (i = 0; i < N; i++) {
p[i] = _readInt();
}
fprintf(_outputFile, "%lld\n", delivery(N, K, L, p));
return 0;
}*/
Compilation message
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:29:11: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
int las=i-1;
~^~
boxes.cpp:46:13: warning: declaration of 'temp' shadows a previous local [-Wshadow]
long long temp=sum1[i]+L*(gonext[i+1]-(i+1));
^~~~
boxes.cpp:37:12: note: shadowed declaration is here
long long temp=L*gonext[0];
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |