Submission #14676

# Submission time Handle Problem Language Result Execution time Memory
14676 2015-06-03T01:35:50 Z Fakeable 전봇대 (KOI13_pole) C++
Compilation error
0 ms 0 KB
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,t;
vector<int> v;
inline ll abs(ll x) {
    return x>0?x:-x;
}
ll calc(ll p) {
    ll ret = 0;
    for(int i=1;i<n;i++) ret += abs(v[i]-i*p);
    return ret;
}
int search(int front,int rear) {
    if(front == rear) return front;
    int mid = (front + rear) / 2;
    ll first = calc(mid);
    ll second = calc(mid+1);
    if(first < second) return search(front, mid);
    return search(mid+1, rear);
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d",&t);
        v.push_back(t);
    }
    int M = 0;
    for(int i=1;i<n;i++) M = max(M, v[i]/i+1);
    int dydx = search(1,M);
    ll ans = 0;
    for(int i=1;i<n;i++) ans += abs(v[i]-i*dydx);
    printf("%lld\n",ans);
    return 0;
}

Compilation message

pole.cpp: In function ‘ll calc(ll)’:
pole.cpp:13:45: error: call of overloaded ‘abs(ll)’ is ambiguous
     for(int i=1;i<n;i++) ret += abs(v[i]-i*p);
                                             ^
pole.cpp:13:45: note: candidates are:
In file included from /usr/include/c++/4.9/cstdlib:72:0,
                 from /usr/include/c++/4.9/bits/stl_algo.h:59,
                 from /usr/include/c++/4.9/algorithm:62,
                 from pole.cpp:3:
/usr/include/stdlib.h:775:12: note: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
pole.cpp:8:11: note: ll abs(ll)
 inline ll abs(ll x) {
           ^
In file included from /usr/include/c++/4.9/bits/stl_algo.h:59:0,
                 from /usr/include/c++/4.9/algorithm:62,
                 from pole.cpp:3:
/usr/include/c++/4.9/cstdlib:179:3: note: __int128 std::abs(__int128)
   abs(__int128 __x) { return __x >= 0 ? __x : -__x; }
   ^
/usr/include/c++/4.9/cstdlib:174:3: note: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
/usr/include/c++/4.9/cstdlib:166:3: note: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
pole.cpp: In function ‘int main()’:
pole.cpp:25:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
pole.cpp:27:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
                       ^