比赛 |
2025暑期集训第7场 |
评测结果 |
W |
题目名称 |
天气预报 |
最终得分 |
0 |
用户昵称 |
LikableP |
运行时间 |
0.007 s |
代码语言 |
C++ |
内存使用 |
1.72 MiB |
提交时间 |
2025-08-11 17:24:46 |
显示代码纯文本
#include <cstdio>
int n;
int target[366][110];
int dx[] = {0, -1, 0, 1, 0, -2, 0, 2, 0};
int dy[] = {0, 0, 1, 0, -1, 0, 2, 0, -2};
bool f(int x, int y) {
return 3 * (x - 1) + y;
}
bool check(__int128 x) {
for (int i = 1; i <= 16; ++i) {
if ((x >> i * 3 & 7) == 7) return false;
}
return true;
}
void write(__int128 x) {
printf("<write>\n");
for (int i = 127; i >= 0; --i) {
putchar((x >> i & 1) ^ 48);
}
putchar('\n');
}
__int128 anc(__int128 status, int x, int y) {
__int128 add = 0;
for (int i = 1; i <= 16; ++i) {
if (i == f(x, y) || i == f(x, y + 1) || i == f(x + 1, y) || i == f(x + 1, y + 1)) continue;
add |= 1 << (i * 3);
}
return status + add;
}
__int128 dec(__int128 status, int x, int y) {
__int128 minus = 0;
for (int i = 1; i <= 16; ++i) {
if (status >> i * 3 & 7) {
minus |= 1 << i * 3;
}
}
return status - minus;
}
bool dfs(int day, int x, int y, __int128 status) {
if (day > n) {
return true;
}
if (target[day][f(x, y)] == 1 || target[day][f(x + 1, y)] || target[day][f(x, y + 1)] || target[day][f(x + 1, y + 1)]) return false;
if (!check(status)) return false;
__int128 sta = dec(status, x, y);
for (int i = 1; i <= 8; ++i) {
int cx = x + dx[i], cy = y + dy[i];
if (cx < 1 || cx > 3 || cy < 1 || cy > 3) continue;
if (dfs(day + 1, cx, cy, anc(sta, x, y))) return true;
}
return false;
}
int main() {
freopen("weather_forecast.in", "r", stdin);
freopen("weather_forecast.out", "w", stdout);
while (scanf("%d", &n)) {
if (!n) break;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 16; ++j) {
scanf("%d", &target[i][j]);
}
}
if (dfs(1, 2, 2, 0)) {
puts("1");
} else {
puts("0");
}
}
return 0;
}