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;
const int md = (int) 1e9;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int DistanceSum(int N, int *X, int *Y) {
int ret = 0;
int mxn = 0, mxm = 0;
int mnn = INT_MAX, mnm = INT_MAX;
for (int i = 0; i < N; ++i) {
mxn = max(mxn, X[i]);
mxm = max(mxm, Y[i]);
mnn = min(mnn, X[i]);
mnm = min(mnm, Y[i]);
}
auto sum = [&](int r) {
r %= md;
return (int) (((long long) r * (r + 1) / 2) % md);
};
auto mul = [&](int x, int y) {
x %= md;
y %= md;
return (int) ((long long) x * y % md);
};
auto add = [&](int& x, int y) {
x %= md; y %= md;
x += y;
if (x >= md) x -= md;
};
int lenn = mxn - mnn + 1;
int lenm = mxm - mnm + 1;
for (int i = 0; i < N; ++i) {
int x = X[i], y = Y[i];
int sx = mul(sum(x - mnn), lenm);
//add(sx, mul(sum(mxn - x), lenm));
int sy = mul(sum(y - mnm), lenn);
//add(sy, mul(sum(mxm - y), lenn));
add(ret, sx);
add(ret, sy);
}
return ret;
}
# | 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... |