Submission #61381197
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
if(x<0) printf("-"),x=-x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
template<class T> il void in(T &x) {
x = 0; char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
x *= f;
}
int T=1;
const int M=2e3+10;
int n,m,dis[M][M][2];
char mp[M][M];
pair<int,int> s,t;
#define x first
#define y second
void bfs(){
queue<pair<pair<int,int>,bool> > q;
q.push(make_pair(s,0));
q.push(make_pair(s,1));
dis[s.x][s.y][0]=dis[s.x][s.y][1]=0;
while(q.size()){
pair<int,int> x=q.front().x;
bool flag=q.front().y;
q.pop();
if(!flag){
int tx,ty=x.y;
tx=x.x+1;
if(tx<=n&&mp[tx][ty]!='#'&&dis[tx][ty][1]==-1){
dis[tx][ty][1]=dis[x.x][x.y][0]+1;
q.push(make_pair(make_pair(tx,ty),1));
}
tx=x.x-1;
if(tx>=1&&mp[tx][ty]!='#'&&dis[tx][ty][1]==-1){
dis[tx][ty][1]=dis[x.x][x.y][0]+1;
q.push(make_pair(make_pair(tx,ty),1));
}
}
else{
int tx=x.x,ty;
ty=x.y+1;
if(ty<=m&&mp[tx][ty]!='#'&&dis[tx][ty][0]==-1){
dis[tx][ty][0]=dis[x.x][x.y][1]+1;
q.push(make_pair(make_pair(tx,ty),0));
}
ty=x.y-1;
if(ty>=1&&mp[tx][ty]!='#'&&dis[tx][ty][0]==-1){
dis[tx][ty][0]=dis[x.x][x.y][1]+1;
q.push(make_pair(make_pair(tx,ty),0));
}
}
}
int ans=1e18;
if(~dis[t.x][t.y][0]) ans=min(ans,dis[t.x][t.y][0]);
if(~dis[t.x][t.y][1]) ans=min(ans,dis[t.x][t.y][1]);
if(ans>=1e18) puts("-1");
else printf("%lld\n",ans);
}
void solve() {
in(n),in(m);
rep(i,1,n) {
rep(j,1,m) cin>>mp[i][j];
}
memset(dis,-1,sizeof dis);
rep(i,1,n) {
rep(j,1,m) {
if(mp[i][j]=='S') s=make_pair(i,j);
if(mp[i][j]=='G') t=make_pair(i,j);
}
}
bfs();
}
fire main() {
while(T--) {
solve();
}
return false;
}
Submission Info
Submission Time
2025-01-04 12:24:48
Task
D - Snaky Walk
User
zhy091206
Language
C++ 20 (gcc 12.2)
Score
400
Code Size
2306 Byte
Status
AC
Exec Time
101 ms
Memory
68916 KB
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:76:13: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
76 | rep(i,1,n) {
| ^
Main.cpp:8:37: note: in definition of macro ‘rep’
8 | #define rep(i,x,y) for(register int i=x;i<=y;i++)
| ^
Main.cpp:77:21: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
77 | rep(j,1,m) cin>>mp[i][j];
| ^
Main.cpp:8:37: note: in definition of macro ‘rep’
8 | #define rep(i,x,y) for(register int i=x;i<=y;i++)
| ^
Main.cpp:80:13: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
80 | rep(i,1,n) {
| ^
Main.cpp:8:37: note: in definition of macro ‘rep’
8 | #define rep(i,x,y) for(register int i=x;i<=y;i++)
| ^
Main.cpp:81:21: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
81 | rep(j,1,m) {
| ^
Main.cpp:8:37: note: in definition of macro ‘rep’
8 | #define rep(i,x,y) for(register int i=x;i<=y;i++)
| ^
Main.cpp:82:54: warning: address requested for ‘i’, which is declared ‘register’ [-Wextra]
82 | if(mp[i][j]=='S') s=make_pair(i,j);
| ~~~~~~~~~^~~~~
Main.cpp:82:54: warning: address requested for ‘j’, which is declared ‘register’ [-Wextra]
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
25 ms
66732 KB
00_sample_01.txt
AC
26 ms
66708 KB
00_sample_02.txt
AC
26 ms
66892 KB
01_random_00.txt
AC
41 ms
67928 KB
01_random_01.txt
AC
26 ms
67376 KB
01_random_02.txt
AC
53 ms
68620 KB
01_random_03.txt
AC
32 ms
67408 KB
01_random_04.txt
AC
45 ms
68016 KB
01_random_05.txt
AC
26 ms
67672 KB
01_random_06.txt
AC
25 ms
66756 KB
01_random_07.txt
AC
26 ms
66996 KB
01_random_08.txt
AC
59 ms
68596 KB
01_random_09.txt
AC
101 ms
68712 KB
01_random_10.txt
AC
91 ms
68764 KB
01_random_11.txt
AC
87 ms
68748 KB
01_random_12.txt
AC
87 ms
68720 KB
01_random_13.txt
AC
83 ms
68896 KB
01_random_14.txt
AC
88 ms
68756 KB
01_random_15.txt
AC
60 ms
68592 KB
01_random_16.txt
AC
60 ms
68584 KB
01_random_17.txt
AC
60 ms
68556 KB
01_random_18.txt
AC
89 ms
68756 KB
01_random_19.txt
AC
92 ms
68752 KB
02_random2_00.txt
AC
59 ms
68780 KB
02_random2_01.txt
AC
60 ms
68704 KB
02_random2_02.txt
AC
61 ms
68844 KB
02_random2_03.txt
AC
60 ms
68844 KB
02_random2_04.txt
AC
59 ms
68916 KB
02_random2_05.txt
AC
60 ms
68856 KB
02_random2_06.txt
AC
61 ms
68844 KB
02_random2_07.txt
AC
60 ms
68844 KB
02_random2_08.txt
AC
60 ms
68844 KB
02_random2_09.txt
AC
59 ms
68696 KB
02_random2_10.txt
AC
60 ms
68668 KB
02_random2_11.txt
AC
59 ms
68784 KB
02_random2_12.txt
AC
60 ms
68716 KB
02_random2_13.txt
AC
59 ms
68848 KB
02_random2_14.txt
AC
59 ms
68772 KB
02_random2_15.txt
AC
58 ms
68652 KB
02_random2_16.txt
AC
58 ms
68692 KB
02_random2_17.txt
AC
58 ms
68840 KB
02_random2_18.txt
AC
60 ms
68848 KB
02_random2_19.txt
AC
59 ms
68844 KB
03_random3_00.txt
AC
82 ms
68712 KB
03_random3_01.txt
AC
70 ms
68552 KB
03_random3_02.txt
AC
82 ms
68692 KB
03_random3_03.txt
AC
81 ms
68684 KB
04_random4_00.txt
AC
79 ms
68648 KB
04_random4_01.txt
AC
75 ms
68840 KB
04_random4_02.txt
AC
76 ms
68852 KB
04_random4_03.txt
AC
78 ms
68676 KB
05_handmade_00.txt
AC
72 ms
68560 KB
05_handmade_01.txt
AC
82 ms
68896 KB
05_handmade_02.txt
AC
25 ms
66684 KB
05_handmade_03.txt
AC
25 ms
66708 KB
05_handmade_04.txt
AC
26 ms
66752 KB
05_handmade_05.txt
AC
83 ms
68700 KB