답안 #253421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253421 2020-07-28T03:58:45 Z tinjyu 이상적인 도시 (IOI12_city) C++14
32 / 100
218 ms 71032 KB
#include <iostream>
using namespace std;
long long int sumx[100005],sumy[100005],t[100005],len[100005],n,map[2005][2005],tag[2005][2005];
int DistanceSum(int N, int *x, int *y) {
	n=N;
	int mix=2000000000,miy=2000000000;
	for(int i=0;i<n;i++)
	{
		mix=min(mix,x[i]);
		miy=min(miy,y[i]);
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)map[i][j]=-1;
	}
	for(int i=0;i<n;i++)
	{
		x[i]-=mix;
		y[i]-=miy;
		map[x[i]][y[i]]=i;
	}
	if(n>2000)
	{
		long long int ans=0;
		for(int i=0;i<n;i++)
		{
			sumx[x[i]]++;
			sumy[y[i]]++;
		}
		long long int now=0,num=0;
		for(int i=0;i<=4;i++)
		{
			ans+=now*sumx[i];
			num+=sumx[i];
			now+=num;
			now%=1000000000;
			ans%=1000000000;
		}
		now=0,num=0;
		for(int i=0;i<=100000;i++)
		{
			ans+=now*sumy[i];
			num+=sumy[i];
			now+=num;
			now%=1000000000;
			ans%=1000000000;
		}
		return ans;
	}
	
	long long int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			tag[x[j]][y[j]]=0;
		}
		t[0]=i;
		len[0]=0;
		tag[x[i]][y[i]]=1;
		long long int p=0,pp=0;
		while(p<=pp)
		{
			if(t[p]<i)ans+=len[p];
			ans%=1000000000;
			for(int i=1;i<=4;i++)
			{
				long long int tmpx=x[t[p]],tmpy=y[t[p]];
				if(i==1)tmpx++;
				if(i==2)tmpy++;
				if(i==3)tmpx--;
				if(i==4)tmpy--;
				if(tmpx>=0 && tmpy>=0 && map[tmpx][tmpy]!=-1 && tag[tmpx][tmpy]==0)
				{
					pp++;
					len[pp]=len[p]+1;
					t[pp]=map[tmpx][tmpy];
					tag[tmpx][tmpy]=1;
				}
			}
			p++;		
		}
	}
  return ans;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 896 KB Output is correct
5 Correct 1 ms 896 KB Output is correct
6 Correct 2 ms 1536 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
11 Correct 2 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 12416 KB Output is correct
2 Correct 45 ms 12416 KB Output is correct
3 Correct 124 ms 24320 KB Output is correct
4 Correct 111 ms 24192 KB Output is correct
5 Correct 218 ms 32376 KB Output is correct
6 Correct 152 ms 32128 KB Output is correct
7 Correct 210 ms 32508 KB Output is correct
8 Correct 154 ms 32384 KB Output is correct
9 Correct 145 ms 32128 KB Output is correct
10 Correct 139 ms 32116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 71032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 85 ms 71032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -