#include <bits/stdc++.h>
using namespace std;
void solve()
{
/// JUST KEEP GOING
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};
int n, m; cin>>n>>m; char grid[n][m]; int d[n][m];
set<int>v[n], h[m]; int sx, sy, ex, ey; bool vis[n][m];
for(int l=0;l<n;l++) {
for(int i=0;i<m;i++) {
cin>>grid[l][i]; d[l][i]=1e9;
char c=grid[l][i]; vis[l][i]=false;
if(c=='S') { sx=l; sy=i; d[l][i]=0; }
if(c=='C') { ex=l; ey=i; }
}
}
queue<pair<int, int>>q; q.push({sx, sy});
while(!q.empty()) {
int a=q.front().first, b=q.front().second; q.pop();
if(vis[a][b]) continue; vis[a][b]=true;
for(int l=0;l<4;l++) {
int x=a+nx[l], y=b+ny[l];
if(x>=0&&x<n&&y>=0&&y<m) {
if(vis[x][y]||grid[x][y]=='#') continue;
d[x][y]=d[a][b]+1; q.push({x, y});
}
}
}
cout<<d[ex][ey]<<'\n'; return;
}
int32_t main()
{
int t; t=1;
while(t--) {
solve();
}
return 0;
}
Compilation message
portals.cpp: In function 'void solve()':
portals.cpp:22:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
22 | if(vis[a][b]) continue; vis[a][b]=true;
| ^~
portals.cpp:22:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
22 | if(vis[a][b]) continue; vis[a][b]=true;
| ^~~
portals.cpp:31:22: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | cout<<d[ex][ey]<<'\n'; return;
| ^~~~
portals.cpp:31:22: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
292 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
288 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |