Submission #420394

# Submission time Handle Problem Language Result Execution time Memory
420394 2021-06-08T10:35:03 Z Aldas25 Ideal city (IOI12_city) C++14
32 / 100
1000 ms 3976 KB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

const int MAXN = 100100;

int x[MAXN], y[MAXN];
ll d[MAXN];
int n;
vi adj[MAXN];

void bfs (int st) {
    FOR(i, 0, n-1) d[i] = -1;
    queue<int> q;
    q.push(st);
    d[st] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : adj[v]) {
            if (d[u] == -1) {
                d[u] = d[v]+1;
                q.push(u);
            }
        }
    }
}

int DistanceSum(int N, int *X, int *Y) {

    n = N;
    FOR(i, 0, n-1) x[i] = X[i];
    FOR(i, 0, n-1) y[i] = Y[i];

    FOR(i, 0, n-1) FOR(j, i+1, n-1) {
        if (abs(x[i] - x[j]) + abs(y[i] - y[j]) == 1){
            adj[i].pb(j);
            adj[j].pb(i);
        }
    }

    ll ans = 0;
    FOR(i, 0, n-1) {
        bfs(i);
        FOR(j, 0, n-1) ans += d[j];
    }
    ans /= 2;

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2656 KB Output is correct
10 Correct 3 ms 2660 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2636 KB Output is correct
2 Correct 33 ms 2708 KB Output is correct
3 Correct 69 ms 2752 KB Output is correct
4 Correct 76 ms 2756 KB Output is correct
5 Correct 121 ms 2772 KB Output is correct
6 Correct 135 ms 2780 KB Output is correct
7 Correct 128 ms 2780 KB Output is correct
8 Correct 140 ms 2868 KB Output is correct
9 Correct 135 ms 2776 KB Output is correct
10 Correct 133 ms 2788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 3976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1036 ms 3840 KB Time limit exceeded
2 Halted 0 ms 0 KB -