Submission #577161

# Submission time Handle Problem Language Result Execution time Memory
577161 2022-06-14T08:10:42 Z WongChun1234 Ideal city (IOI12_city) C++14
11 / 100
1000 ms 4412 KB
//#include"grader.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100050;
const ll MOD=1000000000;
const bool DEBUG=0;
int n,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
ll ans;
pair<int,int> coord[N];
map<pair<int,int>,int> hv,vis;
queue<pair<pair<int,int>,int>> bfs;
int DistanceSum(int _N, int *x, int *y) {
	n=_N;
	for (int i=0;i<n;i++) coord[i]={x[i],y[i]};
	sort(coord,coord+n);
	for (int i=0;i<n;i++){
		hv[coord[i]]=i+1;
	}
	for (int i=0;i<n;i++){
		vis.clear();
		while (bfs.size()) bfs.pop();
		bfs.push({coord[i],0});
		vis[coord[i]]=1;
		while (bfs.size()){
			auto curr=bfs.front().first;
			int cdist=bfs.front().second;
			bfs.pop();
			for (int i=0;i<4;i++){
				if (!hv[{curr.first+dx[i],curr.second+dy[i]}]) continue;
				if (vis[{curr.first+dx[i],curr.second+dy[i]}]) continue;
				ans+=cdist+1;
				ans%=MOD;
				vis[{curr.first+dx[i],curr.second+dy[i]}]=1;
				bfs.push({{curr.first+dx[i],curr.second+dy[i]},cdist+1});
			}
		}
	}
	return ans/2;
}

/*
6
1 1
2 1
2 3
3 1
3 2
3 3
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 5 ms 316 KB Output is correct
6 Correct 19 ms 340 KB Output is correct
7 Correct 19 ms 312 KB Output is correct
8 Correct 17 ms 460 KB Output is correct
9 Correct 18 ms 340 KB Output is correct
10 Correct 22 ms 344 KB Output is correct
11 Correct 18 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 635 ms 512 KB Output is correct
2 Correct 586 ms 492 KB Output is correct
3 Execution timed out 1085 ms 596 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 3260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 4412 KB Time limit exceeded
2 Halted 0 ms 0 KB -