Submission #547421

# Submission time Handle Problem Language Result Execution time Memory
547421 2022-04-10T16:21:57 Z tabr Ideal city (IOI12_city) C++17
32 / 100
1000 ms 3080 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 int mod = (int) 1e9;
    int 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 = r + 1; i < n; i++) {
            res += d[i];
            res %= mod;
        }
    }
    return res;
}

#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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 300 KB Output is correct
2 Correct 28 ms 436 KB Output is correct
3 Correct 70 ms 468 KB Output is correct
4 Correct 67 ms 468 KB Output is correct
5 Correct 119 ms 572 KB Output is correct
6 Correct 108 ms 468 KB Output is correct
7 Correct 125 ms 580 KB Output is correct
8 Correct 114 ms 468 KB Output is correct
9 Correct 108 ms 468 KB Output is correct
10 Correct 101 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 3080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 3072 KB Time limit exceeded
2 Halted 0 ms 0 KB -