답안 #61844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61844 2018-07-26T21:03:25 Z zetapi 이상적인 도시 (IOI12_city) C++14
100 / 100
378 ms 67776 KB
#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr ::iterator 

typedef pair<ll,ll>  pii;

const ll MAX=1e6;
const ll mod=1e9;

vector<pii> vec;

set<ll> adj[MAX];

ll res,value[MAX],sum[MAX];

void dfs(int node,int par)
{
	sum[node]=value[node];
	for(auto A:adj[node])
	{
		if(A==par)
			continue;
		dfs(A,node);
		sum[node]+=sum[A];
		sum[node]%=mod;
	}
	return ;
}

void dfs_(int node,int par)
{
	for(auto A:adj[node])
	{
		if(A==par)
			continue;
		dfs_(A,node);
		res+=(sum[A]*(sum[1]-sum[A]+mod)%mod)%mod;
		res%=mod;
	}
	return ;
}

void cal(int N,int *X,int *Y)
{
	for(int A=1;A<=N;A++)
	{
		sum[A]=0;
		value[A]=0;
		adj[A].clear();
	}
	int ptr=0;
	vector<pii> vec;
	map<pii,int> mark;
	for(int A=0;A<N;A++)
		vec.pb(mp(X[A],Y[A]));
	vec.pb(mp(0,0));
	sort(vec.begin(),vec.end());
	for(int A=1;A<vec.size();A++)
	{
		if(vec[A].first==vec[A-1].first and vec[A].second==vec[A-1].second+1)
		{
			value[ptr]++;
			mark[mp(vec[A].first,vec[A].second)]=ptr;
		}
		else
		{
			value[++ptr]++;
			mark[mp(vec[A].first,vec[A].second)]=ptr;		
		}
		//cout<<vec[A].first<<" "<<vec[A].second<<" "<<mark[vec[A]]<<"\n";
	}
	for(int A=1;A<vec.size();A++)
	{
		if(mark[mp(vec[A].first-1,vec[A].second)])
		{
			adj[mark[vec[A]]].insert(mark[mp(vec[A].first-1,vec[A].second)]);
			adj[mark[mp(vec[A].first-1,vec[A].second)]].insert(mark[vec[A]]);
		//	cout<<mark[vec[A]]<<" "<<mark[mp(vec[A].first-1,vec[A].second)]<<"lol \n";
		}
	}
	dfs(1,0);
	dfs_(1,0);
	return ;
}

int DistanceSum(int N, int *X, int *Y) 
{
	cal(N,X,Y);
	for(int A=0;A<N;A++)
		swap(X[A],Y[A]);
	cal(N,X,Y);
	return res;
}

/*signed main()
{
	ios_base::sync_with_stdio(false);

	int X[]={2,2,3,3,4,4,4,4,5,5,5};
	int Y[]={5,6,3,6,3,4,5,6,3,4,6};
	cout<<DistanceSum(11,X,Y);
	return 0;
}*/

Compilation message

city.cpp: In function 'void cal(int, int*, int*)':
city.cpp:62:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<vec.size();A++)
              ~^~~~~~~~~~~
city.cpp:76:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<vec.size();A++)
              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 47352 KB Output is correct
2 Correct 49 ms 47464 KB Output is correct
3 Correct 46 ms 47464 KB Output is correct
4 Correct 48 ms 47576 KB Output is correct
5 Correct 54 ms 47576 KB Output is correct
6 Correct 45 ms 47576 KB Output is correct
7 Correct 50 ms 47620 KB Output is correct
8 Correct 48 ms 47620 KB Output is correct
9 Correct 52 ms 47620 KB Output is correct
10 Correct 47 ms 47620 KB Output is correct
11 Correct 49 ms 47620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47688 KB Output is correct
2 Correct 46 ms 47688 KB Output is correct
3 Correct 59 ms 47824 KB Output is correct
4 Correct 57 ms 47824 KB Output is correct
5 Correct 59 ms 48048 KB Output is correct
6 Correct 61 ms 48048 KB Output is correct
7 Correct 62 ms 48048 KB Output is correct
8 Correct 53 ms 48048 KB Output is correct
9 Correct 58 ms 48048 KB Output is correct
10 Correct 63 ms 48048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 49916 KB Output is correct
2 Correct 98 ms 49984 KB Output is correct
3 Correct 182 ms 53080 KB Output is correct
4 Correct 187 ms 53216 KB Output is correct
5 Correct 342 ms 58276 KB Output is correct
6 Correct 350 ms 58336 KB Output is correct
7 Correct 355 ms 58440 KB Output is correct
8 Correct 341 ms 58440 KB Output is correct
9 Correct 333 ms 58588 KB Output is correct
10 Correct 340 ms 63452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 63452 KB Output is correct
2 Correct 99 ms 63452 KB Output is correct
3 Correct 207 ms 63452 KB Output is correct
4 Correct 201 ms 63452 KB Output is correct
5 Correct 376 ms 66080 KB Output is correct
6 Correct 352 ms 66080 KB Output is correct
7 Correct 378 ms 67776 KB Output is correct
8 Correct 362 ms 67776 KB Output is correct
9 Correct 345 ms 67776 KB Output is correct
10 Correct 339 ms 67776 KB Output is correct