답안 #912893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912893 2024-01-20T04:05:38 Z Muhammad_Aneeq 이상적인 도시 (IOI12_city) C++17
44 / 100
1000 ms 8224 KB
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
using namespace std;
long long const MAXN=1e5+10;
vector<long long>nei[MAXN]={};
long long mod=1e9;
long long ans=0;
vector<long long>dx={0,0,-1,1},dy={-1,1,0,0};
long long dis[MAXN]={};
bool vis[MAXN]={};
void bfs(long long x)
{
	queue<int>s;
	s.push(x);
	vis[x]=1;
	while (s.size())
	{
		int y=s.front();
		s.pop();
		for (auto j:nei[y])
		{
			if (!vis[j])
			{
				dis[j]=dis[y]+1;
				vis[j]=1;
				s.push(j);
			}
		}
	}
}
int DistanceSum(int N, int X[], int Y[])
{
	map<long long,vector<long long>>d;
	map<pair<long long,long long>,long long>ex,cnt;
	for (long long i=0;i<N;i++)
		d[X[i]].push_back(Y[i]);
	bool subtask_3=1;
	for (auto& i:d)
	{
		sort(begin(i.second),end(i.second));
		if (i.second.size()!=i.second.back()-i.second[0]+1)
		{
			subtask_3=0;
			break;
		}
	}
	if (subtask_3)
	{
		sort(Y,Y+N);
		sort(X,X+N);
		long long ans=0;
		long long szx=0,sux=0,szy=0,suy=0;
		for (long long i=0;i<N;i++)
		{
			long long g=1ll*Y[i]*szy-suy;
			g%=mod;
			ans=(ans+g)%mod;
			g=1ll*X[i]*szx-sux;
			g%=mod;
			ans=(ans+g)%mod;
			szy++;
			suy+=Y[i];
			szx++;
			sux+=X[i];
		}
		return ans;
	}
	for (int i=0;i<N;i++)
	{
		for (int j=0;j<N;j++)
		{
			if (abs(X[i]-X[j])+abs(Y[i]-Y[j])==1)
				nei[i].push_back(j);
		}
	}
	for (long long i=0;i<N;i++)
		dis[i]=0;
	for (long long i=0;i<N;i++)
	{
		bfs(i);
		for (long long j=0;j<N;j++)
		{
			dis[j]%=mod;
			ans=(ans+dis[j])%mod;
		}
		for (long long j=0;j<N;j++)
			dis[j]=vis[j]=0;
	}
	return ans/2;
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:46:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wsign-compare]
   46 |   if (i.second.size()!=i.second.back()-i.second[0]+1)
      |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Incorrect 2 ms 3420 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3560 KB Output is correct
2 Correct 31 ms 3420 KB Output is correct
3 Correct 77 ms 3604 KB Output is correct
4 Correct 80 ms 3420 KB Output is correct
5 Correct 130 ms 3636 KB Output is correct
6 Correct 138 ms 3676 KB Output is correct
7 Correct 132 ms 3648 KB Output is correct
8 Correct 140 ms 3416 KB Output is correct
9 Correct 127 ms 3420 KB Output is correct
10 Correct 124 ms 3648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3932 KB Output is correct
2 Correct 9 ms 3932 KB Output is correct
3 Correct 16 ms 4444 KB Output is correct
4 Correct 17 ms 4692 KB Output is correct
5 Correct 32 ms 5912 KB Output is correct
6 Correct 36 ms 5756 KB Output is correct
7 Correct 35 ms 5724 KB Output is correct
8 Correct 34 ms 5724 KB Output is correct
9 Correct 40 ms 5532 KB Output is correct
10 Correct 54 ms 8224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1054 ms 4724 KB Time limit exceeded
2 Halted 0 ms 0 KB -