Submission #1030906

#TimeUsernameProblemLanguageResultExecution timeMemory
1030906VMaksimoski008Ideal city (IOI12_city)C++17
32 / 100
63 ms604 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...