답안 #280462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
280462 2020-08-22T19:38:25 Z ElyesChaabouni 이상적인 도시 (IOI12_city) C++14
11 / 100
1000 ms 2332 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
int inc[4][2]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
int DistanceSum(int N, int *X, int *Y)
{
	long long ans=0;
	for(int i = 0; i < N; i++)
	{
		//cout << i << ' ' << X[i] << ' ' << Y[i] << '\n';
		unordered_map<pair<int, int>, int, hash_pair>m;
		for(int j = 0; j < N; j++)
		{
			if(j!=i)
			{
				m[make_pair(X[j], Y[j])]=j;
			}
		}
		int nb=1, idx=0;
		vector<pair<int, int> >bfs;
		bfs.push_back(make_pair(X[i], Y[i]));
		bool ok=1;
		while(bfs.size()!=N)
		{
			//cout << nb << '\n';
			int l=bfs.size();
			for(int j = idx; j < l; j++)
			{
				//cout << bfs[j].first << ' ' << bfs[j].second << '\n';
				for(int k = 0; k < 4; k++)
				{
					int xx=bfs[j].first+inc[k][0], yy=bfs[j].second+inc[k][1];
					pair<int, int>cu=make_pair(xx, yy);
					if(m.count(cu))
					{
						if(m[cu] < i)
						{
							ans+=nb;
							//ans%=1000000000;
						}
						m.erase(cu);
						bfs.push_back(cu);
					}
				}
			}
			nb++;
			idx=l;
		}
      ans%= 1000000000;
	}
  	//ans*=( 1000000000);
	ans%= 1000000000;
	return ans;
}
//size

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:41:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |   while(bfs.size()!=N)
      |         ~~~~~~~~~~^~~
city.cpp:40:8: warning: unused variable 'ok' [-Wunused-variable]
   40 |   bool ok=1;
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 12 ms 384 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 12 ms 384 KB Output is correct
9 Correct 12 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 12 ms 388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 384 KB Output is correct
2 Correct 347 ms 384 KB Output is correct
3 Execution timed out 1070 ms 504 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1072 ms 2292 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 2332 KB Time limit exceeded
2 Halted 0 ms 0 KB -