Submission #547652

# Submission time Handle Problem Language Result Execution time Memory
547652 2022-04-11T07:17:44 Z tabr Ideal city (IOI12_city) C++17
32 / 100
1000 ms 2900 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int DistanceSum(int n, int x[], int y[]) {
    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; i++) {
        mp[make_pair(x[i], y[i])] = i;
    }
    vector<vector<int>> g(n);
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    for (int i = 0; i < n; i++) {
        for (int dir = 0; dir < 4; dir++) {
            int nx = x[i] + dx[dir];
            int ny = y[i] + dy[dir];
            if (mp.count(make_pair(nx, ny))) {
                g[i].emplace_back(mp[make_pair(nx, ny)]);
            }
        }
    }
    const long long mod = (int) 2e9;
    long long res = 0;
    for (int r = 0; r < n; r++) {
        vector<int> d(n, -1);
        queue<int> que;
        d[r] = 0;
        que.emplace(r);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int to : g[v]) {
                if (d[to] == -1) {
                    d[to] = d[v] + 1;
                    que.emplace(to);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            res += d[i];
            res %= mod;
        }
    }
    return (int) (res / 2);
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n = 11;
    int x[] = {2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5};
    int y[] = {5, 6, 3, 6, 3, 4, 5, 6, 3, 4, 6};
    cout << DistanceSum(n, x, y) << '\n';
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 304 KB Output is correct
7 Correct 2 ms 304 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 304 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 340 KB Output is correct
2 Correct 31 ms 436 KB Output is correct
3 Correct 75 ms 500 KB Output is correct
4 Correct 70 ms 492 KB Output is correct
5 Correct 125 ms 596 KB Output is correct
6 Correct 117 ms 468 KB Output is correct
7 Correct 132 ms 568 KB Output is correct
8 Correct 117 ms 468 KB Output is correct
9 Correct 114 ms 564 KB Output is correct
10 Correct 112 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 2900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 2884 KB Time limit exceeded
2 Halted 0 ms 0 KB -