This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll tot,eff,midder,VI;
int n;
/*struct A{ll X;ld imp;
void sc(int i){scanf("%lld",&X);imp=(i?(ld)X/i:0);tot+=X;}
bool operator<(const A&R)const{return imp==R.imp?X<R.X:imp<R.imp;}
};
vector<A>V;
*/
vector<ll>V;
inline ll mov(ll I,ll gap)
{
// return abs(V[I].X-I*gap);
return abs(V[I]-I*gap);
}
inline ll res(ll gap)
{
int i;
ll total=0;
for(i=0;i<n;i++)
total+=mov(i,gap);
return total;
}
ll finder(ll l,ll r)
{
ll leng=1ll<<62;
for(ll i=l;i<=r;i++)
{
leng=min(leng,res(i));
}
return leng;
}
int main()
{
scanf("%d",&n);eff=n;
V.resize(n);
int cnt=0;
for(auto&I:V)scanf("%lld",&I);
/* for(auto&I:V)I.sc(cnt++);
sort(V.begin(),V.end());
*/
ll l=1,m,m1,m2,m3,r=1ll<<32;
while(l+3<r)
{
m=l+r>>1;
m1=res(m-1);
m2=res(m);
m3=res(m+1);
if(m2<=m3)r=m;
if(m1>=m2)l=m;
//printf("%lld %lld %lld %lld :: %lld %lld \n",m,m1,m2,m3,l,r);
}
printf("%lld",finder(l,r));
}
Compilation message (stderr)
pole.cpp: In function 'int main()':
pole.cpp:49:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
m=l+r>>1;
~^~
pole.cpp:40:9: warning: unused variable 'cnt' [-Wunused-variable]
int cnt=0;
^~~
pole.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);eff=n;
~~~~~^~~~~~~~~
pole.cpp:42:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(auto&I:V)scanf("%lld",&I);
~~~~~^~~~~~~~~~~
# | 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... |