이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<ll> P;
vector<ll> Le,R,Ri;
ll n,k,l;
void debug(){
cout << "Le " ;
for(int i:Le) cout << i << " ";
cout << "\n";
cout << "Ri ";
for(int i:Ri) cout << i << " ";
cout << "\n";
}
void pre_L(){
Le.push_back(0);
for(ll i=0;i<k;i++) Le.push_back(2*P[i]);
for(ll i=k;i<n;i++){
Le.push_back(2*P[i]+Le[i+1-k]);
}
Le.push_back(0);
}
void pre_R(){
for(ll i=n-1;i>=n-k;i--) R.push_back(2*(l-P[i]));
for(ll i=n-k-1;i>=0;i--){
R.push_back(2*(l-P[i])+R[n-k-1-i]);
}
Ri.push_back(0);
for(ll i=n-1;i>=0;i--) Ri.push_back(R[i]);
Ri.push_back(0);
}
long long cal(int lb,int rb){
ll answer = ((rb-lb+1)/k)*l;
if((rb-lb+1)%k) answer += l;
answer += Le[lb-1];
answer += Ri[rb+1];
//cout << lb << " " << rb << " " << answer << "\n";
return answer;
}
long long delivery(int N, int K, int L, int p[]) {
for(int i=0;i<N;i++) P.push_back((ll)p[i]);
sort(P.begin(),P.end());
ll answer = 10000000000000000;
n=N;k=K;l=L;
pre_L();pre_R();
for(int i=1;i<=N+1;i++){
answer = min(answer,cal(i,i-1));
}
for(int i=1;i<=N+1;i++){
if(i+K-1==N) answer = min(answer,cal(i,i+K-1));
}
//debug();
return answer;
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'void debug()':
boxes.cpp:10:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
10 | for(int i:Le) cout << i << " ";
| ^~
boxes.cpp:13:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
13 | for(int i:Ri) cout << i << " ";
| ^~
# | 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... |