제출 #595472

#제출 시각아이디문제언어결과실행 시간메모리
595472Apiram선물상자 (IOI15_boxes)C++14
컴파일 에러
0 ms0 KiB
//#include "boxes.h" #include<bits/stdc++.h> using namespace std; long long delivery(int N, int K, int L, int p[]) { if (K == 1){ long long ans = 0; for (int i = 0;i<N;++i){ ans +=min(p[i],L - p[i]) * 2; } return ans; } else if (K == N){ long long ans = min({L,(L - p[0]) * 2,p[N - 1] * 2}); for (int i = 0;i<N - 1;++i){ ans = min(ans,(long long)p[i] * 2 + (L - p[i + 1]) * 2); } return ans; } else{ long long ans = 0; vector<int>have(N); for (int i = 0;i<N;++i){ ans+=min(p[i],L - p[i]) * 2; have[i] = K - 1; } for (int i = 1;i<N;++i){ if (have[i - 1] > 0 && min((p[i] - p[i - 1]) * 2,p[i] - p[i - 1] + L - p[i] - p[i - 1]) < min(p[i],L - p[i]) * 2){ ans-=min(p[i],L - p[i]) * 2; ans+=min((p[i] - p[i - 1]) * 2,p[i] - p[i - 1] + L - p[i] - p[i - 1]); have[i] = have[i - 1] - 1; have[i - 1] = 0; } } for (int i = N - 2;i>=0;--i){ if (have[i + 1] > 0 && have[i] == K - 1 && min((p[i + 1] - p[i]) * 2,p[i + 1] - p[i] + p[i] - (L - p[i + 1])) < min(p[i],L - p[i])*2){ ans-=min(p[i],L - p[i])*2; ans+=min((p[i + 1] - p[i]) * 2,p[i + 1] - p[i] + p[i] - (L - p[i + 1])); have[i] = have[i + 1] - 1; have[i] = 0; } } return ans; //first compute the total distance we have to travel to satisfy the teams } return 0; } int main() { 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)<<'\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccRqMl02.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cchREcr3.o:boxes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status