summary refs log tree commit diff homepage
path: root/2018/day06.c
blob: c204264d2640105d1f0c0ce2a68d244835fbab4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>

static int len;
static struct Point {
	int x, y;
} points[50];
static int area[50];

static int dist(struct Point a, struct Point b) {
	int x = a.x - b.x;
	int y = a.y - b.y;
	return (x < 0 ? -x : x) + (y < 0 ? -y : y);
}

static int close(struct Point p) {
	int c = 0;
	for (int i = 1; i < len; ++i) {
		if (dist(p, points[i]) < dist(p, points[c])) c = i;
	}
	for (int i = 0; i < len; ++i) {
		if (dist(p, points[i]) == dist(p, points[c]) && i != c) return -1;
	}
	return c;
}

int main() {
	while (!feof(stdin)) {
		scanf("%d, %d\n", &points[len].x, &points[len].y);
		len++;
	}
	int maxX = 0, maxY = 0;
	for (int i = 0; i < len; ++i) {
		if (points[i].x > maxX) maxX = points[i].x;
		if (points[i].y > maxY) maxY = points[i].y;
	}
	for (int x = 0; x <= maxX; ++x) {
		for (int y = 0; y <= maxY; ++y) {
			int c = close((struct Point) { x, y });
			if (c < 0) continue;
			if (area[c] < 0) continue;
			area[c]++;
			if (x == 0 || x == maxX || y == 0 || y == maxY) area[c] = -1;
		}
	}
	int max = 0;
	for (int i = 0; i < len; ++i) {
		if (area[i] > max) max = area[i];
	}
	printf("%d\n", max);

	int size = 0;
	for (int x = 0; x <= maxX; ++x) {
		for (int y = 0; y <= maxY; ++y) {
			int sum = 0;
			for (int i = 0; i < len; ++i) {
				sum += dist((struct Point) { x, y }, points[i]);
			}
			if (sum < 10000) size++;
		}
	}
	printf("%d\n", size);
}