Submission #11420401


Source Code Expand

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

bool b[600][600] = { false };
char c[600][600];
void search(int x,int y){
  if(x < 0 || x >= W || y < 0 || y <= H || c[x][y] == "#") return;
  if(b[x][y]) return;

  b[x][y] = true;

  search(x - 1, y);
  search(x, y - 1);
  search(x,  y + 1);
  search(x + 1, y);
}

int main(){
  int H,W;
  cin >> H >> W;

 
  int sw,sh,gw,gh;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> c[i][j];
    }
  }
  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(c[i][j] == 's'){ sw = i, sh = j; }
      if(c[i][j] == 'g'){ gw = i, gh = j; }
    }
  }

  search(sw , sh);

  if(b[gw][gh]){ cout << "Yes"; }
  else{ cout << "No"; }
  

  return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘void search(int, int)’:
./Main.cpp:7:20: error: ‘W’ was not declared in this scope
   if(x < 0 || x >= W || y < 0 || y <= H || c[x][y] == "#") return;
                    ^
./Main.cpp:7:39: error: ‘H’ was not declared in this scope
   if(x < 0 || x >= W || y < 0 || y <= H || c[x][y] == "#") return;
                                       ^
./Main.cpp:7:55: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if(x < 0 || x >= W || y < 0 || y <= H || c[x][y] == "#") return;
                                                       ^