Submission #362963

# Submission time Handle Problem Language Result Execution time Memory
362963 2021-02-05T01:42:15 Z Seanliu Ideal city (IOI12_city) C++14
32 / 100
194 ms 1004 KB
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
using namespace std;

const int MOD = 1e9, maxN = 2326;
const long long int INF = (1LL << 31) - 2;

int mp[maxN][maxN], vis[maxN], d[maxN], dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
queue<int> que;

inline int add(int a, int b){
	return (a + b >= MOD ? a + b - MOD : a + b);
}

int DistanceSum(int N, int *X, int *Y) {
	if(N > maxN) return 0;
	int minX = INF, minY = INF;
	for(int i = 0; i < N; i++){
		minX = min(minX, X[i]);
		minY = min(minY, Y[i]);
	}
	for(int i = 0; i < N; i++){
		X[i] -= minX - 1;
		Y[i] -= minY - 1;
		mp[X[i]][Y[i]] = i + 1;
	}
	long long int ans = 0;
	for(int i = 0; i < N; i++){
		fill(d, d + N, INF);	
		fill(vis, vis + N, false);
		d[i] = 0;
		que.push(i);
		vis[i] = true;
		//cout << "i = " << i << endl;
		while(que.size()){
			int id = que.front(); que.pop();
			for(int j = 0; j < 4; j++){
				if(mp[X[id] + dir[j][0]][Y[id] + dir[j][1]]){
					int nid = mp[X[id] + dir[j][0]][Y[id] + dir[j][1]] - 1;
					if(!vis[nid]){
						d[nid] = d[id] + 1;
						//cout << "d[" << i << "][" << nid << "] = " << d[nid] << endl;
						ans = add(ans, d[nid]);
						vis[nid] = true;
						que.push(nid);
					}
				}
			}
		}
	}
	return ans / 2;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 644 KB Output is correct
2 Correct 35 ms 492 KB Output is correct
3 Correct 96 ms 620 KB Output is correct
4 Correct 83 ms 748 KB Output is correct
5 Correct 194 ms 876 KB Output is correct
6 Correct 126 ms 748 KB Output is correct
7 Correct 186 ms 1004 KB Output is correct
8 Correct 130 ms 896 KB Output is correct
9 Correct 124 ms 620 KB Output is correct
10 Correct 126 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -