답안 #562581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
562581 2022-05-14T16:49:26 Z Leo121 이상적인 도시 (IOI12_city) C++14
32 / 100
1000 ms 5064 KB
#include <bits/stdc++.h>
#define forn(i, a, b) for(int i = int (a); i <= int(b); ++ i)
#define fora(i, a, b) for(int i = int (a); i >= int(b); -- i)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
int mx[4] = {0, 0, 1, -1};
int my[4] = {1, -1, 0, 0};
map<pii, int> mapa;
queue<int> q;

const int maxn = 1e5;
int distancia[maxn];
vi graph[maxn];
int mod = 1e9;
int res = 0;
void bfs(int ind){
    int u;
    while(!q.empty()){
        u = q.front();
        q.pop();
        for(auto v : graph[u]){
            if(distancia[v] == -1){
                distancia[v] = distancia[u] + 1;
                if(v > ind){
                    res += distancia[v];
                    res %= mod;
                }
                q.push(v);
            }
        }
    }
}

int DistanceSum(int N, int *X, int *Y) {
    forn(i, 0, N - 1){
        mapa[mp(X[i], Y[i])] = i;
    }
    forn(i, 0, N - 1){
        forn(j, 0, 3){
            if(mapa.count(mp(X[i] + mx[j], Y[i] + my[j]))){
                graph[i].pb(mapa[mp(X[i] + mx[j], Y[i] + my[j])]);
            }
        }
    }
    forn(i, 0, N - 1){
        memset(distancia, -1, sizeof(distancia));
        distancia[i] = 0;
        q.push(i);
        bfs(i);
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 4 ms 3028 KB Output is correct
5 Correct 3 ms 3028 KB Output is correct
6 Correct 4 ms 3028 KB Output is correct
7 Correct 4 ms 3028 KB Output is correct
8 Correct 5 ms 3028 KB Output is correct
9 Correct 4 ms 3028 KB Output is correct
10 Correct 5 ms 3064 KB Output is correct
11 Correct 5 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 3156 KB Output is correct
2 Correct 39 ms 3132 KB Output is correct
3 Correct 75 ms 3196 KB Output is correct
4 Correct 76 ms 3196 KB Output is correct
5 Correct 129 ms 3156 KB Output is correct
6 Correct 118 ms 3156 KB Output is correct
7 Correct 128 ms 3256 KB Output is correct
8 Correct 126 ms 3156 KB Output is correct
9 Correct 117 ms 3256 KB Output is correct
10 Correct 115 ms 3268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 5028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 5064 KB Time limit exceeded
2 Halted 0 ms 0 KB -