답안 #912826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912826 2024-01-20T02:18:29 Z Muhammad_Aneeq 이상적인 도시 (IOI12_city) C++17
23 / 100
44 ms 7792 KB
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int const MAXN=1e5+10;
vector<int>nei[MAXN]={};
int mod=1e9;
int DistanceSum(int N, int X[], int Y[])
{
	int ans=0;
	map<int,vector<int>>d;
	for (int 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);
		int ans=0;
		long long szx=0,sux=0,szy=0,suy=0;
		for (int 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;
	}
	return ans;
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:19:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   19 |   if (i.second.size()!=i.second.back()-i.second[0]+1)
      |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2908 KB Output is correct
2 Correct 7 ms 3364 KB Output is correct
3 Correct 17 ms 3976 KB Output is correct
4 Correct 17 ms 3932 KB Output is correct
5 Correct 31 ms 5212 KB Output is correct
6 Correct 33 ms 4948 KB Output is correct
7 Correct 34 ms 5204 KB Output is correct
8 Correct 31 ms 5092 KB Output is correct
9 Correct 35 ms 4948 KB Output is correct
10 Correct 44 ms 7792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -