Submission #118423

# Submission time Handle Problem Language Result Execution time Memory
118423 2019-06-19T02:54:17 Z E869120 Ideal city (IOI12_city) C++14
32 / 100
118 ms 1376 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

vector<int>vec[2009]; int dist[2009];

int DistanceSum(int N, int *X, int *Y) {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) == 1) {
				vec[i].push_back(j);
			}
		}
	}

	long long sum = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) dist[j] = (1 << 30);
		queue<int>Q; Q.push(i); dist[i] = 0;
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			for (int j = 0; j < vec[pos].size(); j++) {
				if (dist[vec[pos][j]] > dist[pos] + 1) {
					dist[vec[pos][j]] = dist[pos] + 1;
					Q.push(vec[pos][j]);
				}
			}
		}
		for (int j = 0; j < N; j++) sum += dist[j];
	}
	return (int)((sum / 2LL) % 1000000000LL);
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < vec[pos].size(); j++) {
                    ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 14 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 384 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 25 ms 384 KB Output is correct
2 Correct 28 ms 384 KB Output is correct
3 Correct 63 ms 512 KB Output is correct
4 Correct 66 ms 384 KB Output is correct
5 Correct 118 ms 512 KB Output is correct
6 Correct 116 ms 492 KB Output is correct
7 Correct 116 ms 528 KB Output is correct
8 Correct 118 ms 512 KB Output is correct
9 Correct 118 ms 512 KB Output is correct
10 Correct 111 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 112 ms 1184 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 1376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -