<Problem>
https://www.spoj.com/PTIT/problems/BCROBOT/
#include <iostream>
#include <queue>
using namespace std;
#define RE 2147483647
int n;
char a[1001][1001];
int dx[4]{ 1, -1, 0, 0 };
int dy[4]{ 0, 0, 1, -1 };
class Node {
public:
int x, y;
Node(int x, int y) {
this->x = x;
this->y = y;
}
};
void bfs(int x, int y, bool** visited) {
queue<Node> iDex;
iDex.push(Node(x, y));
visited[x][y] = true;
while (!iDex.empty()) {
Node t = iDex.front();
iDex.pop();
for (int i = 0; i <= 3; i++) {
int nextX = t.x + dx[i];
int nextY = t.y + dy[i];
if (nextX >= 1 && nextX <= n && nextY >= 1 && nextY <= n &&
!visited[nextX][nextY] && a[nextX][nextY] == '.') {
visited[nextX][nextY] = true;
iDex.push(Node(nextX, nextY));
}
}
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
long long** f = new long long* [1003];
for (int i = 0; i <= 1002; i++) {
f[i] = new long long[1003] { 0 };
}
bool** visited = new bool* [1003];
for (int i = 0; i <= 1002; i++) {
visited[i] = new bool[1003] { false };
}
f[1][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j] == '.')
f[i][j] = (f[i - 1][j] + f[i][j - 1]) % RE;
}
}
//cout << f[n][n] << endl;
if (f[n][n] > 0) {
cout << f[n][n] << endl;
}
else {
bfs(1, 1, visited);
if (visited[n][n] == true) {
cout << "THE GAME IS A LIE" << endl;
}
else {
cout << "INCONCEIVABLE" << endl;
}
}
return 0;
}