이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
ll n, k, l;
vector<int>teams;
ll distanciaABase(ll number){
return min(number, l-number);
}
bool isLeft(int number){
return number <= l/2;
}
ll dp[10000001][2];
ll calculateDp(){
ll acum = 0, restantes = k, ant = 0;
for(int i = 0 ;i < n ; i ++){
restantes--;
acum += (teams[i] - ant);
dp[i][0] = acum + distanciaABase(teams[i]);
ant = teams[i];
if(!restantes){
restantes = k;
ant = 0;
acum += distanciaABase(teams[i]);
}
//cout << i << " -> " << dp[i][0] << endl;
}
acum = 0, restantes = k, ant = l;
for(int i = n-1 ;i >= 0 ; i --){
restantes--;
acum += (ant - teams[i]);
dp[i][1] = acum + distanciaABase(teams[i]);
ant = teams[i];
if(!restantes){
restantes = k;
ant = l;
acum += distanciaABase(teams[i]);
}
//cout << i << " -> " << dp[i][1] << endl;
}
ll best = dp[0][1];
for(int i = 0 ;i < n-1 ; i ++){
best = min(best, dp[i][0] + dp[i+1][1]);
}
return min(best, dp[n-1][0]);
}
long long delivery(int N, int K, int L, int p[]) {
n = N, k = K, l = L;
for(int i = 0 ; i < n ; i ++){
teams.pb(p[i]);
}
return calculateDp();
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'long long int calculateDp()':
boxes.cpp:35:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
35 | for(int i = n-1 ;i >= 0 ; 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... |