QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471237#5416. Fabulous Fungus FrenzyqLWA 2ms4088kbC++233.4kb2024-07-10 19:50:452024-07-10 19:50:47

Judging History

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

  • [2024-07-10 19:50:47]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4088kb
  • [2024-07-10 19:50:45]
  • 提交

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 = i; 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)) {
							ox = x, oy = y;
							break;
						}
				for (i32 x = i; x < n[0] && !~ox; ++x)
					for (i32 y = 0; y < m[0]; ++y)
						if (mat[x][y] == '*' && !(x == i && y < j)) {
							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: 0ms
memory: 3768kb

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: 0ms
memory: 3760kb

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

score: 0
Accepted
time: 0ms
memory: 3752kb

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:

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

result:

ok puzzle solved

Test #4:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

2 2 1
OO
OO

OP
PP

1 2
PP

output:

8
-2 1 2
-4 2 2
1 1 1
-4 2 1
1 1 1
-4 2 2
-1 2 1
-2 1 2

result:

ok puzzle solved

Test #5:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

2 2 1
OO
OO

OP
PO

2 1
P
P

output:

4
-4 2 2
-2 1 2
1 1 1
-2 1 2

result:

ok puzzle solved

Test #6:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

2 2 1
OO
OO

OP
PO

2 2
PP
PP

output:

-1

result:

ok puzzle solved

Test #7:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

2 2 1
OO
OO

OP
PP

1 2
OP

output:

7
1 1 1
-4 2 2
-1 2 1
1 1 1
-4 2 2
-1 2 1
1 1 1

result:

ok puzzle solved

Test #8:

score: 0
Accepted
time: 2ms
memory: 4088kb

input:

20 20 20
bofelagiqboebdqplbhq
qsrksfthhptcmikjohkt
qrnhpoatbekggnkdonet
aoalekbmpbisgflbhmol
djnhnlitcakltqgegqrt
fdctfarsmbnbeosdgilo
ttrsljgiratfmioajorh
gorljkihdnmnofnblfhm
bqjkaehetdjlgctmijpc
geslcskpoqjcgtbdspoa
riqthroqmmhqgprqhsba
fdiarrcomockfqdjjdkd
jsbnigfqgsfekbbnnkir
ildqctqtqrpcetaocp...

output:

9798
20 1 1
-2 1 2
-2 1 3
-2 1 4
-2 1 5
-2 1 6
-2 1 7
-2 1 8
-2 1 9
-2 1 10
-2 1 11
-2 1 12
-2 1 13
-2 1 14
-2 1 15
-2 1 16
-2 1 17
-2 1 18
-2 1 19
-4 2 19
-4 3 19
-4 4 19
-4 5 19
-4 6 19
-4 7 19
-4 8 19
-4 9 19
-4 10 19
-4 11 19
-4 12 19
-4 13 19
-4 14 19
-4 15 19
-4 16 19
-4 17 19
-4 18 19
-4 19 1...

result:

ok puzzle solved

Test #9:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

20 20 2
HbevPluVL5ORtUFcV9gf
Mrq6zdTPMPnwlN7Fpzx6
Nfp71dVuxTZp9Qet0Ca9
ugbaF34DquDdbUnk5x7V
fDFszn4PmvMpJ5BDWueJ
2YvFxKJgst8XbftPfy9T
F7Q4huk87Lrp1M7i08is
Q41E5AqLkkP3Q5qONXC2
MuM7iIzev3ZpxItvriQK
6OBdEC0sso5vdNQlrCSR
BJQtKjN6RmppsMGIYL81
yyKsWJSoKorGGblNle0r
RkKEQACh8f0bS5nPTtJH
fQgoc39vdsPAUmxlYYL...

output:

-1

result:

ok puzzle solved

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3844kb

input:

20 20 2
pqo3Mcpvo74RFSsJszsa
znrYm92Qr8fbqhbCTOgq
4KiMYr0kLAxPGNG15x7L
QHKmq6xaJ4PU4msuRAiv
UBfS6VUO87hRnMAjGXKX
zCgknw3FfhdifmVcT6FF
GH6ohIAzZuprlC3vMDVh
mHIJ9KlQvWxt6EgGbJkA
3SwJNhRSdEeF9BNtc9k2
mZmEuriH7Rc4ccMjqI0Y
cFfI8TC1iM4PkKziLOiN
15CUjuwudnrums3c3dsl
ekL52LiFEpzmU4vaGtuX
CfrnQtWb5zAN9oQS2fj...

output:


result:

wrong output format Unexpected end of file - int32 expected