답안 #3165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3165 2013-08-27T04:40:54 Z cki86201 이상적인 도시 (IOI12_city) C++
100 / 100
104 ms 10260 KB
#include<algorithm>
#include<stdio.h>
using namespace std;

int ord[100010];
int *X,*Y;
int N;
int gro[2][100010];
int wei[2][100010];
int len[2];
int C;
int st[2][100010],en[2][200020], next[2][200020], c[2];
bool check[2][100010];
long long ans;

bool comp1(const int a,const int b){return X[a]!=X[b]?X[a]<X[b]:Y[a]<Y[b];}
bool comp2(const int a,const int b){return Y[a]!=Y[b]?Y[a]<Y[b]:X[a]<X[b];}

void addedge(int t,int s,int d)
{
	++c[t];
	next[t][c[t]]=st[t][s];
	st[t][s]=c[t];
	en[t][c[t]]=d;
}

void make_edge(int t)
{
	t?sort(ord,ord+N,comp1):sort(ord,ord+N,comp2);
	int i;
	for(i=0;i<N;i++){
		if(i && gro[t^1][ord[i]]==gro[t^1][ord[i-1]] && gro[t][ord[i]]!=gro[t][ord[i-1]]){
			int s=gro[t][ord[i]],d=gro[t][ord[i-1]];
			addedge(t,s,d);
			addedge(t,d,s);
		}
	}
}

int dfs(int t,int x)
{
	check[t][x]=1;
	int i,cnt=0;
	for(i=st[t][x];i;i=next[t][i]){
		if(check[t][en[t][i]])continue;
		int x=dfs(t,en[t][i]);
		cnt+=x;
		ans+=(long long)x*(N-x);
	}
	return cnt+wei[t][x];
}

int DistanceSum(int Nn, int *Xx, int *Yy){
	X=Xx,Y=Yy,N=Nn;
	int i,cnt=0;
	for(i=0;i<N;i++)ord[i]=i;
	sort(ord,ord+N,comp1);
	for(i=0;i<N;i++){
		if(!i || (X[ord[i]]!=X[ord[i-1]] || Y[ord[i]]-Y[ord[i-1]]!=1)){
			wei[0][len[0]]=cnt;
			++len[0];
			cnt=0;
		}
		gro[0][ord[i]]=len[0];
		cnt++;
		if(i==N-1)wei[0][len[0]]=cnt;
	}
	sort(ord,ord+N,comp2);cnt=0;
	for(i=0;i<N;i++){
		if(!i || (Y[ord[i]]!=Y[ord[i-1]] || X[ord[i]]-X[ord[i-1]]!=1)){
			wei[1][len[1]]=cnt;
			++len[1];
			cnt=0;
		}
		gro[1][ord[i]]=len[1];
		cnt++;
		if(i==N-1)wei[1][len[1]]=cnt;
	}
	make_edge(0);
	make_edge(1);
	dfs(0,1);
	dfs(1,1);
	return (int)(ans%1000000000ll);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7140 KB Output is correct
2 Correct 0 ms 7140 KB Output is correct
3 Correct 0 ms 7140 KB Output is correct
4 Correct 0 ms 7140 KB Output is correct
5 Correct 0 ms 7140 KB Output is correct
6 Correct 0 ms 7140 KB Output is correct
7 Correct 0 ms 7140 KB Output is correct
8 Correct 0 ms 7140 KB Output is correct
9 Correct 0 ms 7140 KB Output is correct
10 Correct 0 ms 7140 KB Output is correct
11 Correct 0 ms 7140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7272 KB Output is correct
2 Correct 0 ms 7272 KB Output is correct
3 Correct 0 ms 7272 KB Output is correct
4 Correct 0 ms 7272 KB Output is correct
5 Correct 0 ms 7276 KB Output is correct
6 Correct 0 ms 7276 KB Output is correct
7 Correct 0 ms 7276 KB Output is correct
8 Correct 0 ms 7276 KB Output is correct
9 Correct 0 ms 7276 KB Output is correct
10 Correct 0 ms 7276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7344 KB Output is correct
2 Correct 16 ms 7344 KB Output is correct
3 Correct 48 ms 7532 KB Output is correct
4 Correct 44 ms 7532 KB Output is correct
5 Correct 104 ms 7924 KB Output is correct
6 Correct 104 ms 7928 KB Output is correct
7 Correct 104 ms 7948 KB Output is correct
8 Correct 96 ms 7924 KB Output is correct
9 Correct 104 ms 8052 KB Output is correct
10 Correct 100 ms 10260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7344 KB Output is correct
2 Correct 16 ms 7348 KB Output is correct
3 Correct 48 ms 7532 KB Output is correct
4 Correct 40 ms 7576 KB Output is correct
5 Correct 100 ms 7924 KB Output is correct
6 Correct 104 ms 8096 KB Output is correct
7 Correct 104 ms 8068 KB Output is correct
8 Correct 100 ms 8004 KB Output is correct
9 Correct 96 ms 7924 KB Output is correct
10 Correct 104 ms 7924 KB Output is correct