답안 #66027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66027 2018-08-09T12:17:14 Z mhnd 이상적인 도시 (IOI12_city) C++14
23 / 100
1000 ms 60224 KB
//#include "grader.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 5e5+50;
const ll oo = 1e18;
const ll mod = 1e9;

map<pair<ll,ll>,pair<int,int>> vis,cost;
map<pair<ll,ll>,bool> r;
ll ans = 0;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

void bfs(int sx,int sy){
	queue<pair<pair<int,int>,int>> q;
	q.push({{sx,sy},0});
	while(q.size()){
		pair<int,int> u = q.front().first;
		int cst = q.front().second;
		q.pop();
		if(vis[u] == make_pair(sx,sy))continue;
		vis[u]={sx,sy};
		for(int i=0;i<4;i++){
			pair<int,int> v = {u.first+dx[i],u.second+dy[i]};
			if(cost[v] == make_pair(sx,sy))continue;
			cost[v]={sx,sy};
			ans = (ans+cst+1)%mod;
			q.push({v,cst+1});
		}
	}
}

int DistanceSum(int N, int *X, int *Y) {
	if(N<=2000){
		for(int i=0;i<N;i++)r[{X[i],Y[i]}]=1;
		for(int i=0;i<N;i++)bfs(X[i],Y[i]);
		return ans;
	}
	sort(X,X+N);
	int sum=0,ret=0,lst=X[0];
	for(int i=0;i<N;i++){
		if(X[i]!=lst){
			ret = (ret + (X[i]-lst)*1ll*(sum*1ll*(N-sum))%mod)%mod;
			lst = X[i];
		}
		sum++;
	}
	ans = ret;
	sort(Y,Y+N);
	sum=0;ret=0;lst=Y[0];
	for(int i=0;i<N;i++){
		if(Y[i]!=lst){
			ret = (ret + (Y[i]-lst)*1ll*(sum*1ll*(N-sum))%mod)%mod;
			lst = Y[i];
		}
		sum++;
	}
	ans = (ans+ret)%mod;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 60224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 60224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 60224 KB Output is correct
2 Correct 9 ms 60224 KB Output is correct
3 Correct 20 ms 60224 KB Output is correct
4 Correct 19 ms 60224 KB Output is correct
5 Correct 36 ms 60224 KB Output is correct
6 Correct 37 ms 60224 KB Output is correct
7 Correct 40 ms 60224 KB Output is correct
8 Correct 36 ms 60224 KB Output is correct
9 Correct 40 ms 60224 KB Output is correct
10 Correct 34 ms 60224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 60224 KB Output isn't correct
2 Halted 0 ms 0 KB -