#include<bits/stdc++.h>
#define int long long
#define down(x) (1ll<<(2*(x)))
#define right(x) (1ll<<(2*(x)+1))
using namespace std;
const int SIZE = 3e5, MOD = 299987;
int f[2][SIZE][5], tot[2], d, st[2][SIZE], ans;
struct Hash {
int nxt[SIZE], head[MOD + 50];
inline void insert(int x, int s, int p) {
int id = x % MOD + 1;
for (int i = head[id]; i; i = nxt[i]) {
if (st[d][i] == x) {
f[d][i][p] += s;
printf("f[%lld][%lld][%lld]=%lld st=%lld\n", d, i, p, f[d][i][p], st[d][i]);
return ;
}
}
nxt[++tot[d]] = head[id];
head[id] = tot[d];
st[d][tot[d]] = x;
f[d][tot[d]][p] = s;
printf("f[%lld][%lld][%lld]=%lld st=%lld\n", d, tot[d], p, f[d][tot[d]][p], st[d][tot[d]]);
}
inline void clear() {
tot[d] = 0;
memset(head, 0, sizeof head);
}
} h;
char c[40];
int a[40][40], ex, ey;
signed main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> c + 1;
for (int j = 1; j <= m; j++) {
if (c[j] == '#')a[i][j] = 1;
else {
a[i][j] = 0;
ex = i;
ey = j;
}
}
}
h.insert(0, 1, 0);
for (int i = 1; i <= n; i++) {
// for(int j=1;j<=tot[d];j++)st[d][j]<<=2;
for (int j = 1; j <= m; j++) {
puts("------------------------------------------");
printf("i=%d,j=%d\n", i, j);
d ^= 1;
h.clear();
memset(f[d], 0, sizeof f[d]);
for (int k = 1; k <= tot[d ^ 1]; k++) {
int nst = st[d ^ 1][k], R = nst & right(j - 1), D = nst & down(j);
for (int l = 0; l <= 3; l++) {
int s = f[d ^ 1][k][l];
printf("s=f[%lld][%lld][%lld]=%lld,st=%lld\n", d ^ 1, k, l, s, nst);
int t = nst;
if (t & right(j))t -= right(j);
if (t & down(j))t -= down(j);
if (a[i][j] == 1) {
if (!D)h.insert(t, s, l);
} else if (!R && !D) {
h.insert(t, s, l);
h.insert(t + down(j), s, l + 1);
if (l == 3 && i == ex && j == ey) {
ans += s;
puts("!!!");
// system("pause");
}
} else if (!R && D) {
h.insert(t + down(j), s, l);
h.insert(t + right(j), s, l);
} else if (R && !D) {
h.insert(t + right(j), s, l);
h.insert(t + down(j), s, l);
h.insert(t, s, l);
/*if (l == 3 && i == ex && j == ey) {
ans += s;
puts("!!!");
// system("pause");
}*/
}
}
}
}
}
cout << ans;
system("pause");
return 0;
}
本题是在Windows下调试,这是带有调试信息的代码。
#include<bits/stdc++.h>
#define int long long
#define down(x) (1ll<<(2*(x)))
#define right(x) (1ll<<(2*(x)+1))
using namespace std;
const int SIZE = 3e5, MOD = 299987;
int f[2][SIZE][5], tot[2], d, st[2][SIZE], ans;
struct Hash {
int nxt[SIZE], head[MOD + 50];
inline void insert(int x, int s, int p) {
int id = x % MOD + 1;
for (int i = head[id]; i; i = nxt[i]) {
if (st[d][i] == x) {
f[d][i][p] += s;
return ;
}
}
nxt[++tot[d]] = head[id];
head[id] = tot[d];
st[d][tot[d]] = x;
f[d][tot[d]][p] = s;
}
inline void clear() {
tot[d] = 0;
memset(head, 0, sizeof head);
}
} h;
char c[40];
int a[40][40], ex, ey;
signed main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> c + 1;
for (int j = 1; j <= m; j++) {
if (c[j] == '#')a[i][j] = 1;
else {
a[i][j] = 0;
ex = i;
ey = j;
}
}
}
h.insert(0, 1, 0);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
d ^= 1;
h.clear();
memset(f[d], 0, sizeof f[d]);
for (int k = 1; k <= tot[d ^ 1]; k++) {
int nst = st[d ^ 1][k], R = nst & right(j - 1), D = nst & down(j);
for (int l = 0; l <= 3; l++) {
int s = f[d ^ 1][k][l];
int t = nst;
if (t & right(j))t -= right(j);
if (t & down(j))t -= down(j);
if (a[i][j] == 1) {
if (!D)h.insert(t, s, l);
} else if (!R && !D) {
h.insert(t, s, l);
h.insert(t + down(j), s, l + 1);
if (l == 3 && i == ex && j == ey) {
ans += s;
}
} else if (!R && D) {
h.insert(t + down(j), s, l);
h.insert(t + right(j), s, l);
} else if (R && !D) {
h.insert(t + right(j), s, l);
h.insert(t + down(j), s, l);
h.insert(t, s, l);
if (l == 3 && i == ex && j == ey) {
ans += s;
}
}
}
}
}
}
cout << ans;
return 0;
}
这是删除调试信息的代码。
感激不尽。
样例没过,输出总是非常大。