#include #include #include #include #include #include using namespace std; // Serves to keep track of any map, each bit is mapped to something uint8_t the_matrix[500][500]; /* V3 V2 V1 V0 E3 E2 E1 E0 Vx: Visited in this phase, V0 is the first phase Ex: Edge in this direction, E0 is to the north during phase 0, E1 to the west during phase 0 etc E0 is to the east during phase 1, E1 to the north during phase 1 etc */ struct Agent { int x; int y; int steps; }; enum Direction { NORTH, WEST, SOUTH, EAST, }; bool check_dir(Agent smith, Direction dir) { return the_matrix[smith.x][smith.y] & (0x01 << ((dir+smith.steps)%4)); } int main() { int width, height, steps; string str_in; ostringstream debug_stream; queue search_queue; while(cin >> height >> width) { steps = 0; cin.ignore(1000, '\n'); debug_stream << "Read width and height [" << width << "][" << height << "]\n"; for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { if(x == (width-1) && y == (height-1)) { the_matrix[x][y] = 0; continue; } getline(cin, str_in); debug_stream << "Read line: " << str_in << endl; the_matrix[x][y] = (str_in.find('N') != string::npos) ? (1<