답안 #911319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
911319 2024-01-18T18:39:20 Z Macker 이상적인 도시 (IOI12_city) C++17
32 / 100
112 ms 1080 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()
#define dist(x) dist[x.first][x.second]

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

int DistanceSum(int N, int *X, int *Y) {
    vector<pii> v;
    int mxx = 0, mxy = 0;
    int mnx = INT_MAX, mny = INT_MAX;
    for (int i = 0; i < N; i++) {
        v.push_back({X[i], Y[i]});
        mxx = max(mxx, X[i]);
        mxy = max(mxy, Y[i]);
        mnx = min(mnx, X[i]);
        mny = min(mny, Y[i]);
    }
    mxx -= mnx - 1;
    mxy -= mny - 1;
    for (auto &i : v) {
        i.first -= mnx - 1;
        i.second -= mny - 1;
    }
    

    if(N < 5000){
        ll res = 0;
        vector<pii> off = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
        vector<vector<int>> dist;
        dist.assign(mxx + 2, vector<int>(mxy + 2, 0));
        for (auto &i : v)
        {    
            for (auto &j : v) {
                dist(j) = INT_MAX;
            }
            queue<pii> q;
            q.push(i);
            dist(i) = 0;
            while(q.size()){
                pii a = q.front(); q.pop();
                for (auto &[dx, dy] : off) {
                    pii b = {a.first + dx, a.second + dy};
                    if(dist(b) != 0 && dist(b) > dist(a) + 1){
                        dist(b) = dist(a) + 1;
                        q.push(b);
                    }
                }
            }
            for (auto &j : v) {
                res += dist(j);
            }
        }
        return res / 2;
    }
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:14:17: warning: control reaches end of non-void function [-Wreturn-type]
   14 |     vector<pii> v;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 348 KB Output is correct
2 Correct 20 ms 476 KB Output is correct
3 Correct 55 ms 344 KB Output is correct
4 Correct 50 ms 348 KB Output is correct
5 Correct 108 ms 512 KB Output is correct
6 Correct 79 ms 540 KB Output is correct
7 Correct 112 ms 348 KB Output is correct
8 Correct 78 ms 524 KB Output is correct
9 Correct 71 ms 496 KB Output is correct
10 Correct 69 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1080 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -