답안 #1005898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005898 2024-06-23T07:39:10 Z 정민찬(#10832) 이상적인 도시 (IOI12_city) C++14
11 / 100
1000 ms 2908 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll mod = 1e9;

set<pair<int,int>> s;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

ll getDist(pair<int,int> st) {
    map<pair<int,int>, ll> d;
    d[st] = 0;
    ll ans = 0;
    queue<pair<int,int>> q;
    q.push(st);
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        ans += d[{x, y}];
        for (int k=0; k<4; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (s.find({nx, ny}) != s.end() && d.find({nx, ny}) == d.end()) {
                d[{nx, ny}] = d[{x, y}] + 1;
                q.push({nx, ny});
            }
        }
    }
    return ans;
}

int DistanceSum(int N, int *X, int *Y) {
    for (int i=0; i<N; i++) {
        s.insert({X[i], Y[i]});
    }
    ll ans = 0;
    for (int i=0; i<N; i++) {
        ans += getDist({X[i], Y[i]});
        ans %= mod;
    }
    return ans / 2;
}

Compilation message

city.cpp: In function 'll getDist(std::pair<int, int>)':
city.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |         auto [x, y] = q.front();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 15 ms 464 KB Output is correct
7 Correct 16 ms 468 KB Output is correct
8 Correct 14 ms 344 KB Output is correct
9 Correct 16 ms 472 KB Output is correct
10 Correct 18 ms 348 KB Output is correct
11 Correct 15 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 515 ms 848 KB Output is correct
2 Correct 467 ms 548 KB Output is correct
3 Execution timed out 1068 ms 604 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1048 ms 2908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1046 ms 2904 KB Time limit exceeded
2 Halted 0 ms 0 KB -