Submission #71670007


Source Code Expand

#include <bits/stdc++.h>
//#include <windows.h>
//taskkill /f /im 未命名1.exe
#define ED cerr<<endl;
#define TS cerr<<"I AK IOI"<<endl;
#define cr(x) cerr<<x<<endl;
#define cr2(x,y) cerr<<x<<" "<<y<<endl;
#define cr3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<endl;
#define cr4(x,y,z,w) cerr<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
#define pr(a,l,r) for(int i=l;i<=r;++i) cerr<<a[i]<<' ';ED
#define popcnt __builtin_popcount
#define all(s) s.begin(),s.end()
#define bstring basic_string
//#define add(x,y) (x+=y)%=mod
#define pii pair<int,int>
#define epb emplace_back
#define pb push_back
#define mk make_pair
#define ins insert
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
using namespace std;
const int N=1e3+5,INF=0x3f3f3f3f,mod=1e9+7;
int t,n,m,ans=0;
char s[N][N];vector<pii> S[30];
int dr[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int dis[N][N],vis[N][N];

bool in(int x,int y) {
	return x>=1&&x<=n&&y>=1&&y<=m;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;++j) {
			if(s[i][j]!='.'&&s[i][j]!='#') {
				S[s[i][j]-'a'].epb(i,j);
			}
		}
	}
	deque<pii> q;
	memset(dis,0x3f,sizeof(dis));
	dis[1][1]=0,q.push_front({1,1});
	while(!q.empty()) {
		pii u=q.front();q.pop_front();
		if(vis[u.fi][u.se]) continue;
		vis[u.fi][u.se]=1;
		if(u.se) {
			for(int j=0;j<4;++j) {
				int tx=u.fi+dr[j][0];
				int ty=u.se+dr[j][1];
				if(in(tx,ty)&&s[tx][ty]!='#'&&dis[u.fi][u.se]+1<dis[tx][ty]) {
					dis[tx][ty]=dis[u.fi][u.se]+1;
					q.push_back({tx,ty});
				}
			}
			int op=s[u.fi][u.se]-'a';
			if(op>=0&&op<26) {
				if(dis[u.fi][u.se]<dis[op][0]) {
					dis[op][0]=dis[u.fi][u.se];
					q.push_front({op,0});
				}
			}
		}
		else {
			for(auto it:S[u.fi]) {
				if(dis[u.fi][u.se]+1<dis[it.fi][it.se]) {
					dis[it.fi][it.se]=dis[u.fi][u.se]+1;
					q.push_back(it);
				}
			}
		}
	}
	if(dis[n][m]>INF/2) puts("-1"); 
	else printf("%d\n",dis[n][m]);
	return 0;
}

Submission Info

Submission Time
Task D - Teleport Maze
User Include_S_Z_C_
Language C++23 (GCC 15.2.0)
Score 400
Code Size 2034 Byte
Status AC
Exec Time 41 ms
Memory 28336 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 51
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 7688 KiB
00_sample_01.txt AC 2 ms 7692 KiB
00_sample_02.txt AC 2 ms 7808 KiB
00_sample_03.txt AC 2 ms 7864 KiB
01_random_00.txt AC 2 ms 7876 KiB
01_random_01.txt AC 20 ms 13552 KiB
01_random_02.txt AC 20 ms 12624 KiB
01_random_03.txt AC 37 ms 27956 KiB
01_random_04.txt AC 28 ms 12960 KiB
01_random_05.txt AC 39 ms 16824 KiB
01_random_06.txt AC 31 ms 13480 KiB
01_random_07.txt AC 29 ms 12872 KiB
01_random_08.txt AC 3 ms 7748 KiB
01_random_09.txt AC 14 ms 10912 KiB
01_random_10.txt AC 28 ms 12868 KiB
01_random_11.txt AC 37 ms 24816 KiB
01_random_12.txt AC 41 ms 13192 KiB
01_random_13.txt AC 40 ms 12972 KiB
01_random_14.txt AC 41 ms 13368 KiB
01_random_15.txt AC 39 ms 12804 KiB
01_random_16.txt AC 2 ms 7848 KiB
01_random_17.txt AC 9 ms 10796 KiB
01_random_18.txt AC 8 ms 8820 KiB
01_random_19.txt AC 36 ms 22188 KiB
01_random_20.txt AC 40 ms 17716 KiB
01_random_21.txt AC 39 ms 18492 KiB
01_random_22.txt AC 9 ms 9152 KiB
01_random_23.txt AC 41 ms 15780 KiB
01_random_24.txt AC 2 ms 7644 KiB
01_random_25.txt AC 5 ms 9168 KiB
01_random_26.txt AC 8 ms 8864 KiB
01_random_27.txt AC 27 ms 18588 KiB
01_random_28.txt AC 27 ms 17860 KiB
01_random_29.txt AC 28 ms 16040 KiB
01_random_30.txt AC 28 ms 17472 KiB
01_random_31.txt AC 28 ms 17264 KiB
01_random_32.txt AC 2 ms 7712 KiB
01_random_33.txt AC 7 ms 10536 KiB
01_random_34.txt AC 7 ms 8712 KiB
01_random_35.txt AC 16 ms 15388 KiB
01_random_36.txt AC 7 ms 9028 KiB
01_random_37.txt AC 12 ms 13324 KiB
01_random_38.txt AC 16 ms 14836 KiB
01_random_39.txt AC 15 ms 14644 KiB
02_handmade_00.txt AC 20 ms 12604 KiB
02_handmade_01.txt AC 25 ms 28336 KiB
02_handmade_02.txt AC 5 ms 8772 KiB
02_handmade_03.txt AC 5 ms 8884 KiB
02_handmade_04.txt AC 13 ms 12800 KiB
02_handmade_05.txt AC 19 ms 12744 KiB
02_handmade_06.txt AC 32 ms 20884 KiB