QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56291 | #4376. Dragon slayer | qinjianbin# | WA | 211ms | 37744kb | C++11 | 1.7kb | 2022-10-18 14:34:21 | 2022-10-18 14:34:22 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
const int N = 20;
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int ban[N][N][N][N], n, m, k;
int xs, ys, xt, yt;
int vis[N][N][1 << 15];
struct node
{
int x, y, state;
};
void bfs()
{
_for(i, 0, n)
_for(j, 0, m)
rep(S, 0, 1 << k)
vis[i][j][S] = 0;
queue<node> q;
q.push({xs, ys, 0});
vis[xs][ys][0] = 1;
while(!q.empty())
{
node u = q.front(); q.pop();
int x = u.x, y = u.y;
rep(i, 0, 4)
{
int xx = x + dir[i][0], yy = y + dir[i][1];
if(xx < 0 || xx > n || yy < 0 || yy > m) continue;
int state = u.state;
if(ban[x][y][xx][yy] != -1)
{
int cur = ban[x][y][xx][yy];
if(!((state >> cur) & 1)) state |= 1 << cur;
}
if(!vis[xx][yy][state])
{
q.push({xx, yy, state});
vis[xx][yy][state] = 1;
}
}
}
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d%d%d", &n, &m, &k);
scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
memset(ban, -1, sizeof ban);
_for(i, 1, k)
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if(x1 == x2)
{
if(y1 > y2) swap(y1, y2);
if(x1 > 0)
_for(j, y1, y2) ban[x1 - 1][j][x1][j] = i - 1;
}
else
{
if(x1 > x2) swap(x1, x2);
if(y1 > 0)
_for(j, x1, x2) ban[j][y1 - 1][j][y1] = i - 1;
}
}
bfs();
int ans = 1e9;
rep(S, 0, 1 << k)
if(vis[xt][yt][S])
{
int cnt = 0;
rep(i, 0, k)
if((S >> i) & 1)
cnt++;
ans = min(ans, cnt);
}
printf("%d\n", ans);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 211ms
memory: 37744kb
input:
10 4 4 4 0 2 3 3 0 2 4 2 1 3 1 0 2 4 2 1 3 1 3 4 3 2 2 0 0 2 1 0 1 3 1 1 0 1 2 3 2 2 0 0 2 1 2 1 2 2 1 0 1 1 15 15 15 3 12 4 1 8 0 8 15 1 11 15 11 1 1 1 15 3 1 3 15 0 10 14 10 14 1 14 14 8 1 8 15 1 5 14 5 0 15 14 15 0 4 14 4 0 2 15 2 11 0 11 15 4 1 4 15 1 11 15 11 1 12 14 12 15 15 15 8 5 14 0 0 12 1...
output:
1 2 0 0 3 6 1 1 0 0
result:
wrong answer 4th lines differ - expected: '5', found: '0'