이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000000
long long int ans = 0;
int color;
struct dato{
pair<int, int> pos;
long long int costo;
};
queue<dato> cola;
map<pair<int, int> , bool> mapa;
map<pair<int, int> , int> visitado;
int mov[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
void busca(){
while(!cola.empty()){
dato sig;
sig = cola.front();
cola.pop();
if(visitado[{sig.pos.first, sig.pos.second}] != color){
visitado[{sig.pos.first, sig.pos.second}] = color;
ans+= sig.costo;
ans%=MOD;
for(int i = 0; i < 4; ++i){
dato aux;
aux.pos.first = sig.pos.first + mov[i][0];
aux.pos.second = sig.pos.second + mov[i][1];
aux.costo = sig.costo + 1;
aux.costo%=MOD;
if(mapa[{aux.pos.first, aux.pos.second}]){
cola.push(aux);
}
}
}
}
}
int DistanceSum(int N, int *X, int *Y) {
for(int i = 0; i < N; ++i){
mapa[{X[i], Y[i]}] = true;
}
for(int i = 0; i < N; ++i){
color++;
dato aux;
aux.costo = 0;
aux.pos.first = X[i];
aux.pos.second = Y[i];
cola.push(aux);
busca();
}
ans/=2;
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... |