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>
#define pii pair<int, int>
#define x first
#define y second
#define pb push_back
#define all(x) x.begin(), x.end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
const int MOD = 1000000000, N = 3000;
int delta[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool estVille[N][N], vue[N][N];
int dist[N][N];
int DistanceSum(int nVilles, int *X, int *Y) {
vector<int> x, y;
for (int iVille = 0; iVille < nVilles; ++iVille){
x.pb(X[iVille]);
y.pb(Y[iVille]);
}
int SUM = 0;
sort(all(x)); sort(all(y));
int sumPg = 0, sumPp = 0;
for (int e : x)
sumPg += e;
sumPg -= x[0];
for (int ind = 0; ind < nVilles; ++ind){
SUM = (SUM + (ind * x[ind] - sumPp + sumPg - (nVilles - 1 - ind) * x[ind]))%MOD;
if (ind != nVilles - 1)
sumPg -= x[ind + 1];
sumPp += x[ind];
}
// cout << "sum " << SUM << endl;
sumPg = 0, sumPp = 0;
for (int e :y)
sumPg += e;
sumPg -= y[0];
for (int ind = 0; ind < nVilles; ++ind){
SUM = (SUM + (ind * y[ind] - sumPp + sumPg - (nVilles - 1 - ind) * y[ind]))%MOD;
//cout << "d" << (ind * y[ind] - sumPp + sumPg - (nVilles - 1 - ind) * y[ind]) << endl;
if (ind != nVilles - 1)
sumPg -= y[ind + 1];
sumPp += y[ind];
}
return SUM/2;
}
# | 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... |