Submission #98196

# Submission time Handle Problem Language Result Execution time Memory
98196 2019-02-21T12:18:33 Z E869120 Ideal city (IOI12_city) C++14
32 / 100
166 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> G[2009]; int dist[2009], mod = 1000000000;
long long cx[200009], cy[200009];

int DistanceSum(int N, int *X, int *Y) {
	if (N > 2000) {
		int minx = 2147483647, miny = 2147483647;
		for (int i = 0; i < N; i++) { minx = min(minx, X[i]); miny = min(miny, Y[i]); }
		for (int i = 0; i < N; i++) { cx[X[i] - minx]++; cy[Y[i] - miny]++; }
		
		long long sum = 0;
		for (int i = 0; i <= N; i++) sum += 1LL * cx[i] * (1LL * N - cx[i]);
		for (int i = 0; i <= N; i++) sum += 1LL * cy[i] * (1LL * N - cy[i]);
		return sum % mod;
	}
	else {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				int V = abs(X[i] - X[j]) + abs(Y[i] - Y[j]);
				if (V == 1) G[i].push_back(j);
			}
		}
		
		int sum = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) dist[j] = 10000;
			
			queue<int> que; que.push(i); dist[i] = 0;
			while (!que.empty()) {
				int pos = que.front(); que.pop();
				for (int j = 0; j < (int)G[pos].size(); j++) {
					if (dist[G[pos][j]] > dist[pos] + 1) {
						dist[G[pos][j]] = dist[pos] + 1;
						que.push(G[pos][j]);
					}
				}
			}
			for (int j = i + 1; j < N; j++) { sum += dist[j]; sum %= mod; }
		}
		return sum;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 304 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 384 KB Output is correct
2 Correct 35 ms 384 KB Output is correct
3 Correct 78 ms 512 KB Output is correct
4 Correct 93 ms 484 KB Output is correct
5 Correct 144 ms 512 KB Output is correct
6 Correct 166 ms 504 KB Output is correct
7 Correct 145 ms 512 KB Output is correct
8 Correct 145 ms 512 KB Output is correct
9 Correct 150 ms 512 KB Output is correct
10 Correct 147 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -