Submission #68750733


Source Code Expand

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn=500+5;
const int x[4]={-1,0,1,0};
const int y[4]={0,1,0,-1};
string s[maxn];
int dis[maxn][maxn][2];
class A
{
public:
    int x,y,zt;
};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h,w;
    cin>>h>>w;
    queue<A> q;
    pair<int,int> ed;
    for (int i=1;i<=h;i++)
    {
        cin>>s[i];
        s[i]=' '+s[i];
        for (int j=1;j<=w;j++)
        {
            dis[i][j][0]=dis[i][j][1]=1e9;
            if (s[i][j]=='S')
            {
                dis[i][j][0]=0;
                q.push({i,j,0});
                s[i][j]='.';
            }
            else if (s[i][j]=='G')
            {
                ed={i,j};
                s[i][j]='.';
            }
        }
    }
    while(!q.empty())
    {
        auto now=q.front();
        q.pop();
        for (int i=0;i<4;i++)
        {
            int nxtx=now.x+x[i];
            int nxty=now.y+y[i];
            int nxtzt=now.zt;
            if (nxtx>0&&nxtx<=h&&nxty>0&&nxty<=w)
            {
                if (s[nxtx][nxty]=='?')
                    nxtzt^=1;
                if (s[nxtx][nxty]!='#'&&dis[nxtx][nxty][nxtzt]>=1e9)
                {
                    if (nxtzt==0&&s[nxtx][nxty]=='x')
                        continue;
                    if (nxtzt==1&&s[nxtx][nxty]=='o')
                        continue;
                    dis[nxtx][nxty][nxtzt]=dis[now.x][now.y][now.zt]+1;
                    q.push({nxtx,nxty,nxtzt});
                }
            }
        }
    }
    int ans=min(dis[ed.first][ed.second][0],dis[ed.first][ed.second][1]);
    if (ans>=1e9)
        cout<<"-1";
    else
        cout<<ans;
}

Submission Info

Submission Time
Task D - Toggle Maze
User Alliy666
Language C++ 23 (gcc 12.2)
Score 400
Code Size 1869 Byte
Status AC
Exec Time 27 ms
Memory 5884 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 67
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt, 02_random_42.txt, 02_random_43.txt, 02_random_44.txt, 02_random_45.txt, 02_random_46.txt, 02_random_47.txt, 02_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3508 KiB
00_sample_01.txt AC 1 ms 3444 KiB
00_sample_02.txt AC 1 ms 3576 KiB
01_handmade_00.txt AC 10 ms 5684 KiB
01_handmade_01.txt AC 11 ms 5744 KiB
01_handmade_02.txt AC 11 ms 5688 KiB
01_handmade_03.txt AC 10 ms 5660 KiB
01_handmade_04.txt AC 1 ms 3496 KiB
01_handmade_05.txt AC 1 ms 3488 KiB
01_handmade_06.txt AC 1 ms 3456 KiB
01_handmade_07.txt AC 1 ms 3556 KiB
01_handmade_08.txt AC 1 ms 3572 KiB
01_handmade_09.txt AC 6 ms 5736 KiB
01_handmade_10.txt AC 6 ms 5684 KiB
01_handmade_11.txt AC 11 ms 5716 KiB
01_handmade_12.txt AC 12 ms 5756 KiB
01_handmade_13.txt AC 8 ms 5660 KiB
01_handmade_14.txt AC 8 ms 5884 KiB
02_random_00.txt AC 1 ms 3520 KiB
02_random_01.txt AC 11 ms 5120 KiB
02_random_02.txt AC 2 ms 3492 KiB
02_random_03.txt AC 13 ms 5356 KiB
02_random_04.txt AC 1 ms 3848 KiB
02_random_05.txt AC 15 ms 5764 KiB
02_random_06.txt AC 12 ms 5696 KiB
02_random_07.txt AC 15 ms 5604 KiB
02_random_08.txt AC 2 ms 5548 KiB
02_random_09.txt AC 15 ms 5612 KiB
02_random_10.txt AC 2 ms 5740 KiB
02_random_11.txt AC 14 ms 5756 KiB
02_random_12.txt AC 2 ms 5740 KiB
02_random_13.txt AC 5 ms 5144 KiB
02_random_14.txt AC 13 ms 5240 KiB
02_random_15.txt AC 2 ms 3776 KiB
02_random_16.txt AC 16 ms 5752 KiB
02_random_17.txt AC 2 ms 5504 KiB
02_random_18.txt AC 16 ms 5704 KiB
02_random_19.txt AC 3 ms 5504 KiB
02_random_20.txt AC 16 ms 5764 KiB
02_random_21.txt AC 2 ms 5532 KiB
02_random_22.txt AC 16 ms 5744 KiB
02_random_23.txt AC 2 ms 3640 KiB
02_random_24.txt AC 5 ms 5024 KiB
02_random_25.txt AC 2 ms 4632 KiB
02_random_26.txt AC 5 ms 4372 KiB
02_random_27.txt AC 3 ms 4176 KiB
02_random_28.txt AC 8 ms 5876 KiB
02_random_29.txt AC 5 ms 5564 KiB
02_random_30.txt AC 12 ms 5792 KiB
02_random_31.txt AC 3 ms 5744 KiB
02_random_32.txt AC 5 ms 5732 KiB
02_random_33.txt AC 4 ms 5736 KiB
02_random_34.txt AC 8 ms 5744 KiB
02_random_35.txt AC 5 ms 3868 KiB
02_random_36.txt AC 16 ms 4800 KiB
02_random_37.txt AC 10 ms 4336 KiB
02_random_38.txt AC 27 ms 5768 KiB
02_random_39.txt AC 22 ms 5684 KiB
02_random_40.txt AC 27 ms 5668 KiB
02_random_41.txt AC 1 ms 3580 KiB
02_random_42.txt AC 1 ms 3468 KiB
02_random_43.txt AC 2 ms 5480 KiB
02_random_44.txt AC 2 ms 5476 KiB
02_random_45.txt AC 1 ms 3448 KiB
02_random_46.txt AC 1 ms 3488 KiB
02_random_47.txt AC 2 ms 5304 KiB
02_random_48.txt AC 2 ms 5428 KiB