Submission #71684019


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int gx[4]={0,0,1,-1};
const int gy[4]={1,-1,0,0};
int n,m;
char c[1005][1005];
bool f[1005][1005];
struct Node{int x,y,ans;};
map<char,bool> mp;
int bfs(){
    queue<Node> q;
    Node a={1,1,0};
    q.push(a);
    while(!q.empty()){
        a=q.front();
        q.pop();
        if(a.x==n&&a.y==m) return a.ans;
        for(int i=0;i<4;i++){
            Node now;
            now.x=gx[i]+a.x;
            now.y=gy[i]+a.y;
            now.ans=a.ans+1;
            if(f[now.x][now.y]) q.push(now),f[now.x][now.y]=false;
        }
        if(c[a.x][a.y]!='.'){
            char cs=c[a.x][a.y];
            if(mp[cs]) continue;
            mp[cs]=true;
            for(int i=1;i<=n;i++){
                for(int j=1;j<=m;j++){
                    if(c[i][j]==cs){
                        Node now;
                        now.x=i;
                        now.y=j;
                        now.ans=a.ans+1;
                        q.push(now);
                        f[i][j]=false;
                    }
                }
            }
        }
    }
    return -1;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c[i][j];
            if(c[i][j]!='#') f[i][j]=true;
        }
    }
    cout<<bfs();
	return 0;
}

Submission Info

Submission Time
Task D - Teleport Maze
User FYCCCTA2011
Language C++23 (GCC 15.2.0)
Score 400
Code Size 1370 Byte
Status AC
Exec Time 66 ms
Memory 19496 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 1 ms 3540 KiB
00_sample_01.txt AC 1 ms 3436 KiB
00_sample_02.txt AC 1 ms 3648 KiB
00_sample_03.txt AC 1 ms 3596 KiB
01_random_00.txt AC 1 ms 3548 KiB
01_random_01.txt AC 19 ms 6912 KiB
01_random_02.txt AC 30 ms 5712 KiB
01_random_03.txt AC 66 ms 19496 KiB
01_random_04.txt AC 39 ms 5900 KiB
01_random_05.txt AC 37 ms 8396 KiB
01_random_06.txt AC 42 ms 6540 KiB
01_random_07.txt AC 40 ms 5856 KiB
01_random_08.txt AC 1 ms 3480 KiB
01_random_09.txt AC 17 ms 4860 KiB
01_random_10.txt AC 38 ms 5584 KiB
01_random_11.txt AC 59 ms 16212 KiB
01_random_12.txt AC 46 ms 6284 KiB
01_random_13.txt AC 40 ms 5980 KiB
01_random_14.txt AC 50 ms 6364 KiB
01_random_15.txt AC 49 ms 5676 KiB
01_random_16.txt AC 1 ms 3512 KiB
01_random_17.txt AC 9 ms 4856 KiB
01_random_18.txt AC 30 ms 5680 KiB
01_random_19.txt AC 54 ms 13196 KiB
01_random_20.txt AC 44 ms 9324 KiB
01_random_21.txt AC 48 ms 9936 KiB
01_random_22.txt AC 30 ms 5528 KiB
01_random_23.txt AC 41 ms 7916 KiB
01_random_24.txt AC 1 ms 3548 KiB
01_random_25.txt AC 5 ms 4092 KiB
01_random_26.txt AC 30 ms 5476 KiB
01_random_27.txt AC 48 ms 10400 KiB
01_random_28.txt AC 47 ms 9416 KiB
01_random_29.txt AC 44 ms 8044 KiB
01_random_30.txt AC 44 ms 9080 KiB
01_random_31.txt AC 45 ms 9216 KiB
01_random_32.txt AC 1 ms 3584 KiB
01_random_33.txt AC 16 ms 4716 KiB
01_random_34.txt AC 27 ms 5476 KiB
01_random_35.txt AC 40 ms 7592 KiB
01_random_36.txt AC 27 ms 5696 KiB
01_random_37.txt AC 37 ms 5856 KiB
01_random_38.txt AC 41 ms 7160 KiB
01_random_39.txt AC 38 ms 6912 KiB
02_handmade_00.txt AC 30 ms 5696 KiB
02_handmade_01.txt AC 37 ms 17340 KiB
02_handmade_02.txt AC 25 ms 4608 KiB
02_handmade_03.txt AC 25 ms 4460 KiB
02_handmade_04.txt AC 27 ms 5612 KiB
02_handmade_05.txt AC 38 ms 5612 KiB
02_handmade_06.txt AC 59 ms 6784 KiB