# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121848 | TuGSGeReL | Ideal city (IOI12_city) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
int DistanceSum(int n, int *x, int *y) {
int mnx = INT_MAX, mny = INT_MAX;
for (int i = 0; i < n; i++)
{
mnx = min(mnx, x[i]);
mny = min(mny, y[i]);
}
for (int i = 0; i < n; i++)
{
x[i] -= mnx;
y[i] -= mny;
}
if ( n <= 0 )
{
} else {
for (int i = 0; i < n; i++)
{
cx[x[i]]++;
cy[y[i]]++;
}
int sx = 0, ans = 0, sy = 0, ssx = 0, ssy = 0;
for (int i = n; i >= 0; i--)
{
ans = (ans + (ssx * cx[i] + cy[i] * ssy) % mod) % mod;
sy = (sy + cy[i]) % mod;
sx = (sx + cx[i]) % mod;
ssx = (ssx + sx) % mod;
ssy = (ssy + sy) % mod;
}
return ans;
}
}