이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL LINF = 1e18;
LL a[100010];
vector<LL>vec[2];
LL n,k,L1;
LL solve1(){
vec[0].clear();
vec[1].clear();
for(int i=1;i<=n;i++){
if(a[i]<=L1/2)
vec[0].push_back(a[i]);
else
vec[1].push_back(a[i]);
}
reverse(vec[1].begin(),vec[1].end());
LL ans = 0;
while(vec[0].size()>=k){
ans += vec[0][vec[0].size()-k]*2;
for(int i=0;i<k;i++)
vec[0].pop_back();
}
while(vec[1].size()>=k){
ans += (L1-vec[1].back())*2;
for(int i=0;i<k;i++)
vec[1].pop_back();
}
for(int i=0;i<vec[1].size();i++)
vec[0].push_back(vec[1][i]);
sort(vec[0].begin(),vec[0].end());
LL ans1 = LINF;
if(vec[0].empty())
ans1 = 0;
for(int i=0;i<=min(k,(LL)vec[0].size());i++){
if(vec[0].size()-i>k)
continue;
ans1 = min(ans1,min(L1,i?vec[0][i-1]*2:0)+min(L1,i!=vec[0].size()?(L1-vec[0][i])*2:0));
}
return ans1+ans;
}
LL solve2(){
vec[0].clear();
vec[1].clear();
for(int i=1;i<=n;i++){
if(a[i]<=L1/2)
vec[0].push_back(a[i]);
else
vec[1].push_back(a[i]);
}
reverse(vec[0].begin(),vec[0].end());
LL ans = 0;
while(vec[0].size()>=k){
ans += vec[0][vec[0].size()-k]*2;
for(int i=0;i<k;i++)
vec[0].pop_back();
}
while(vec[1].size()>=k){
ans += (L1-vec[1][vec[1].size()-k])*2;
for(int i=0;i<k;i++)
vec[1].pop_back();
}
reverse(vec[0].begin(),vec[0].end());
for(int i=0;i<vec[1].size();i++)
vec[0].push_back(vec[1][i]);
LL ans1 = LINF;
if(vec[0].empty())
ans1 = 0;
for(int i=0;i<=min(k,(LL)vec[0].size());i++){
if(vec[0].size()-i>k)
continue;
ans1 = min(ans1,min(L1,i?vec[0][i-1]*2:0)+min(L1,i!=vec[0].size()?(L1-vec[0][i])*2:0));
}
return ans+ans1;
}
long long delivery(int N, int K, int L, int p[]) {
n = N,k = K;
L1 = L;
for(int i=1;i<=n;i++)
a[i] = p[i-1];
sort(a+1,a+n+1);
return solve2();//min(solve1(),solve2());
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'long long int solve1()':
boxes.cpp:26:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
26 | while(vec[0].size()>=k){
| ~~~~~~~~~~~~~^~~
boxes.cpp:32:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
32 | while(vec[1].size()>=k){
| ~~~~~~~~~~~~~^~~
boxes.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<vec[1].size();i++)
| ~^~~~~~~~~~~~~~
boxes.cpp:47:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
47 | if(vec[0].size()-i>k)
| ~~~~~~~~~~~~~~~^~
boxes.cpp:50:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | ans1 = min(ans1,min(L1,i?vec[0][i-1]*2:0)+min(L1,i!=vec[0].size()?(L1-vec[0][i])*2:0));
| ~^~~~~~~~~~~~~~~
boxes.cpp: In function 'long long int solve2()':
boxes.cpp:70:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
70 | while(vec[0].size()>=k){
| ~~~~~~~~~~~~~^~~
boxes.cpp:76:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
76 | while(vec[1].size()>=k){
| ~~~~~~~~~~~~~^~~
boxes.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i=0;i<vec[1].size();i++)
| ~^~~~~~~~~~~~~~
boxes.cpp:91:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
91 | if(vec[0].size()-i>k)
| ~~~~~~~~~~~~~~~^~
boxes.cpp:94:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | ans1 = min(ans1,min(L1,i?vec[0][i-1]*2:0)+min(L1,i!=vec[0].size()?(L1-vec[0][i])*2: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... |