답안 #69798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69798 2018-08-21T13:54:51 Z FedericoS 이상적인 도시 (IOI12_city) C++14
55 / 100
201 ms 1692 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;
	}

	S=0;

	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;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 2 ms 668 KB Output is correct
5 Correct 3 ms 668 KB Output is correct
6 Correct 4 ms 668 KB Output is correct
7 Correct 3 ms 732 KB Output is correct
8 Correct 4 ms 840 KB Output is correct
9 Correct 4 ms 840 KB Output is correct
10 Correct 3 ms 840 KB Output is correct
11 Correct 3 ms 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 1120 KB Output is correct
2 Correct 37 ms 1120 KB Output is correct
3 Correct 105 ms 1288 KB Output is correct
4 Correct 79 ms 1376 KB Output is correct
5 Correct 183 ms 1524 KB Output is correct
6 Correct 128 ms 1524 KB Output is correct
7 Correct 201 ms 1692 KB Output is correct
8 Correct 152 ms 1692 KB Output is correct
9 Correct 118 ms 1692 KB Output is correct
10 Correct 126 ms 1692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1692 KB Output is correct
2 Correct 10 ms 1692 KB Output is correct
3 Correct 21 ms 1692 KB Output is correct
4 Correct 28 ms 1692 KB Output is correct
5 Correct 38 ms 1692 KB Output is correct
6 Correct 37 ms 1692 KB Output is correct
7 Correct 43 ms 1692 KB Output is correct
8 Correct 39 ms 1692 KB Output is correct
9 Correct 46 ms 1692 KB Output is correct
10 Correct 51 ms 1692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1692 KB Output isn't correct
2 Halted 0 ms 0 KB -