답안 #562573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
562573 2022-05-14T16:33:10 Z AlexRex0 이상적인 도시 (IOI12_city) C++14
11 / 100
1000 ms 4432 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 5 ms 212 KB Output is correct
6 Correct 16 ms 308 KB Output is correct
7 Correct 15 ms 340 KB Output is correct
8 Correct 16 ms 352 KB Output is correct
9 Correct 17 ms 212 KB Output is correct
10 Correct 19 ms 340 KB Output is correct
11 Correct 20 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 584 ms 492 KB Output is correct
2 Correct 566 ms 588 KB Output is correct
3 Execution timed out 1095 ms 596 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 3224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 4432 KB Time limit exceeded
2 Halted 0 ms 0 KB -