답안 #288007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288007 2020-09-01T07:49:21 Z ToMmyDong 이상적인 도시 (IOI12_city) C++11
32 / 100
1000 ms 3576 KB
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
    for (IT it=bg;it!=ed;it++) {
        if (it == bg) os << "{" << *it;
        else os << "," << *it;
    }
    return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
    return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
    return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif


const int MAXN = 20003;
map<pii, int> id;
vector<int> edge[MAXN];
int DistanceSum(int n, int *x, int *y) {
    for (int i=0; i<n; i++) {
        id[pii(x[i], y[i])] = i;
    }

    for (int i=0; i<n; i++) {
        vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
        for (int j=0; j<4; j++) {
            int nx = x[i] + dx[j];
            int ny = y[i] + dy[j];
            if (id.count(pii(nx, ny))) {
                int z = id[pii(nx,ny)];
                edge[i].emplace_back(z);
                edge[z].emplace_back(i);
            }
        }
    }

    int ans = 0;
    for (int i=0; i<n; i++) {
        vector<int> dis(n, -1);
        dis[i] = 0;
        queue<int> bfs;
        bfs.emplace(i);
        while (bfs.size()) {
            int cur = bfs.front();
            bfs.pop();
            for (int z : edge[cur]) {
                if (dis[z] == -1) {
                    dis[z] = dis[cur] + 1;
                    bfs.emplace(z);
                    ans += dis[z];
                }
            }
        }
    }

    return ans / 2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 848 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 972 KB Output is correct
2 Correct 43 ms 896 KB Output is correct
3 Correct 78 ms 1024 KB Output is correct
4 Correct 80 ms 1056 KB Output is correct
5 Correct 136 ms 1144 KB Output is correct
6 Correct 157 ms 1024 KB Output is correct
7 Correct 136 ms 1024 KB Output is correct
8 Correct 157 ms 1024 KB Output is correct
9 Correct 147 ms 1136 KB Output is correct
10 Correct 146 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 3576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 3320 KB Time limit exceeded
2 Halted 0 ms 0 KB -