Submission #7475304


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

bool dfs(int x,int y) {
  int c = 1;
  if (town.at(x).at(y) == "g") {
    return 1;
  }
  for (int dx=-1; dx<=1; ++dx) {
    for (int dy=-1; dy<=1; ++dy) {
      int nx = x + dx;
      int ny = y + dy;
      if (town.at(nx).at(ny) == "." && visit.at(nx).at(ny) == 0 && 0 <= nx && nx < H && 0 <= ny && ny < W) {
        visit.at(nx).at(ny) == 1;
        c*(1-dfs(nx,ny));
      }
    }
  }
  return 1-c;
}
  




int main() {
  int H,W;
  cin >> H >> W; 
  vector<vector<char>> town(H,vector<char>(W));
  for (int i=0; i<H; ++H) {
    for (int j=0; j<W; ++j) {
      cin >> town.at(i).at(j);
      if (town.at(i).at(j) == "s") {
        int a = i;
        int b = j;
      }
    }
  }
  vector<vector<int>> visit(H,vector<int>(W,0));
  visit.at(a).at(b) = 1;
  if (bfs(a,b)) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
    
  

Submission Info

Submission Time
Task A - 深さ優先探索
User dodonpa
Language C++14 (GCC 5.4.1)
Score 0
Code Size 945 Byte
Status CE

Compile Error

./Main.cpp: In function ‘bool dfs(int, int)’:
./Main.cpp:6:7: error: ‘town’ was not declared in this scope
   if (town.at(x).at(y) == "g") {
       ^
./Main.cpp:13:11: error: ‘town’ was not declared in this scope
       if (town.at(nx).at(ny) == "." && visit.at(nx).at(ny) == 0 && 0 <= nx && nx < H && 0 <= ny && ny < W) {
           ^
./Main.cpp:13:40: error: ‘visit’ was not declared in this scope
       if (town.at(nx).at(ny) == "." && visit.at(nx).at(ny) == 0 && 0 <= nx && nx < H && 0 <= ny && ny < W) {
                                        ^
./Main.cpp:13:84: error: ‘H’ was not declared in this scope
       if (town.at(nx).at(ny) == "." && visit.at(nx).at(ny) == 0 && 0 <= nx && nx < H && 0 <= ny && ny < W) {
                                                                                    ^
./Main.cpp:13:105: error: ‘W’ was not declared in this scope
       if (town.at(nx).at(ny) == "." && visit.at(nx).at(ny) == 0 && 0 <= nx && nx < H && 0 <= ny && ny < W) {
                                        ...