Submission #761055
Source Code Expand
#include<iostream> #include<iomanip> #include<map> #include<vector> #include<string> #include<stack> using namespace std; enum { WALL = 0, ROAD = 1, SEARCHED = 2, GOAL = 3 }; int main() { int H, W; cin >> H >> W; int state[502][502] = { 0 }; stack<pair<int, int>> place; for (int i = 1; i <= H; i++) { string s; cin >> s; for (int j = 1; j <= s.length; j++) { switch (s[j]) { case 's': state[i][j] = SEARCHED; place.push(make_pair(i, j)); break; case 'g': state[i][j] = GOAL; break; case '.': state[i][j] = ROAD; break; case '#': state[i][j] = WALL; break; } } } const int xy[5] = { 0, 1, 0, -1, 0 }; while (1 <= place.size()) { auto p = place.top(); place.pop(); state[p.second][p.first] = SEARCHED; for (int i = 0; i < 4; i++) { const int y = p.first + xy[i]; const int x = p.second + xy[i + 1]; switch (state[x][y]) { case GOAL: cout << 'Yes' << endl; return 0; case ROAD: place.push(make_pair(y, x)); break; } } } cout << 'No' << endl; }
Submission Info
Submission Time | |
---|---|
Task | A - 深さ優先探索 |
User | eukaryo |
Language | C++14 (Clang++ 3.4) |
Score | 0 |
Code Size | 1131 Byte |
Status | CE |
Compile Error
./Main.cpp:25:26: error: reference to non-static member function must be called; did you mean to call it with no arguments? for (int j = 1; j <= s.length; j++) { ~~^~~~~~ () ./Main.cpp:56:13: warning: multi-character character constant [-Wmultichar] cout << 'Yes' << endl; ^ ./Main.cpp:64:10: warning: multi-character character constant [-Wmultichar] cout << 'No' << endl; ^ 2 warnings and 1 error generated.