QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211556 | #4376. Dragon slayer | ucup-team1001 | WA | 0ms | 3572kb | C++14 | 2.0kb | 2023-10-12 18:22:47 | 2023-10-12 18:22:47 |
Judging History
answer
#include <bits/stdc++.h>
const int maxn=20;
bool vis[maxn][maxn][maxn];
std::vector<int> xx1[maxn],xx2[maxn];
std::vector<int> yy1[maxn],yy2[maxn];
struct node
{
int x,y,dis;
bool operator<(node nod)const
{
return dis>nod.dis;
}
};
int bfs(int xs,int ys,int xt,int yt,int n,int m)
{
std::priority_queue<node> q;
int cnt=0;
q.push((node){xs,ys});
while(!q.empty()){
node nod=q.top();
q.pop();
int x=nod.x,y=nod.y,dis=nod.dis;
if(x==xt&&y==yt)
return dis;
if(vis[x][y][dis])
continue;
vis[x][y][dis]=1;
//std::cout<<x<<' '<<y<<' '<<dis<<std::endl;
int cnt=0;
if(x-1>=0){
for(int j=0;j<xx1[x].size();j++){
int y1=xx1[x][j],y2=xx2[x][j];
if(y1<=y&&y<y2)
cnt++;
}
q.push((node){x-1,y,dis+cnt});
}
cnt=0;
if(x+1<n){
for(int j=0;j<xx1[x+1].size();j++){
int y1=xx1[x+1][j],y2=xx2[x+1][j];
if(y1<=y&&y<y2)
cnt++;
}
q.push((node){x+1,y,dis+cnt});
}
cnt=0;
if(y-1>=0){
for(int j=0;j<yy1[y].size();j++){
int x1=yy1[y][j],x2=yy2[y][j];
if(x1<=x&&x<x2)
cnt++;
}
q.push((node){x,y-1,dis+cnt});
}
cnt=0;
if(y+1<m){
for(int j=0;j<yy1[y+1].size();j++){
int x1=yy1[y+1][j],x2=yy2[y+1][j];
if(x1<=x&&x<x2)
cnt++;
}
q.push((node){x,y+1,dis+cnt});
}
}
return -1;
}
void solve()
{
memset(vis,0,sizeof(vis));
for(int i=0;i<maxn;i++){
xx1[i].clear();
xx2[i].clear();
yy1[i].clear();
yy2[i].clear();
}
int n,m,k;
std::cin>>n>>m>>k;
int xs,ys,xt,yt;
std::cin>>xs>>ys>>xt>>yt;
for(int i=0;i<k;i++)
{
int x1,x2,y1,y2;
std::cin>>x1>>y1>>x2>>y2;
if(x1==x2){
if(y1>y2)
std::swap(y1,y2);
xx1[x1].push_back(y1);
xx2[x1].push_back(y2);
}
if(y1==y2){
if(x1>x2)
std::swap(x1,x2);
yy1[y1].push_back(x1);
yy2[y1].push_back(x2);
}
}
std::cout<<bfs(xs,ys,xt,yt,n,m)<<std::endl;
}
int main()
{
int t;
std::cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3572kb
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:
2 2 0 5 3 6 1 4 1 0
result:
wrong answer 1st lines differ - expected: '1', found: '2'