Submission #69796

# Submission time Handle Problem Language Result Execution time Memory
69796 2018-08-21T13:49:52 Z FedericoS Ideal city (IOI12_city) C++14
32 / 100
210 ms 1752 KB
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

int xmov[]={0, 1, 0, -1};
int ymov[]={1, 0, -1, 0};
int K;
queue<pii> Q;
int B[2005][2005];
int D[2005][2005];
ll ans;
ll S;
ll mod=1e9;

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

	if(N<=2000){

		K=*min_element(X,X+N);
		for(int i=0;i<N;i++)
			X[i]-=K;

		K=*min_element(Y,Y+N);
		for(int i=0;i<N;i++)
			Y[i]-=K;

		for(int i=0;i<N;i++)
			B[X[i]][Y[i]]=true;

		for(int i=0;i<N;i++){

			for(int j=0;j<N;j++)
				D[X[j]][Y[j]]=-1;
			D[X[i]][Y[i]]=0;
			Q.push({X[i],Y[i]});

			while(!Q.empty()){

				pii p=Q.front();
				Q.pop();

				for(int j=0;j<4;j++)
					if(B[p.first+xmov[j]][p.second+ymov[j]] and D[p.first+xmov[j]][p.second+ymov[j]]==-1){
						D[p.first+xmov[j]][p.second+ymov[j]]=D[p.first][p.second]+1;
						Q.push({p.first+xmov[j],p.second+ymov[j]});
					}

			}

			for(int j=0;j<N;j++)
				ans+=D[X[j]][Y[j]];

		}

		return ans/2;
		
	}

	sort(X,X+N);

	for(ll i=0;i<N;i++){
		ans=(ans+i*X[i]-S)%mod;
		S=(S+X[i])%mod;
	}

	sort(Y,Y+N);

	for(ll i=0;i<N;i++){
		ans=(ans+i*Y[i]-S)%mod;
		S=(S+Y[i])%mod;
	}

	return ans;

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 5 ms 620 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 4 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 960 KB Output is correct
2 Correct 36 ms 960 KB Output is correct
3 Correct 134 ms 1344 KB Output is correct
4 Correct 87 ms 1344 KB Output is correct
5 Correct 203 ms 1516 KB Output is correct
6 Correct 147 ms 1516 KB Output is correct
7 Correct 210 ms 1644 KB Output is correct
8 Correct 149 ms 1752 KB Output is correct
9 Correct 123 ms 1752 KB Output is correct
10 Correct 116 ms 1752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 1752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1752 KB Output isn't correct
2 Halted 0 ms 0 KB -