#include #include #include #include using std::vector; typedef vector > Board; int check_white(Board &board, std::stack< std::pair > &todo, int row, int col, int N) { if (row >= 0 && col >= 0 && row < N && col < N) { if (board[row][col] == '-') { board[row][col] = 'w'; todo.push(std::make_pair(row, col)); return 1; } } return 0; } int main(int argc, char const *argv[]) { int T; std::cin >> T; for (int i = 0; i < T; ++i) { int N; std::cin >> N; Board board(N,vector(N)); for (int row = 0; row < N; row++) { char temp[N+1]; std::cin >> temp; for(int col = 0; col < N; col++) { board[row][col] = temp[col]; } } // fill stack with whites std::stack< std::pair > todo; for (int row = 0; row < N; row++) { for (int col = 0; col < N; col++) { if (board[row][col] == 'w') { todo.push(std::pair(row, col)); } } } int no_made_white = 0; while(!todo.empty()) { std::pair n = todo.top(); todo.pop(); int row = n.first; int col = n.second; no_made_white += check_white(board, todo, row-1, col-1, N); no_made_white += check_white(board, todo, row-1, col, N); no_made_white += check_white(board, todo, row-1, col+1, N); no_made_white += check_white(board, todo, row, col-1, N); no_made_white += check_white(board, todo, row, col+1, N); no_made_white += check_white(board, todo, row+1, col-1, N); no_made_white += check_white(board, todo, row+1, col, N); no_made_white += check_white(board, todo, row+1, col+1, N); } std::cout << no_made_white << std::endl; } return 0; }