Submission #11595847
Source Code Expand
#include <bits/stdc++.h> using namespace std; using vi = vector<char>; using vvi = vector<vi>; int N, M; vvi field; using vib = vector<bool>; using vvib = vector<vib>; vvib seen; int main(){ int sx, sy, gx, gy; cin >> N >> M; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> field.at(i).at(j); } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if(field.at(i).at(j) == 's'){ sx = i; sy = j; } if(field.at(i).at(j) == 'g'){ gx = i; gy = j; } } } dfs(sx, sy); if(seen.at(gx).at(gy)) cout << Yes << endl; else cout << No << endl; } void dfs(int h, int w) { seen.at(h).at(w) = true; for (int dir = 0; dir < 4; ++dir) { int nh = h + dx[dir]; int nw = w + dy[dir]; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (field.at(nh).at(nw) == '#') continue; if (seen.at(nh).at(nw)) continue; dfs(nh, nw); } }
Submission Info
Submission Time | |
---|---|
Task | A - 深さ優先探索 |
User | ryana |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1042 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:34:13: error: ‘dfs’ was not declared in this scope dfs(sx, sy); ^ ./Main.cpp:35:34: error: ‘Yes’ was not declared in this scope if(seen.at(gx).at(gy)) cout << Yes << endl; ^ ./Main.cpp:36:16: error: ‘No’ was not declared in this scope else cout << No << endl; ^ ./Main.cpp: In function ‘void dfs(int, int)’: ./Main.cpp:43:22: error: ‘dx’ was not declared in this scope int nh = h + dx[dir]; ^ ./Main.cpp:44:22: error: ‘dy’ was not declared in this scope int nw = w + dy[dir]; ^ ./Main.cpp:46:29: error: ‘H’ was not declared in this scope if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; ^ ./Main.cpp:46:50: error: ‘W’ was not declared in this scope if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; ^