이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
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;
}
return ans;
}
# | 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... |