Submission #1030906

# Submission time Handle Problem Language Result Execution time Memory
1030906 2024-07-22T11:46:44 Z VMaksimoski008 Ideal city (IOI12_city) C++17
32 / 100
63 ms 604 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int DistanceSum(int N, int *X, int *Y) {
    if(N <= 2000) {
        vector<int> graph[N];
        for(int i=0; i<N; i++) {
            for(int j=i+1; j<N; j++) {
                if(abs(X[i] - X[j]) + abs(Y[i] - Y[j]) == 1) {
                    graph[i].push_back(j);
                    graph[j].push_back(i);
                }
            }
        }

        int ans = 0;

        for(int i=0; i<N; i++) {
            queue<int> q;
            vector<bool> vis(N);
            vector<int> dist(N);
            vis[i] = 1; q.push(i);

            while(!q.empty()) {
                int u = q.front(); q.pop();
                for(int &v : graph[u]) {
                    if(vis[v]) continue;
                    vis[v] = 1;
                    dist[v] = dist[u] + 1;
                    q.push(v);
                }
            }

            for(int j=i+1; j<N; j++) ans += dist[j];
        }

        return ans; 
    }

    return N;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 348 KB Output is correct
2 Correct 14 ms 512 KB Output is correct
3 Correct 30 ms 348 KB Output is correct
4 Correct 33 ms 348 KB Output is correct
5 Correct 45 ms 348 KB Output is correct
6 Correct 55 ms 348 KB Output is correct
7 Correct 56 ms 348 KB Output is correct
8 Correct 63 ms 572 KB Output is correct
9 Correct 61 ms 348 KB Output is correct
10 Correct 61 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 564 KB Output isn't correct
2 Halted 0 ms 0 KB -