提出 #7475304


ソースコード 拡げる

Copy
#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;
  }
}
    
  

提出情報

提出日時
問題 A - 深さ優先探索
ユーザ dodonpa
言語 C++14 (GCC 5.4.1)
得点 0
コード長 945 Byte
結果

コンパイルエラー

./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) {
                                        ...