#include<bits/stdc++.h>
using namespace std;
int vis[100001],x,y,t,help,d[1000001];
map<pair<int,int>,int> mp;
vector<int> adj[100000];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
pair<int,int> A[100000];
int DistanceSum(int N, int *X, int *Y) {
int sum = 0;
for (int i = 0; i < N; i++)
mp[{X[i],Y[i]}] = i + 1, A[i] = {X[i],Y[i]};
for (int i = 0; i < N;i ++) {
for (int j = 0; j < 4; j++) {
x = X[i] + dx[j];
y = Y[i] + dy[j];
t = mp[{x,y}];
if (t) adj[i].push_back(t-1);
}
} if ( N <= 5000) {
for (int i = 0; i < N; i++) {
help++;
queue<int> q;
q.push(i);
d[i] = 0;
vis[i] = help;
while (!q.empty()) {
x = q.front();
q.pop();
sum += d[x];
for (int j:adj[x]) {
if (vis[j] != help ) {
vis[j] = help;
d[j] = d[x] + 1;
q.push(j);
}
}
if (sum >= 1e9) sum -= 1e9;
} } return sum/2;}
sort (A, A + N);
int s = 0;
for (int i = 0; i < N; i ++) {
s += A[i].first;
if (s >= 1e9) s-= 1e9;
sum = (1ll*(i + 1)*A[i].first - s + sum)%(1000000000);
if (sum < 0) sum += 1e9;
swap(A[i].first,A[i].second);
}
sort (A , A+ N);
s = 0;
for (int i = 0; i < N; i ++) {
s += A[i].first;
if (s >= 1e9) s-= 1e9;
sum = (1ll*(i + 1)*A[i].first - s + sum)%(1000000000);
if (sum < 0) sum += 1e9;
swap(A[i].first,A[i].second);
}
return sum/2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
7 ms |
2688 KB |
Output is correct |
9 |
Correct |
7 ms |
2688 KB |
Output is correct |
10 |
Correct |
7 ms |
2688 KB |
Output is correct |
11 |
Correct |
7 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2944 KB |
Output is correct |
2 |
Correct |
33 ms |
2816 KB |
Output is correct |
3 |
Correct |
65 ms |
2944 KB |
Output is correct |
4 |
Correct |
66 ms |
2944 KB |
Output is correct |
5 |
Correct |
115 ms |
3072 KB |
Output is correct |
6 |
Correct |
110 ms |
3064 KB |
Output is correct |
7 |
Correct |
120 ms |
3072 KB |
Output is correct |
8 |
Correct |
108 ms |
2944 KB |
Output is correct |
9 |
Correct |
107 ms |
3012 KB |
Output is correct |
10 |
Correct |
102 ms |
2944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
6136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |