QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56293 | #4376. Dragon slayer | qinjianbin# | AC ✓ | 64ms | 37416kb | C++11 | 2.0kb | 2022-10-18 14:57:09 | 2022-10-18 14:57:10 |
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;
//printf("## %d %d %d\n", x, y, u.state);
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);
y2--;
if(x1 > 0)
_for(j, y1, y2)
{
ban[x1 - 1][j][x1][j] = i - 1;
ban[x1][j][x1 - 1][j] = i - 1;
//printf("!! %d %d %d %d\n", x1 - 1, j, x1, j);
}
}
else
{
if(x1 > x2) swap(x1, x2);
x2--;
if(y1 > 0)
_for(j, x1, x2)
{
ban[j][y1 - 1][j][y1] = i - 1;
ban[j][y1][j][y1 - 1] = i - 1;
//printf("!! %d %d %d %d\n", j, y1 - 1, j, y1);
}
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 64ms
memory: 37416kb
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 5 3 5 1 4 1 0
result:
ok 10 lines