# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
207719 |
2020-03-08T16:53:26 Z |
lagoon |
전봇대 (KOI13_pole) |
C++14 |
|
29 ms |
760 KB |
// boj 8986 전봇대
#include <iostream>
#include <algorithm>
using namespace std;
int position[100000], n;
long long dist(int x) {
long long ret = 0;
for (int i = 0; i < n; ++i) {
ret += abs(x * i - position[i]);
}
return ret;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> position[i];
}
long long left = 0;
long long right = 1e9;
while (right - left > 3) {
long long mid1 = left + (right - left) / 3;
long long mid2 = right - (right - left) / 3;
if (dist(mid1) < dist(mid2)) right = mid2;
else left = mid1;
}
long long ans = dist(right);
for (int i = left; i < right; ++i)
ans = min(ans, dist(i));
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Incorrect |
4 ms |
380 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |