제출 #619121

#제출 시각아이디문제언어결과실행 시간메모리
619121Hazem선물상자 (IOI15_boxes)C++14
50 / 100
69 ms22024 KiB
#include <bits/stdc++.h> #define LL long long using namespace std; const LL LINF = 1e18; LL a[10000010]; 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].back()*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]); LL ans1 = LINF; if(vec[0].empty()) ans1 = 0; sort(vec[0].begin(),vec[0].end()); 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 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...