#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
int mod=1e9;
long long ANS;
set<pair<int,int>>S;
queue<array<int,3>>q;
void flod(){
while(q.size()) {
auto[x,y,d]=q.front();
q.pop();
if(!S.count({x,y}))continue;
S.erase({x,y});ANS+=d;
q.push({x-1,y,d+1});
q.push({x+1,y,d+1});
q.push({x,y-1,d+1});
q.push({x,y+1,d+1});
}
}
int DistanceSum(int N, int *X, int *Y) {
if(N>2000){
sort(X,X+N);
sort(Y,Y+N);
long long ans=0;
for(long long i=0;i<N;i++){
ans+=i*X[i] - (N-i-1) *X[i];
ans%=mod;
}
for(long long i=0;i<N;i++){
ans+=i*Y[i] - (N-i-1) *Y[i];
ans%=mod;
}
return (ans+mod)%mod;
}
int A=*min_element(Y,Y+N);
int B=*min_element(X,X+N);
for(int i=0;i<N;i++)
S.insert({X[i]-=B,Y[i]-=A});
set<pair<int,int>>st2=S;
for(int i=0;i<N;i++){
q.push({X[i],Y[i],0});
flod();
S=st2;
}
return ANS/2%mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
452 KB |
Output is correct |
6 |
Correct |
7 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
348 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
8 ms |
348 KB |
Output is correct |
11 |
Correct |
8 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
524 KB |
Output is correct |
2 |
Correct |
235 ms |
348 KB |
Output is correct |
3 |
Correct |
593 ms |
576 KB |
Output is correct |
4 |
Correct |
578 ms |
576 KB |
Output is correct |
5 |
Execution timed out |
1060 ms |
604 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
9 ms |
860 KB |
Output is correct |
4 |
Correct |
9 ms |
860 KB |
Output is correct |
5 |
Correct |
18 ms |
1292 KB |
Output is correct |
6 |
Correct |
17 ms |
1112 KB |
Output is correct |
7 |
Correct |
19 ms |
1216 KB |
Output is correct |
8 |
Correct |
18 ms |
1216 KB |
Output is correct |
9 |
Correct |
18 ms |
1112 KB |
Output is correct |
10 |
Correct |
17 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |