记录编号 571435 评测结果 AAAAAAAA
题目名称 魔板 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.016 s
提交时间 2022-05-23 20:19:29 内存使用 1.83 MiB
显示代码纯文本
#include <bits/stdc++.h>

using i32 = unsigned int;
using i64 = long long;
using PIS = std::pair<i32, std::string>;

const i32 bg = 0x12348765;

i32 A(i32 x) { return x << 16 | x >> 16; }
i32 B(i32 x) { return (x & 0xFFF0FFF0) >> 4 | (x & 0x000F000F) << 12; }
i32 C(i32 x) {
	i32 ret = x & 0xF00FF00F;
	ret |= (x & 0x0F000000) >>  4 | (x & 0x000000F0) <<  4;
	ret |= (x & 0x00F00000) >> 16 | (x & 0x00000F00) << 16;
	return ret;
}

i32 n;
std::unordered_map<i32, bool> st;
char op[] = "0ABC";

void bfs() {
	std::queue<PIS> q;
	q.push(std::make_pair(bg, ""));
	while (q.size()) {
		auto t = q.front(); q.pop();
		auto x = t.first;
		auto y = t.second;
		if (x == n) {
			std::cout << y.size() << '\n' << y << '\n';
			return;
		}
		i32 a = A(x); if (!st[a]) q.push(std::make_pair(a, y + op[1])), st[a] = true;
		i32 b = B(x); if (!st[b]) q.push(std::make_pair(b, y + op[2])), st[b] = true;
		i32 c = C(x); if (!st[c]) q.push(std::make_pair(c, y + op[3])), st[c] = true;
	}
}

int main() {
	freopen("msquare.in", "r", stdin); 
	freopen("msquare.out", "w", stdout);
	i32 a[10];
	for (int i = 1; i <= 8; ++ i) std::cin >> a[i];
	for (int i = 1; i <= 4; ++ i) n = n << 4 | a[i];
	for (int i = 8; i >= 5; -- i) n = n << 4 | a[i];
	bfs();
	return 0;
}