이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
}
if(a.size()==0) return 0;
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));
}
res=min(res,r[a.size()-1]);
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;
}*/
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < a.size(); ++i)
| ~~^~~~~~~~~~
boxes.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 0; i < b.size(); ++i)
| ~~^~~~~~~~~~
boxes.cpp:48:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
48 | res=L+(a.size()>k ? r[a.size()-k-1] : 1ll*0);
| ~~~~~~~~^~
boxes.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 0; i < a.size(); ++i)
| ~~^~~~~~~~~~
boxes.cpp:51:35: 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.size()>=i+2 ? r[a.size()-i-2] : 0));
| ~~~~~~~~^~~~~
boxes.cpp:52:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | 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... |