P7606 [THUPC2021] 混乱邪恶 - Solution
做一个坐标变换。具体的,将原空间映射到平面直角坐标系上,六个方向分别代表:
具体构造你可以想象钦定网格中的一个平行四边形,将它“旋转”为一个矩形。
显然的设
枚举六个方向转移即可。
注意到这是一个只有 0/1 状态的背包,显然可以 bitset 优化掉最后一维,同时空间上滚动数组。空间复杂度
时间复杂度
idea 加入的顺序并不影响我们的答案,因此可以考虑将 idea 打乱,在二维平面上随机走 long long 存下,因此可以直接用 long long,但是实际上效率几乎一样,这里假设压成一个二进制数)
时间复杂度
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long int ll;
using pll = pair<ll, ll>;
using uint = unsigned int;
const int maxn = 1e6 + 10;
constexpr ll mod = 998244353;
const ll inf = 114514191981052013LL;
mt19937 rd(mod);
ll a[maxn][13], L, G; int n, p;
bitset<40> f[2][105][105][40];
inline int r(int x, int y) { return x >= y ? x - y : x - y + p; }
int main() {
scanf("%d%d", &n, &p);
int s = ceil(sqrt(n)) + 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 12; j++) scanf("%lld", &a[i][j]);
}
scanf("%lld%lld", &L, &G);
shuffle(a + 1, a + n + 1, rd); int c = 0;
f[0][0][0][s][s] = 1;
for (int i = 1; i <= n; i++) {
for (int l = 0; l < p; l++) {
for (int g = 0; g < p; g++) {
for (int x = 0; x <= (s << 1); x++) {
bitset<40>& d = f[c ^ 1][l][g][x]; d.reset();
d |= f[c][r(l, a[i][1])][r(g, a[i][2])][x] << 1;
d |= f[c][r(l, a[i][3])][r(g, a[i][4])][x + 1];
d |= f[c][r(l, a[i][5])][r(g, a[i][6])][x + 1] >> 1;
d |= f[c][r(l, a[i][7])][r(g, a[i][8])][x] >> 1;
if (x >= 1) d |= f[c][r(l, a[i][9])][r(g, a[i][10])][x - 1];
if (x >= 1) d |= f[c][r(l, a[i][11])][r(g, a[i][12])][x - 1] << 1;
}
}
}
c ^= 1;
}
puts(f[c][L][G][s][s] ? "Chaotic Evil" : "Not a true problem setter");
return 0;
}