QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724583 | #4376. Dragon slayer | XfJbUhpyzgaW# | AC ✓ | 5ms | 3884kb | C++14 | 2.0kb | 2024-11-08 13:54:47 | 2024-11-08 13:54:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct wall{int x1,y1,x2,y2;}w[20];
int T,n,m,k;
int mp[20][20][2]; // 0 up 1 right
int sx,sy,tx,ty;
int vis[20][20],dx[410],dy[410];
inline bool bound(int x,int y){return 0<=x && x<n && 0<=y && y<m;}
bool check(int s){
for (int i=0;i<=n;++i)
for (int j=0;j<=m;++j)
mp[i][j][0]=mp[i][j][1]=0;
for (int i=1;i<=k;++i)
if (!(s&(1<<i-1))){
if (w[i].x1==w[i].x2)
for (int j=w[i].y1;j<w[i].y2;++j) mp[w[i].x1][j][0]=1;
else
for (int j=w[i].x1;j<w[i].x2;++j) mp[j][w[i].y1][1]=1;
}
for (int i=0;i<n;++i)
for (int j=0;j<m;++j)
vis[i][j]=0;
int t=1,w=1;
vis[sx][sy]=1,dx[1]=sx,dy[1]=sy;
while (t<=w){
int x=dx[t],y=dy[t];++t;
if (bound(x-1,y) && !mp[x][y][0] && !vis[x-1][y]){vis[x-1][y]=1;++w;dx[w]=x-1;dy[w]=y;}
if (bound(x+1,y) && !mp[x+1][y][0] && !vis[x+1][y]){vis[x+1][y]=1;++w;dx[w]=x+1;dy[w]=y;}
if (bound(x,y-1) && !mp[x][y][1] && !vis[x][y-1]){vis[x][y-1]=1;++w;dx[w]=x;dy[w]=y-1;}
if (bound(x,y+1) && !mp[x][y+1][1] && !vis[x][y+1]){vis[x][y+1]=1;++w;dx[w]=x;dy[w]=y+1;}
}
return vis[tx][ty]==1;
}
int main(){
// freopen("a.in","r",stdin);
for (scanf("%d",&T);T;--T){
scanf("%d%d%d",&n,&m,&k);
scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
for (int i=1;i<=k;++i){
scanf("%d%d%d%d",&w[i].x1,&w[i].y1,&w[i].x2,&w[i].y2);
if (w[i].x1>w[i].x2) swap(w[i].x1,w[i].x2);
if (w[i].y1>w[i].y2) swap(w[i].y1,w[i].y2);
}
int ans=-1;
for (int c=0;c<=k;++c){
for (int s=0;s<(1<<k);++s)
if (__builtin_popcount(s)==c)
if (check(s)){
ans=c;
break;
}
if (ans==c) break;
}
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 3884kb
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