답안 #98198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98198 2019-02-21T12:21:51 Z E869120 이상적인 도시 (IOI12_city) C++14
55 / 100
160 ms 3704 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]++; }
		for (int i = 1; i <= N; i++) { cx[i] += cx[i - 1]; cy[i] += cy[i - 1]; }
		
		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;
	}
}
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 464 KB Output is correct
2 Correct 37 ms 384 KB Output is correct
3 Correct 79 ms 488 KB Output is correct
4 Correct 94 ms 384 KB Output is correct
5 Correct 153 ms 632 KB Output is correct
6 Correct 160 ms 604 KB Output is correct
7 Correct 156 ms 512 KB Output is correct
8 Correct 155 ms 548 KB Output is correct
9 Correct 153 ms 548 KB Output is correct
10 Correct 140 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 896 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 14 ms 2048 KB Output is correct
4 Correct 14 ms 1920 KB Output is correct
5 Correct 24 ms 3600 KB Output is correct
6 Correct 27 ms 3448 KB Output is correct
7 Correct 43 ms 3704 KB Output is correct
8 Correct 27 ms 3580 KB Output is correct
9 Correct 37 ms 3600 KB Output is correct
10 Correct 37 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -