QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471243#5416. Fabulous Fungus FrenzyqLWA 1ms3800kbC++233.5kb2024-07-10 19:56:152024-07-10 19:56:15

Judging History

你现在查看的是最新测评结果

  • [2024-07-10 19:56:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3800kb
  • [2024-07-10 19:56:15]
  • 提交

answer

#include <algorithm>
#include <cstdio>
#include <tuple>
using i32 = int;
constexpr i32 N = 20;
char model[N + 1][N + 5][N + 5], mat[N + 5][N + 5];
i32 cnt[128], need[N + 1][128];
i32 n[N + 1], m[N + 1], K;
std::tuple<i32, i32, i32> opts[N * N * N * 25 * 2], *opt = opts - 1;
void work(i32 t, i32 x, i32 y) noexcept {
	*++opt = std::make_tuple(t, x, y);
	// fprintf(stderr, "%d %d %d\n", t, x, y);
	if (t > 0)
		for (i32 i = 0; i < n[t]; ++i)
			for (i32 j = 0; j < m[t]; ++j) --cnt[mat[i][j]], ++cnt[mat[i][j] = '*'];
	else
		switch (t) {
		case -4:
			std::swap(mat[x][y], mat[x - 1][y]);
			break;
		case -3:
			std::swap(mat[x][y], mat[x + 1][y]);
			break;
		case -2:
			std::swap(mat[x][y], mat[x][y - 1]);
			break;
		case -1:
			std::swap(mat[x][y], mat[x][y + 1]);
			break;
		case 0:
			std::swap(mat[x][y], mat[x + 1][y]);
			std::swap(mat[x][y + 1], mat[x + 1][y + 1]);
			std::swap(mat[x + 1][y], mat[x][y + 1]);
			break;
		}
}
void move(i32 x1, i32 y1, i32 x2, i32 y2) noexcept {
	while (y1 < y2) work(-1, x1, y1), ++y1;
	while (x1 > x2) work(-4, x1, y1), --x1;
	while (y1 > y2) work(-2, x1, y1), --y1;
	while (x1 < x2) work(-3, x1, y1), ++x1;
}
signed main() noexcept {
	scanf("%d%d%d", &n[0], &m[0], &K);
	for (i32 i = 0; i < n[0]; ++i) scanf("%s", model[0][i]);
	for (i32 i = 0; i < n[0]; ++i) scanf("%s", mat[i]);
	for (i32 i = 1; i <= K; ++i) {
		scanf("%d%d", &n[i], &m[i]);
		for (i32 j = 0; j < n[i]; ++j) scanf("%s", model[i][j]);
	}
	for (i32 x = 0; x < n[0]; ++x)
		for (i32 y = 0; y < m[0]; ++y) ++cnt[mat[x][y]];
	for (i32 i = 0; i <= K; ++i)
		for (i32 x = 0; x < n[i]; ++x)
			for (i32 y = 0; y < m[i]; ++y) ++need[i][model[i][x][y]];
	do {
		i32 pos = -1, maxi = 0;
		for (i32 i = 0; i <= K; ++i) {
			i32 rest = cnt['*'];
			for (i32 c = 0; c < 128; ++c)
				if (need[i][c] > cnt[c]) rest -= need[i][c] - cnt[c];
			if (rest >= 0 && n[i] * m[i] - (cnt['*'] - rest) + (i == 0) > maxi)
				pos = i, maxi = i ? n[i] * m[i] - (cnt['*'] - rest) : 0x3f3f3f3f;
		}
		if (!~pos) return puts("-1"), 0;
		// fprintf(stderr, "model: %d\n", pos);
		/*
		 OOO
		 G*G
		 B**
		 */
		for (i32 i = 0; i < n[pos]; ++i)
			for (i32 j = 0; j < m[pos]; ++j) {
				i32 ox = -1, oy = -1;
				for (i32 x = 0; x < n[0] && !~ox; ++x)
					for (i32 y = 0; y < m[0]; ++y)
						if (mat[x][y] == model[pos][i][j] && !(x == i && y < j) && !(x < i && y <= m[pos])) {
							ox = x, oy = y;
							break;
						}
				for (i32 x = 0; x < n[0] && !~ox; ++x)
					for (i32 y = 0; y < m[0]; ++y)
						if (mat[x][y] == '*' && !(x <= i && y < j) && !(x < i && y <= m[pos])) {
							ox = x, oy = y;
							break;
						}
				if (!~ox) {
					// fprintf(stderr, "%d %d %c %c\n", i, j, mat[2][2], model[pos][2][2]);
					exit(0);
				}
				// fprintf(stderr, "%d,%d(%c) -> %d,%d(%c)\n", ox, oy, mat[ox][oy], i, j, mat[i][j]);
				move(ox, oy, i, j);
				// for (i32 i = 0; i < n[0]; ++i) fprintf(stderr, "%s\n", mat[i]);
				// fprintf(stderr, "\n");
			}
		// for (i32 i = 0; i < n[0]; ++i) fprintf(stderr, "%s\n", mat[i]);
		// fprintf(stderr, "\n");
		if (pos == 0) break;
		work(pos, 0, 0);
		// for (i32 i = 0; i < n[0]; ++i) fprintf(stderr, "%s\n", mat[i]);
		// fprintf(stderr, "\n");
	} while (true);
	printf("%zu\n", opt - opts + 1);
	for (; opt >= opts; --opt) printf("%d %d %d\n", std::get<0>(*opt), std::get<1>(*opt) + 1, std::get<2>(*opt) + 1);
	// for (i32 i = 0; i < n[0]; ++i) fprintf(stdout, "%s\n", mat[i]);
	// fprintf(stderr, "\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3800kb

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

13
-2 3 2
-4 3 3
-1 3 2
-2 2 2
-4 2 3
-1 2 2
-2 1 3
-2 1 2
1 1 1
-2 3 2
-2 2 2
-4 2 1
-4 3 1

result:

ok puzzle solved

Test #2:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3764kb

input:

4 8 4
11122222
33344444
55556666
77777777

NIxSHUOx
DExDUIxx
DANxSHIx
YUANSHEN

2 3
NIy
DEx

3 8
zzzzzzzz
DANNSH9I
YUA9SHEN

1 1
x

2 5
SHO8y
DUUI8

output:

129
1 1 1
-2 2 4
-2 2 5
-2 2 6
-2 2 7
-2 2 8
-4 3 8
-4 4 8
-3 1 2
-2 1 3
-2 1 4
-2 1 5
-3 1 1
-2 1 2
-2 1 3
-2 1 4
-2 1 5
1 1 1
-2 2 4
-2 2 5
-2 2 6
-2 2 7
-4 3 7
-4 4 7
-3 1 2
-2 1 3
-2 1 4
-2 1 5
-3 1 1
-2 1 2
-2 1 3
-2 1 4
-2 1 5
1 1 1
-2 2 4
-2 2 5
-2 2 6
-4 3 6
-4 4 6
-3 1 2
-2 1 3
-2 1 4
-2 1 ...

result:

wrong answer puzzle remain unsolved