提出 #71685879


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int cnt=0;
struct z{
	int x,y;
}b[1000005];
bool vis[10005][1005];
int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
int h,w;
int step[1005][1005];
void bfs(int x,int y){
	memset(step,-1,sizeof step);
	queue<pair<int,int> >q;
	q.push({x,y});
	vis[x][y]=true;
	while(!q.empty())
	{
		auto t=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=t.first+dx[i];
			int ny=t.second+dy[i];
			if(nx>=1&&nx<=h&&ny>=1&&ny<=w&&!vis[nx][ny])
			{
				vis[nx][ny]=true;
				step[nx][ny]=step[t.first][t.second]+1;
				q.push({nx,ny});
			}
		}
		if(a[t.first][t.second]=='a')
		{
			for(int i=1;i<=cnt;i++)
			{
				int nx=b[i].x;
				int ny=b[i].y;
				if(nx>=1&&nx<=h&&ny>=1&&ny<=w&&!vis[nx][ny])
				{	
					vis[nx][ny]=true;
					step[nx][ny]=step[t.first][t.second]+1;
					q.push({nx,ny});
				}
			}
		}
	}
}
int main()
{
	cin>>h>>w;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>a[i][j];
			if(a[i][j]>='a'&&a[i][j]<='z')
			{
				b[++cnt].x=i;
				b[++cnt].y=j;	
				a[i][j]='a';
			}
		}
	}
	bfs(1,1);
	cout<<step[h][w];
	return 0;
 } 

提出情報

提出日時
問題 D - Teleport Maze
ユーザ sxyz88
言語 C++23 (GCC 15.2.0)
得点 0
コード長 1176 Byte
結果 WA
実行時間 > 2000 ms
メモリ 25204 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 400
結果
WA × 4
WA × 31
TLE × 20
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt WA 2 ms 7556 KiB
00_sample_01.txt WA 2 ms 7556 KiB
00_sample_02.txt WA 2 ms 7600 KiB
00_sample_03.txt WA 2 ms 7556 KiB
01_random_00.txt WA 2 ms 7556 KiB
01_random_01.txt TLE > 2000 ms 9716 KiB
01_random_02.txt WA 37 ms 9604 KiB
01_random_03.txt TLE > 2000 ms 25204 KiB
01_random_04.txt WA 37 ms 9424 KiB
01_random_05.txt TLE > 2000 ms 10440 KiB
01_random_06.txt WA 75 ms 9548 KiB
01_random_07.txt WA 37 ms 9648 KiB
01_random_08.txt WA 3 ms 7380 KiB
01_random_09.txt WA 15 ms 8868 KiB
01_random_10.txt WA 36 ms 9428 KiB
01_random_11.txt TLE > 2000 ms 21696 KiB
01_random_12.txt WA 50 ms 9452 KiB
01_random_13.txt WA 41 ms 9604 KiB
01_random_14.txt WA 86 ms 9636 KiB
01_random_15.txt WA 37 ms 9604 KiB
01_random_16.txt WA 3 ms 7568 KiB
01_random_17.txt WA 17 ms 8660 KiB
01_random_18.txt WA 36 ms 9460 KiB
01_random_19.txt TLE > 2000 ms 18020 KiB
01_random_20.txt TLE > 2000 ms 13028 KiB
01_random_21.txt TLE > 2000 ms 14152 KiB
01_random_22.txt TLE > 2000 ms 10080 KiB
01_random_23.txt TLE > 2000 ms 11360 KiB
01_random_24.txt WA 3 ms 7500 KiB
01_random_25.txt WA 413 ms 8368 KiB
01_random_26.txt WA 36 ms 9604 KiB
01_random_27.txt TLE > 2000 ms 14616 KiB
01_random_28.txt TLE > 2000 ms 13556 KiB
01_random_29.txt TLE > 2000 ms 11756 KiB
01_random_30.txt TLE > 2000 ms 12864 KiB
01_random_31.txt TLE > 2000 ms 13000 KiB
01_random_32.txt WA 3 ms 7612 KiB
01_random_33.txt WA 1349 ms 9008 KiB
01_random_34.txt WA 37 ms 9424 KiB
01_random_35.txt TLE > 2000 ms 11596 KiB
01_random_36.txt TLE > 2000 ms 9928 KiB
01_random_37.txt WA 1100 ms 9808 KiB
01_random_38.txt TLE > 2000 ms 10696 KiB
01_random_39.txt TLE > 2000 ms 10612 KiB
02_handmade_00.txt WA 36 ms 9648 KiB
02_handmade_01.txt TLE > 2000 ms 25160 KiB
02_handmade_02.txt WA 36 ms 9604 KiB
02_handmade_03.txt WA 36 ms 9460 KiB
02_handmade_04.txt WA 36 ms 9452 KiB
02_handmade_05.txt WA 36 ms 9592 KiB
02_handmade_06.txt TLE > 2000 ms 25068 KiB