Submission #879727

#TimeUsernameProblemLanguageResultExecution timeMemory
879727NeroZeinIdeal city (IOI12_city)C++17
0 / 100
5 ms604 KiB
#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 n = 0, m = 0; for (int i = 0; i < N; ++i) { n = max(n, X[i]); m = max(m, Y[i]); } auto sum = [&](int r) { return (int) (((long long) r * (r + 1) / 2) % md); }; auto mul = [&](int x, int y) { return (int) ((long long) x * y % md); }; auto add = [&](int& x, int y) { x += y; if (x >= md) x -= md; }; for (int i = 0; i < N; ++i) { int x = X[i], y = Y[i]; int sx = mul(sum(x - 1), m); add(sx, mul(sum(n - x), m)); int sy = mul(sum(y - 1), n); add(sy, mul(sum(m - y), n)); add(ret, sx); add(ret, sy); } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...