아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bricks in the Wall

시간 제한2초메모리 제한1024 MB

요약
막힌 칸이 있는 n×m 격자에서 서로 겹치지 않는 가로 또는 세로 빈 칸 구간을 최대 두 개 골라 길이 합의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
행렬, 누적 합, 동적 계획법
정답자
아직 제출이 없습니다

문제

Bob is decorating a loft-style rectangular wall with bricks. The wall consists of n×mn \times m unit cells. Some cells are already occupied by bricks, while the remaining cells are empty.

Bob wants to add up to two more bricks to this wall. New bricks must have a width equal to 11 unit and can have any positive integer length. Each brick can only be placed horizontally or vertically, so each new brick will occupy several consecutive empty cells in one row or in one column. Also, these two bricks must not intersect, i.e. occupy the same cell.

What is the maximum possible sum of lengths of at most two new bricks that Bob can add to this wall?

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm --- the height and the width of the wall (1≤n,m1 \le n, m; n⋅m≤106n \cdot m \le 10^6).

The next nn lines contain mm characters each, describing the wall. An occupied cell is denoted by '\#', an empty cell is denoted by '.'.

It is guaranteed that the sum of n⋅mn \cdot m over all test cases does not exceed 10610^6.

출력

For each test case, print a single integer --- the maximum possible sum of lengths of at most two new bricks.

예제1

  1. 예제 1

    입력
    5
    2 2
    ..
    ..
    4 5
    ###.#
    #....
    .##.#
    #.#.#
    2 1
    .
    .
    2 3
    ###
    #.#
    5 4
    ##.#
    ..#.
    #.#.
    ....
    #.##
    
    예상 출력
    4
    6
    2
    1
    7