답안 #742196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742196 2023-05-15T18:26:51 Z Hacv16 이상적인 도시 (IOI12_city) C++17
32 / 100
124 ms 1108 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX = 2015;
const int MOD = 1000000000;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

vector<int> adj[MAX];

bool adjacent(int x1, int y1, int x2, int y2){
    for(int i = 0; i < 4; i++){
        int nx = x1 + dx[i], ny = y1 + dy[i];
        if(nx == x2 && ny == y2) return true;
    }

    return false;
}

int DistanceSum(int N, int X[], int Y[]) {
    int resp = 0;

    for(int i = 0; i < N; i++)
        for(int j = i + 1; j < N; j++)
            if(adjacent(X[i], Y[i], X[j], Y[j])){
                adj[i].emplace_back(j);
                adj[j].emplace_back(i);
            }

    for(int i = 0; i < N; i++){
        queue<int> q; vector<int> dist(N, -1);
        q.push(i); dist[i] = 0;

        while(q.size()){
            int u = q.front(); q.pop();

            for(auto v : adj[u]){
                if(dist[v] != -1) continue;
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }

        for(int j = 0; j < N; j++) resp += dist[j];
        resp %= MOD;
    }

    return resp >> 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 340 KB Output is correct
2 Correct 28 ms 340 KB Output is correct
3 Correct 58 ms 376 KB Output is correct
4 Correct 63 ms 408 KB Output is correct
5 Correct 102 ms 352 KB Output is correct
6 Correct 118 ms 440 KB Output is correct
7 Correct 108 ms 460 KB Output is correct
8 Correct 115 ms 444 KB Output is correct
9 Correct 124 ms 440 KB Output is correct
10 Correct 111 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 988 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -