Submission #466594

# Submission time Handle Problem Language Result Execution time Memory
466594 2021-08-19T17:57:44 Z rainboy Hexagonal Territory (APIO21_hexagon) C++17
36 / 100
42 ms 4672 KB
#include "hexagon.h"
#include <vector>

using namespace std;

typedef vector<int> vi;

const int MD = 1000000007, V2 = 500000004, V6 = 166666668, INF = 0x3f3f3f3f, X = 2000;

int max(int a, int b) { return a > b ? a : b; }

int dx[] = { 1, 1, 0, -1, -1, 0 };
int dy[] = { 0, 1, 1, 0, -1, -1 };

int choose2(int n) {
	return (long long) n * (n - 1) % MD * V2 % MD;
}

int choose3(int n) {
	return (long long) n * (n - 1) % MD * (n - 2) % MD * V6 % MD;
}

char grid[X][X + 1]; int dd[X][X], qu[X * X], head, cnt;

void dfs(int x, int y, char c) {
	int h;

	if (x < 0 || x >= X || y < 0 || y >= X || grid[x][y])
		return;
	grid[x][y] = c;
	for (h = 0; h < 6; h++)
		dfs(x + dx[h], y + dy[h], c);
}

long long cross(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int draw_territory(int n, int a, int b, vi hh, vi ll) {
	int h, i, l, x, y, x_, y_, ans1, ans2;
	long long area2, boundary, internal;

	if (n == 3)
		ans1 = choose2(ll[0] + 2), ans2 = choose3(ll[0] + 2) * 2 % MD;
	else if (b == 0 || 1) {
		x = 0, y = 0, area2 = 0, boundary = 0;
		for (i = 0; i < n; i++) {
			h = hh[i] - 1;
			area2 += cross(x, y, x + dx[h] * ll[i], y + dy[h] * ll[i]);
			boundary += ll[i];
			x += dx[h] * ll[i], y += dy[h] * ll[i];
		}
		if (area2 < 0)
			area2 = -area2;
		internal = (area2 - boundary) / 2 + 1;
		ans1 = (boundary + internal) % MD, ans2 = 0;
	} else {
		x = 1, y = 1;
		for (i = 0; i < n; i++) {
			h = hh[i] - 1;
			for (l = 0; l < ll[i]; l++)
				x = max(x + dx[h], 1), y = max(y + dy[h], 1);
		}
		x_ = x, y_ = y;
		for (i = 0; i < n; i++) {
			h = hh[i] - 1;
			for (l = 0; l < ll[i]; l++)
				grid[x += dx[h]][y += dy[h]] = 'X';
		}
		dfs(0, 0, ' ');
		for (x = 0; x < X; x++)
			for (y = 0; y < X; y++)
				dfs(x, y, 'O');
		ans1 = 0;
		for (x = 0; x < X; x++)
			for (y = 0; y < X; y++) {
				dd[x][y] = INF;
				if (grid[x][y] != ' ')
					ans1++;
			}
		dd[x_][y_] = 0, qu[head + cnt++] = x_ * X + y_;
		ans2 = 0;
		while (cnt) {
			int xy, d;

			xy = qu[cnt--, head++], x = xy / X, y = xy % X, d = dd[x][y] + 1;
			ans2 = (ans2 + dd[x][y]) % MD;
			for (h = 0; h < 6; h++) {
				int x_ = x + dx[h], y_ = y + dy[h];

				if (x_ >= 0 && x_ < X && y_ >= 0 && y_ < X && grid[x_][y_] != ' ' && dd[x_][y_] > d)
					dd[x_][y_] = d, qu[head + cnt++] = x_ * X + y_;
			}
		}
	}
	return ((long long) ans1 * a + (long long) ans2 * b) % MD;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 432 KB Output is correct
7 Correct 6 ms 844 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 8 ms 1228 KB Output is correct
12 Correct 9 ms 1228 KB Output is correct
13 Correct 8 ms 1112 KB Output is correct
14 Correct 9 ms 1308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 6 ms 820 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 9 ms 1200 KB Output is correct
14 Correct 9 ms 1228 KB Output is correct
15 Correct 10 ms 1100 KB Output is correct
16 Correct 9 ms 1308 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 14 ms 2004 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 19 ms 2664 KB Output is correct
24 Correct 29 ms 4072 KB Output is correct
25 Correct 42 ms 4400 KB Output is correct
26 Correct 15 ms 2296 KB Output is correct
27 Correct 11 ms 1656 KB Output is correct
28 Correct 8 ms 1228 KB Output is correct
29 Correct 33 ms 4668 KB Output is correct
30 Correct 33 ms 4672 KB Output is correct
31 Correct 33 ms 4664 KB Output is correct
32 Correct 33 ms 4404 KB Output is correct
33 Correct 16 ms 2176 KB Output is correct
34 Correct 8 ms 1228 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -