이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct hash_pair{
size_t operator()(const pair<int,int> &x) const {
auto hash1 = hash<int>{}(x.first);
auto hash2 = hash<int>{}(x.second+12345);
return hash1^hash2;
}
};
unordered_map< pair<int,int>, int, hash_pair > mp, vis, dis;
queue< pair<int,int> > q;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int DistanceSum(int N, int *X, int *Y) {
for(int i=0; i<N; i++) {
mp[{X[i], Y[i]}] = 1;
}
long long ans = 0;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) vis[{X[j], Y[j]}] = 0;
vis[{X[i], Y[i]}] = 1;
q.push({X[i], Y[i]});
dis[{X[i], Y[i]}] = 0;
while(!q.empty()) {
int x = q.front().first;
int y = q.front().second;
ans += dis[{x, y}];
q.pop();
for(int j=0; j<4; j++) {
if(mp[{x+dx[j], y+dy[j]}] == 1 && vis[{x+dx[j], y+dy[j]}] == 0) {
vis[{x+dx[j], y+dy[j]}] = 1;
dis[{x+dx[j], y+dy[j]}] = dis[{x, y}] + 1;
q.push({x+dx[j], y+dy[j]});
}
}
}
}
return (ans/2) % 1000000000;
}
# | 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... |