Submission #576456

#TimeUsernameProblemLanguageResultExecution timeMemory
576456benson1029Ideal city (IOI12_city)C++14
32 / 100
1087 ms5308 KiB
#include<bits/stdc++.h>
using namespace std;

int mp[2005][2005], vis[2005][2005], dis[2005][2005];
queue< pair<int,int> > q;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
vector<int> XX, YY;


int DistanceSum(int N, int *X, int *Y) {
	for(int i=0; i<N; i++) {
		XX.push_back(X[i]);
		YY.push_back(Y[i]);
	}
	sort(XX.begin(), XX.end()); sort(YY.begin(), YY.end());
	for(int i=0; i<N; i++) {
		X[i] -= XX[0];
		Y[i] -= YY[0];
	}
	for(int i=0; i<N; i++) {
		mp[X[i]][Y[i]] = 1;
	}
	long long ans = 0;
	for(int i=0; i<N; i++) {
		for(int j=0; j<N; j++) vis[X[j]][Y[j]] = 0;
		vis[X[i]][Y[i]] = 1;
		q.push({X[i], Y[i]});
		dis[X[i]][Y[i]] = 0;
		while(!q.empty()) {
			int x = q.front().first;
			int y = q.front().second;
			ans += dis[x][y];
			q.pop();
			for(int j=0; j<4; j++) {
				if(mp[x+dx[j]][y+dy[j]] == 1 && vis[x+dx[j]][y+dy[j]] == 0) {
					vis[x+dx[j]][y+dy[j]] = 1;
					dis[x+dx[j]][y+dy[j]] = dis[x][y] + 1;
					q.push({x+dx[j], y+dy[j]});
				}
			}
		}
	}
	return (ans/2) % 1000000000;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...