#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //Utilities #define sqr(x) ((x)*(x)) #define cbr(x) ((x)*(x)*(x)) #define rep(c, i, n) for((i)=(c); (i)<(n); (i)++) //Geometry /** struct pt { long long x, y; }; double vecmul(pt a, pt b) { //Векторное умножение А*В return (a.x*b.y - b.x*a.y); } //скалярное умножение a*b = |a|*|b|*cos(a,b) double dist(double ax, double ay, double bx, double by) { return sqrt(sqr(ax - bx) + sqr(ay - by)); } */ //DBG //templatevoid printarr(T a[], T2 sz, T2 beg = 0) { for (T2 i = beg; i> n; int i, j; rep(0, i, n+2) { lab[0][i] = '#'; lab[n + 1][i] = '#'; lab[i][0] = '#'; lab[i][n + 1] = '#'; } rep(0, i, n) { rep(0, j, n) { cin >> lab[i+1][j+1]; } } rep(0, i, n+2) { rep(0, j, n+2) { cout << lab[i][j]; } cout << endl; } dfs(1, 1); dfs(n - 1, n - 1); cout << paint*9-36; return 0; } void dfs(int y, int x) { lab[y][x] = '$'; if (lab[y][x + 1] == '#') { paint++; }; DBG3(y, x, paint); if (lab[y][x - 1] == '#') { paint++; }; DBG3(y, x, paint); if (lab[y + 1][x] == '#') { paint++; }; DBG3(y, x, paint); if (lab[y - 1][x] == '#') { paint++; }; DBG3(y, x, paint); cout << endl; if (lab[y][x + 1] == '.') { dfs(y, x + 1); }; if (lab[y][x - 1] == '.') { dfs(y, x - 1); }; if (lab[y + 1][x] == '.') { dfs(y + 1, x); }; if (lab[y - 1][x] == '.') { dfs(y - 1, x); }; }