Submission #61380810
Source Code Expand
#include<bits/stdc++.h>
#define il inline
#define all(x) (x).begin(),(x).end()
#define mem(x,y) memset((x),(y),sizeof((x)))
#define input(x) freopen(x,"r",stdin)
#define output(x) freopen(x,"w",stdout)
using namespace std;
using db=double;
using ll=long long;
using ull=unsigned long long;
const int N=1e3+10;
struct node{int x,y,z;};
vector<node>ve={{1,0,0},{-1,0,0},{0,1,1},{0,-1,1}};
char s[N][N];bool vis[N][N][2];int dis[N][N][2];
il int bfs(int x,int y)
{
queue<node>q;
q.push({x,y,-1});
while(!q.empty())
{
auto [x,y,z]=q.front();q.pop();
if(s[x][y]=='G') return dis[x][y][z];
for(auto [i,j,k]:ve)
{
if(z==k) continue;
if(!vis[x+i][y+j][k]) vis[x+i][y+j][k]=1,dis[x+i][y+j][k]=dis[x][y][z]+1,q.push({x+i,y+j,k});
}
}
return -1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n,m,x,y;
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>s[i]+1;
mem(vis,1);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
if(s[i][j]!='#') mem(vis[i][j],0);
if(s[i][j]=='S') x=i,y=j;
}
cout<<bfs(x,y);
return 0;
}
Submission Info
Submission Time
2025-01-04 21:23:12+0900
Task
D - Snaky Walk
User
ilibilib
Language
C++ 17 (gcc 12.2)
Score
400
Code Size
1225 Byte
Status
AC
Exec Time
34 ms
Memory
14408 KiB
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:37:36: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
37 | for(int i=1;i<=n;++i) cin>>s[i]+1;
| ~~~~^~
Main.cpp:45:18: warning: ‘y’ may be used uninitialized [-Wmaybe-uninitialized]
45 | cout<<bfs(x,y);
| ^
Main.cpp:35:15: note: ‘y’ was declared here
35 | int n,m,x,y;
| ^
Main.cpp:45:18: warning: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
45 | cout<<bfs(x,y);
| ^
Main.cpp:35:13: note: ‘x’ was declared here
35 | int n,m,x,y;
| ^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
400 / 400
Status
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_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, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_random4_00.txt, 04_random4_01.txt, 04_random4_02.txt, 04_random4_03.txt, 05_handmade_00.txt, 05_handmade_01.txt, 05_handmade_02.txt, 05_handmade_03.txt, 05_handmade_04.txt, 05_handmade_05.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
2 ms
5516 KiB
00_sample_01.txt
AC
2 ms
5568 KiB
00_sample_02.txt
AC
2 ms
5476 KiB
01_random_00.txt
AC
4 ms
7252 KiB
01_random_01.txt
AC
2 ms
6360 KiB
01_random_02.txt
AC
6 ms
6628 KiB
01_random_03.txt
AC
3 ms
5936 KiB
01_random_04.txt
AC
4 ms
6088 KiB
01_random_05.txt
AC
2 ms
5912 KiB
01_random_06.txt
AC
2 ms
5452 KiB
01_random_07.txt
AC
2 ms
5616 KiB
01_random_08.txt
AC
6 ms
6572 KiB
01_random_09.txt
AC
30 ms
13492 KiB
01_random_10.txt
AC
30 ms
12724 KiB
01_random_11.txt
AC
15 ms
9624 KiB
01_random_12.txt
AC
17 ms
11208 KiB
01_random_13.txt
AC
30 ms
14344 KiB
01_random_14.txt
AC
13 ms
10108 KiB
01_random_15.txt
AC
6 ms
6472 KiB
01_random_16.txt
AC
6 ms
6812 KiB
01_random_17.txt
AC
6 ms
6692 KiB
01_random_18.txt
AC
34 ms
14408 KiB
01_random_19.txt
AC
14 ms
10492 KiB
02_random2_00.txt
AC
4 ms
6508 KiB
02_random2_01.txt
AC
4 ms
6492 KiB
02_random2_02.txt
AC
4 ms
6428 KiB
02_random2_03.txt
AC
5 ms
6512 KiB
02_random2_04.txt
AC
5 ms
6516 KiB
02_random2_05.txt
AC
6 ms
6464 KiB
02_random2_06.txt
AC
6 ms
6384 KiB
02_random2_07.txt
AC
6 ms
6684 KiB
02_random2_08.txt
AC
6 ms
6524 KiB
02_random2_09.txt
AC
7 ms
6576 KiB
02_random2_10.txt
AC
7 ms
6536 KiB
02_random2_11.txt
AC
8 ms
6508 KiB
02_random2_12.txt
AC
7 ms
6500 KiB
02_random2_13.txt
AC
7 ms
6428 KiB
02_random2_14.txt
AC
7 ms
6436 KiB
02_random2_15.txt
AC
7 ms
6620 KiB
02_random2_16.txt
AC
6 ms
6560 KiB
02_random2_17.txt
AC
7 ms
6568 KiB
02_random2_18.txt
AC
6 ms
6536 KiB
02_random2_19.txt
AC
5 ms
6664 KiB
03_random3_00.txt
AC
18 ms
14388 KiB
03_random3_01.txt
AC
19 ms
13636 KiB
03_random3_02.txt
AC
25 ms
14312 KiB
03_random3_03.txt
AC
20 ms
14244 KiB
04_random4_00.txt
AC
19 ms
14284 KiB
04_random4_01.txt
AC
25 ms
14328 KiB
04_random4_02.txt
AC
21 ms
14324 KiB
04_random4_03.txt
AC
22 ms
14308 KiB
05_handmade_00.txt
AC
18 ms
14396 KiB
05_handmade_01.txt
AC
30 ms
14316 KiB
05_handmade_02.txt
AC
2 ms
5440 KiB
05_handmade_03.txt
AC
2 ms
5368 KiB
05_handmade_04.txt
AC
2 ms
5424 KiB
05_handmade_05.txt
AC
23 ms
14384 KiB