답안 #65105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65105 2018-08-06T15:59:11 Z aquablitz11 이상적인 도시 (IOI12_city) C++14
11 / 100
1000 ms 4260 KB
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

const int N = 2e3+10;
const int INF = INT_MAX;

int mxx = 0, mxy = 0;
map<pii, int> idx;
int dist[N];
bool vis[N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int DistanceSum(int n, int *X, int *Y)
{
    int mnx = INF, mny = INF;
    for (int i = 0; i < n; ++i) {
        mnx = min(mnx, X[i]);
        mny = min(mny, Y[i]);
    }
    for (int i = 0; i < n; ++i) {
        X[i] -= mnx;
        Y[i] -= mny;
        mxx = max(mxx, X[i]);
        mxy = max(mxy, Y[i]);
        idx[pii(X[i], Y[i])] = i;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j)
            vis[j] = dist[j] = 0;
        queue<int> nxt;
        nxt.push(i);
        while (!nxt.empty()) {
            int j = nxt.front();
            int x = X[j];
            int y = Y[j];
            nxt.pop();
            if (j > i) {
                ans += dist[j];
                ans %= (int)1e9;
            }
            for (int k = 0; k < 4; ++k) {
                int nx = x+dx[k];
                int ny = y+dy[k];
                if (!idx.count(pii(nx, ny)))
                    continue;
                int nj = idx[pii(nx, ny)];
                if (!vis[nj]) {
                    vis[nj] = true;
                    dist[nj] = dist[j]+1;
                    nxt.push(nj);
                }
            }
        }
    }
    return ans;

}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:33:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
             vis[j] = dist[j] = 0;
                      ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 572 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 660 KB Output is correct
6 Correct 16 ms 696 KB Output is correct
7 Correct 25 ms 700 KB Output is correct
8 Correct 17 ms 752 KB Output is correct
9 Correct 21 ms 764 KB Output is correct
10 Correct 20 ms 768 KB Output is correct
11 Correct 24 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 584 ms 964 KB Output is correct
2 Correct 536 ms 968 KB Output is correct
3 Execution timed out 1078 ms 968 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 4096 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 4260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -