이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
long long delivery(int N, int K, int L, int p[]) {
vector<int> vec;
for(int i = 0; i < N; i++) if(p[i] > 0) vec.push_back(p[i]);
int n = vec.size();
if(n == 0) return 0;
int k = K;
int trips = n / k;
//if(n % k != 0) trips++;
auto calc = [&](int l, int r){
if(l > r) return 0;
return min(min(vec[r] * 2, (L - vec[l]) * 2), L);
};
return calc(0, n - 1);
/*vector<ll> pre(trips + 1);
for(int i = 0; i < trips; i++){
if(i == 0) pre[i] = calc(0, k - 1);
else pre[i] = pre[i - 1] + calc(i * k, i * k + k - 1);
}
ll suf = 0;
int lnow = trips * k, rnow = n - 1, prenow = trips - 1;
ll ans = 1e18;
while(prenow >= 0){
ans = min(ans, suf + pre[prenow] + calc(lnow, rnow));
prenow--;
lnow -= k;
rnow -= k;
suf += calc(rnow + 1, rnow + k);
}
ans = min(ans, suf + calc(lnow, rnow));*/
//return ans;
}
// g++ -std=c++17 -o run -Wshadow -Wall -Wextra -fsanitize=undefined -fsanitize=address boxes.cpp grader.cpp
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:11:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
11 | int n = vec.size();
| ~~~~~~~~^~
boxes.cpp:14:9: warning: unused variable 'trips' [-Wunused-variable]
14 | int trips = n / k;
| ^~~~~
# | 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... |