#include<bits/stdc++.h>
using namespace std;
int mod=1e9;
long long ANS;
set<pair<int,int>>st;
queue<tuple<int,int,int>>q;
void flod(){
if(q.empty())return;
auto[x,y,d]=q.front();
q.pop();
if(!st.count({x,y}))return flod();
st.erase({x,y});
ANS+=d;
q.emplace(x-1,y,d+1);
q.emplace(x+1,y,d+1);
q.emplace(x,y-1,d+1);
q.emplace(x,y+1,d+1);
flod();
}
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++)
st.insert({X[i]-=B,Y[i]-=A});
set<pair<int,int>>st2=st;
for(int i=0;i<N;i++){
q.emplace(X[i],Y[i],0);
flod();
st=st2;
}
return ANS/2%mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
532 KB |
Output is correct |
7 |
Correct |
8 ms |
344 KB |
Output is correct |
8 |
Correct |
10 ms |
348 KB |
Output is correct |
9 |
Correct |
8 ms |
348 KB |
Output is correct |
10 |
Correct |
9 ms |
348 KB |
Output is correct |
11 |
Correct |
12 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
275 ms |
916 KB |
Output is correct |
2 |
Correct |
261 ms |
856 KB |
Output is correct |
3 |
Correct |
706 ms |
1112 KB |
Output is correct |
4 |
Correct |
609 ms |
1144 KB |
Output is correct |
5 |
Execution timed out |
1028 ms |
1368 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
600 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
11 ms |
1112 KB |
Output is correct |
4 |
Correct |
9 ms |
1116 KB |
Output is correct |
5 |
Correct |
17 ms |
1852 KB |
Output is correct |
6 |
Correct |
18 ms |
1884 KB |
Output is correct |
7 |
Correct |
19 ms |
2080 KB |
Output is correct |
8 |
Correct |
18 ms |
1884 KB |
Output is correct |
9 |
Correct |
18 ms |
1856 KB |
Output is correct |
10 |
Correct |
18 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |