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;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<int,int> pii;
const ll MAX=1e6;
const ll mod=1e9;
ll res1,res2,sum[MAX];
int DistanceSum(int N, int *X, int *Y)
{
res1=0;
res2=0;
ll f=X[0],s=Y[0],f_=X[0],s_=Y[0];
for(int A=1;A<N;A++)
{
f=max(f,(ll)X[A]);
s=max(s,(ll)Y[A]);
f_=min(f_,(ll)X[A]);
s_=min(s_,(ll)Y[A]);
}
f=f-f_+1;
s=s-s_+1;
for(ll A=1;A<MAX;A++)
sum[A]=(sum[A-1]+A)%mod;
for(ll A=1;A<=f;A++)
{
res1+=((s*s)%mod*(sum[A-1]))%mod;
res1%=mod;
}
for(ll A=1;A<=s;A++)
{
res2+=((f*f)%mod*sum[A-1])%mod;
res2%=mod;
}
return (res1+res2)%mod;
}
/*signed main()
{
ios_base::sync_with_stdio(false);
int X[]={1,1,2,2};
int Y[]={1,2,1,2};
cout<<DistanceSum(4,X,Y);
return 0;
}*/
# | 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... |