Submission #64556749


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e3+10,M=1e9;
int h,w,xc,yc,xz,yz;
char a[N][N];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int dis[N][N];
struct node
{
int x,y;
};
deque<node>q;
void bfs()
{
while(!q.empty())
{
int x=q.front().x,y=q.front().y;
q.pop_front();
for(int i=0;i<4;i++)
{
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e3+10,M=1e9;
int h,w,xc,yc,xz,yz;
char a[N][N];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int dis[N][N];
struct node
{
	int x,y;
};
deque<node>q;
void bfs()
{
	while(!q.empty())
	{
		int x=q.front().x,y=q.front().y;
		q.pop_front();
		for(int i=0;i<4;i++)
		{
			int xnew=x+dx[i],ynew=y+dy[i];
			if(xnew<1||xnew>h||ynew<1||ynew>w||a[xnew][ynew]=='#'||dis[xnew][ynew]<=dis[x][y]) 
			{
				continue;
			}
			q.push_front({xnew,ynew});
			dis[xnew][ynew]=dis[x][y];
		}
		for(int i=x-2;i<=x+2;i++)
		{
			int xnew=i,ynew=y;
			if(xnew<1||xnew>h||ynew<1||ynew>w||dis[xnew][ynew]<=dis[x][y]) 
			{
				continue;
			}
			q.push_back({xnew,ynew});
			dis[xnew][ynew]=dis[x][y]+1;
		}
		for(int i=y-2;i<=y+2;i++)
		{
			int xnew=x,ynew=i;
			if(xnew<1||xnew>h||ynew<1||ynew>w||dis[xnew][ynew]<=dis[x][y]) 
			{
				continue;
			}
			q.push_back({xnew,ynew});
			dis[xnew][ynew]=dis[x][y]+1;
		}
	}
}
signed main()
{
	cin>>h>>w;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>a[i][j];
		}
	}
	cin>>xc>>yc>>xz>>yz;
	memset(dis,0x3f,sizeof(dis));
	q.push_front({xc,yc});
	dis[xc][yc]=0;
	bfs();
	cout<<dis[xz][yz];
	return 0;
}

Submission Info

Submission Time
Task D - Takahashi the Wall Breaker
User A86562U
Language C++ 20 (gcc 12.2)
Score 0
Code Size 1278 Byte
Status TLE
Exec Time 2287 ms
Memory 1353952 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 22
TLE × 12
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 5 ms 11448 KB
example_01.txt AC 5 ms 11432 KB
example_02.txt AC 4 ms 11616 KB
example_03.txt AC 5 ms 11428 KB
hand_00.txt TLE 2287 ms 1350696 KB
hand_01.txt TLE 2210 ms 60848 KB
hand_02.txt TLE 2212 ms 95892 KB
hand_03.txt TLE 2277 ms 1275032 KB
hand_04.txt TLE 2211 ms 66528 KB
hand_05.txt TLE 2285 ms 1352388 KB
hand_06.txt TLE 2286 ms 1343344 KB
hand_07.txt AC 151 ms 44976 KB
hand_08.txt AC 112 ms 36704 KB
hand_09.txt AC 4 ms 11432 KB
random_00.txt AC 243 ms 12788 KB
random_01.txt AC 205 ms 12796 KB
random_02.txt AC 870 ms 14316 KB
random_03.txt AC 1107 ms 15896 KB
random_04.txt TLE 2287 ms 1348400 KB
random_05.txt TLE 2283 ms 1353952 KB
random_06.txt AC 246 ms 47724 KB
random_07.txt AC 241 ms 47356 KB
random_08.txt AC 192 ms 40656 KB
random_09.txt AC 243 ms 46532 KB
random_10.txt AC 221 ms 44800 KB
random_11.txt AC 245 ms 44944 KB
random_12.txt AC 404 ms 13136 KB
random_13.txt AC 294 ms 13108 KB
random_14.txt AC 505 ms 13532 KB
random_15.txt AC 427 ms 13312 KB
random_16.txt AC 286 ms 13236 KB
random_17.txt TLE 2277 ms 1205160 KB
random_18.txt TLE 2273 ms 1139264 KB
random_19.txt TLE 2282 ms 1336916 KB


2025-04-11 (Fri)
11:54:14 +00:00