# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
23670 | leejseo | 전봇대 (KOI13_pole) | C++14 | 39 ms | 2292 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <algorithm>
#define abs(a) ((a)>0?(a):-(a))
#define min(a, b) ((a)<(b)?(a):(b))
int N;
int X[100000];
long long D, Ans;
struct bot{
int x, id;
} Bot[100000];
bool cmp(bot a, bot b){
return (long long)a.x * (long long)b.id < (long long)b.x * (long long)a.id;
}
long long cost(long long d){
int i;
long long sum = 0;
for (i=1; i<N; i++){
sum += abs(i*d - X[i]);
}
return sum;
}
int main(void){
int i;
long long sum, t;
scanf("%d", &N);
for (i=0; i<N; i++) scanf("%d", &X[i]);
for (i=1; i<N; i++){
Bot[i].x = X[i];
Bot[i].id = i;
}
std::sort(Bot+1, Bot+N, cmp);
sum = N; sum = sum*(sum-1)/2;
t = 0;
for (i=1; i<N; i++){
if (t+1 <= (sum+1)/2 && (sum+1)/2 <= t+Bot[i].id) break;
t += Bot[i].id;
}
D = Bot[i].x / Bot[i].id;
printf("%lld\n", min(cost(D), cost(D+1)));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |