#include<string> #include<iostream> #include<vector> #include<string> #include<deque> #include<algorithm> #include<fstream> using namespace std; #define ONLINE_JUDGE #ifndef ONLINE_JUDGE #define cin F ifstream F("input.txt"); #endif vector<string> mat(101); vector<int> leng[101]; int N, M, _max = 1; int main() { int i; cin >> N >> M; for (i = 0; i < N; ++i) { cin >> mat[i]; leng[i].resize(M); } deque <pair <int, int> > DQ; pair<int, int> x, y; leng[0][0] = 1; DQ.push_back(make_pair(0, 0)); while (!DQ.empty()) { x = DQ.front(); DQ.pop_front(); y = x; y.first += 1; if (y.first < N && y.second < M && mat[y.first][y.second] == '.' && leng[y.first][y.second] == 0) { leng[y.first][y.second] = 1; DQ.push_back(y); _max = max(_max, y.first + y.second + 1); } y = x; y.second += 1; if (y.first < N && y.second < M && mat[y.first][y.second] == '.' && leng[y.first][y.second] == 0) { leng[y.first][y.second] = 1; DQ.push_back(y); _max = max(_max, y.first + y.second + 1); } } cout << _max; #ifndef ONLINE_JUDGE system("pause"); #endif return 0; }