# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
944562 |
2024-03-13T00:16:33 Z |
rainboy |
전봇대 (KOI13_pole) |
C |
|
12 ms |
2392 KB |
#include <stdio.h>
#define N 100000
long long abs_(long long a) { return a > 0 ? a : -a; }
long long min(long long a, long long b) { return a < b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int tt[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (tt[ii[j]] == tt[i_])
j++;
else if (tt[ii[j]] < tt[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int xx[N], ii[N];
int n, i, t;
long long a, ans1, ans2;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &xx[i]);
for (i = 1; i < n; i++)
xx[i] -= xx[0];
for (i = 1; i < n; i++)
tt[i] = xx[i] / i;
for (i = 1; i < n; i++)
ii[i] = i;
sort(ii, 1, n);
a = (long long) n * (n - 1) / 2, t = 0;
for (i = 1; i < n; i++)
if ((a -= tt[ii[i]] * 2) < 0) {
t = tt[ii[i]];
break;
}
ans1 = 0;
for (i = 1; i < n; i++)
ans1 += abs_(xx[i] - (long long) t * i);
ans2 = 0;
for (i = 1; i < n; i++)
ans2 += abs_(xx[i] - (long long) (t + 1) * i);
printf("%lld\n", min(ans1, ans2));
return 0;
}
Compilation message
pole.c: In function 'main':
pole.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
pole.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &xx[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |