AtCoder Typical Contest 001

Submission #7475304

Source codeソースコード

#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

Task問題 A - 深さ優先探索
User nameユーザ名 futureworld
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 CE
Score得点 -
Source lengthソースコード長 945 Byte
File nameファイル名
Exec time実行時間 -
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

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

Test case