Submission #64520226


Source Code Expand

#include<bits/stdc++.h>
#define int long long
#define FastIO
#ifdef FastIO
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin)),*p2=0,*p1++)
#endif //#ifdef FastIO
using namespace std;int n,m,k;
namespace IO{char buf[8888888],*p1=buf,*p2=buf,ibuf;
int rd(int x=0,int f=1){for(;!isdigit(ibuf);ibuf=getchar())ibuf=='-'&&(f=-1);for(;isdigit(ibuf);ibuf=getchar())x=(x<<1)+(x<<3)+(ibuf^48);return x*f;}
int rds(char*s,int n=0){for(;!isgraph(ibuf);ibuf=getchar());for(;isgraph(ibuf);ibuf=getchar())s[n++]=ibuf;return s[n]=0,n;}
}using IO::rd;using IO::rds;//namespace IO
#define fio(s) (freopen(s".in","r",stdin),freopen(s".out","w",stdout))

int a[1000100];
char s[1010][1010];
int d[1010][1010];
int dx[8]={-1,0,1,0,-2,0,2,0};
int dy[8]={0,-1,0,1,0,-2,0,2};
bool vis[1010][1010];

signed main(){int Tst=1;
//Tst=rd();
while(Tst--){

	n=rd();m=rd();n+=2,m+=2;
	for(int i=2;i<n;i++)rds(s[i]+2);
	int a=rd()+1,b=rd()+1,c=rd()+1,D=rd()+1;
	memset(d,-1,sizeof(d));
	deque<int>Q;Q.push_back(a<<32|b);
	d[a][b]=0;
	while(!Q.empty())
	{
		int x=Q.front()>>32,y=signed(Q.front());Q.pop_front();
		if(vis[x][y])continue;
		vis[x][y]=1;
		for(int k=0;k<4;k++)
		{
			int xx=x+dx[k],yy=y+dy[k];
			if(xx<2||yy<2||xx>=n||yy>=m)continue;
			if(s[xx][yy]=='#')continue;
			if(~d[xx][yy])if(d[xx][yy]<=d[x][y])continue;
			d[xx][yy]=d[x][y],Q.push_front(xx<<32|yy);
		}
		for(int k=0;k<8;k++)
		{
			int xx=x+dx[k],yy=y+dy[k];
			if(xx<2||yy<2||xx>=n||yy>=m)continue;
			if(~d[xx][yy])continue;
			d[xx][yy]=d[x][y]+1,Q.push_back(xx<<32|yy);
		}
	}
	cout<<d[c][D]<<endl;

//newline!
}return 0;}

Submission Info

Submission Time
Task D - Takahashi the Wall Breaker
User while_1
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1643 Byte
Status AC
Exec Time 68 ms
Memory 22588 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 34
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 4 ms 11508 KiB
example_01.txt AC 4 ms 11372 KiB
example_02.txt AC 4 ms 11380 KiB
example_03.txt AC 4 ms 11532 KiB
hand_00.txt AC 36 ms 14516 KiB
hand_01.txt AC 40 ms 14540 KiB
hand_02.txt AC 40 ms 14520 KiB
hand_03.txt AC 36 ms 14516 KiB
hand_04.txt AC 35 ms 14432 KiB
hand_05.txt AC 34 ms 18552 KiB
hand_06.txt AC 33 ms 18548 KiB
hand_07.txt AC 36 ms 22588 KiB
hand_08.txt AC 37 ms 22480 KiB
hand_09.txt AC 4 ms 11460 KiB
random_00.txt AC 33 ms 14400 KiB
random_01.txt AC 34 ms 14300 KiB
random_02.txt AC 44 ms 14428 KiB
random_03.txt AC 42 ms 14388 KiB
random_04.txt AC 35 ms 14236 KiB
random_05.txt AC 34 ms 14216 KiB
random_06.txt AC 66 ms 20100 KiB
random_07.txt AC 63 ms 20372 KiB
random_08.txt AC 56 ms 21932 KiB
random_09.txt AC 65 ms 19764 KiB
random_10.txt AC 58 ms 20156 KiB
random_11.txt AC 68 ms 19944 KiB
random_12.txt AC 60 ms 14408 KiB
random_13.txt AC 66 ms 14352 KiB
random_14.txt AC 52 ms 14312 KiB
random_15.txt AC 57 ms 14396 KiB
random_16.txt AC 64 ms 14404 KiB
random_17.txt AC 36 ms 14304 KiB
random_18.txt AC 39 ms 14320 KiB
random_19.txt AC 36 ms 14308 KiB