QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74564#4376. Dragon slayerchenjunliangAC ✓3ms4112kbC++141.1kb2023-02-02 16:34:102023-02-02 16:34:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-02 16:34:12]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:4112kb
  • [2023-02-02 16:34:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T,n,m,k,x,y,x2,y2,a[20][20][20][20],g[20][20][20],f[20][20],s[20];
int xi[4]={0,0,1,-1},yi[4]={1,-1,0,0};
void dfs(int xx,int yy,int z,int w){
	if(f[xx][yy]<z)return ;
	if(g[xx][yy][z]<=w)return ;
	f[xx][yy]=z;
	g[xx][yy][z]=w;
	for(int i=0;i<4;i++){
		int xa=xx+xi[i],ya=yy+yi[i];
		if(xa<0||xa>n-1||ya<0||ya>m-1)continue;
		if(s[a[xx][yy][xa][ya]]){
			s[a[xx][yy][xa][ya]]=0;
			dfs(xa,ya,z+1,w+1);
			s[a[xx][yy][xa][ya]]=1;
		}
		else dfs(xa,ya,z,w+1);
	}
}
int main(){
	cin>>T;
	while(T--){
		memset(f,10000,sizeof(f));
		memset(g,10000,sizeof(g));
		memset(a,0,sizeof(a));
		memset(s,0,sizeof(s));
		cin>>n>>m>>k;
		cin>>x>>y>>x2>>y2;
		for(int i=1,b,c,d,e;i<=k;i++){
			s[i]=1;
			cin>>b>>c>>d>>e;
			int l,r,v;
			if(b==d) l=c,r=e,v=1;
			else l=b,r=d,v=2;
			if(l>r)swap(l,r);
			for(int j=l;j<r;j++){
				if(v==1){
					a[b-1][j][d][j]=i;
					a[d][j][b-1][j]=i;
				}
				else {
					a[j][c-1][j][e]=i;
					a[j][e][j][c-1]=i;
				}
			}
		}
		dfs(x,y,0,0);
		cout<<f[x2][y2]<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 4112kb

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