#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int maxn = 1e5+10;
const long long mod = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
int n;
ll soma[maxn];
pii pt[maxn];
bool comp(pii a, pii b) {return a.y < b.y;}
int DistanceSum(int N, int *X, int *Y)
{
n = N;
for (int i = 0; i < n; i++)
pt[i+1] = {X[i], Y[i]};
sort(pt+1, pt+n+1);
for (int i = 1; i <= n; i++)
soma[i] = (soma[i-1]+(ll)pt[i].x)%mod;
ll ans = 0LL;
for (int i = 1; i <= n; i++)
{
ll v = (soma[n]-soma[i]+mod)%mod;
ans = (ans+v)%mod;
ans = (ans-((n-i)*(ll)pt[i].x)%mod+mod)%mod;
v = soma[i-1];
ans = (ans-v+mod)%mod;
ans = (ans+((i-1)*(ll)pt[i].x)%mod)%mod;
}
sort(pt+1, pt+n+1, comp);
for (int i = 1; i <= n; i++)
soma[i] = (soma[i-1]+(ll)pt[i].y)%mod;
for (int i = 1; i <= n; i++)
{
ll v = (soma[n]-soma[i]+mod)%mod;
ans = (ans+v)%mod;
ans = (ans-(((ll)n-(ll)i)*(ll)pt[i].y)%mod+mod)%mod;
v = soma[i-1];
ans = (ans-v+mod)%mod;
ans = (ans+(((ll)i-1LL)*(ll)pt[i].y)%mod)%mod;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |