이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <map>
#include <utility>
#include <queue>
using namespace std;
vector < int > Next[100005];
int con[100005];
map < pair < int , int > , int > where;
int MOD=1000000000;
queue < pair < int , int > > BFS;
int DistanceSum(int N, int *X, int *Y)
{
int ans=0,x,y,i,j;
for(i=0;i<N;i++) where[make_pair(X[i],Y[i])]=i;
for(i=0;i<N;i++)
{
if(where.find(make_pair(X[i]+1,Y[i]))!=where.end()) Next[i].push_back(where[make_pair(X[i]+1,Y[i])]);
if(where.find(make_pair(X[i]-1,Y[i]))!=where.end()) Next[i].push_back(where[make_pair(X[i]-1,Y[i])]);
if(where.find(make_pair(X[i],Y[i]+1))!=where.end()) Next[i].push_back(where[make_pair(X[i],Y[i]+1)]);
if(where.find(make_pair(X[i],Y[i]-1))!=where.end()) Next[i].push_back(where[make_pair(X[i],Y[i]-1)]);
}
for(i=0;i<N;i++)
{
for(j=0;j<N;j++) con[j]=-1;
BFS.push(make_pair(i,0));
while(!BFS.empty())
{
x=BFS.front().first;
y=BFS.front().second;
BFS.pop();
if(con[x]!=-1) continue;
con[x]=y;
if(i<x)
{
ans+=y;
if(ans>MOD) ans-=MOD;
}
for(auto k:Next[x]) BFS.push(make_pair(k,y+1));
}
}
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... |