Problem:


Score : 400 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.

Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.

Snuke wants to maximize the number of squares lighted by the lamp.

You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.

Find the maximum possible number of squares lighted by the lamp.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

S_i is a string of length W consisting of # and ..

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13



Sample input:
4 6
#..#..
.....#
....#.
#.#...


Sample output:
8

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))
    
def dfs(i, j):
    num = 1
    if i != h - 1:
        n = 0
        while i + n < h and s[i+n][j] != '#':
            n += 1
            num += 1
    if i != 0:
        n = 0
        while 0 <= i - n and s[i-n][j] != '#':
            n += 1
            num += 1
    if j != w - 1:
        n = 0
        while j + n < w and s[i][j+n] != '#':
            n += 1
            num += 1
    if j != 0:
        n = 0
        while 0 <= j - n and s[i][j-n] != '#':
            n += 1
            num += 1
    return num

max_ = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            ans = dfs(i, j)
            if ans > max_:
                max_ = ans

print(ans)

Submission status: Wrong Answer

Solution code:
def count_light(i, j):
  count = 1
  
  # 上方向
  k = i - 1
  while k >= 0:
    if S[k][j] == '.':
      count += 1
    k -= 1
  
  # 下方向
  k = i + 1
  while k < H:
    if S[k][j] == '.':
      count += 1
    k += 1
  
  # 右方向
  k = j + 1
  while k < W:
    if S[i][k] == '.':
      count += 1
    k += 1
  
  # 左方向
  k = j - 1
  while k >= 0:
    if S[i][k] == '.':
      count += 1
    k -= 1
  
  return count
    
H,W = (int(x) for x in input().split())
S = []
for i in range(H):
  S.append(list(input()))

max = 0
for i in range(H):
  for j in range(W):
    if not(S[i][j] == '#'):
      tmp = count_light(i, j)
      if (max < tmp):
        max = tmp

print(max)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6) 

H, W = map(int, input().split())
maze = [input() for i in range(H)]
ans = 0

def search1(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return 

    search1(x + 1, y, cnt + 1)
    return
def search2(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return 

    search2(x - 1, y, cnt + 1)
    return
def search3(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return 

    search3(x, y + 1, cnt + 1)
    return
def search4(x, y, cnt):
    global ans
    if x < 0 or W <= x or y < 0 or H <= y or maze[y][x] == '#':
        ans += cnt - 1
        return 

    search4(x, y - 1, cnt + 1)
    return
    
MAX = 0
for i in range(H):
    for j in range(W):
        search1(i, j, 0)
        search2(i, j, 0)
        search3(i, j, 0)
        search4(i, j, 0)
        MAX = max(ans + 1, MAX)
        ans = 0

print(MAX)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = map(int, input().split())

field = np.zeros((H,W))

for i in range(H):
    S = input().rstrip()
    for j in range(W):
        if S[j] == '#':
            field[i, j] = 1
        
lighted_max = 1
lighted_total = 0
for i in range(H): 
    row_slice = field[i,:]
    lighted_row = len( row_slice[row_slice == 0])
    for j in range(W):
        if field[i, j] == 1:
            continue

        col_slice = field[:, j]
        lighted_col = len(col_slice[col_slice == 0])
        lighted_total = lighted_row + lighted_col
        
        if lighted_total > lighted_max:
            lighted_max = lighted_total
        
print(lighted_max-1)

Submission status: Wrong Answer

Solution code:
#d.py
h,w = map(int,input().split())
slis = [input() for x in range(h)]
vy = [0,0,1,-1]
vx = [1,-1,0,0]

ans_lis = []
ma = 0
for ny in range(h):
    bef = 0
    y = slis[ny]
    cnt = 0
    lis = []
    for x in range(w):
        if y[x] == '.':
            cnt += 1
        elif y[x] == '#':
            if ma < cnt:
                ma = cnt
                ma_fla = x
                ma_bef = bef+1
            bef = x
            cnt = 0
    else:
        lis.append(cnt)
        if ma < cnt:
            ma = cnt
            ma_fla = x
            ma_bef = bef+1
ans = ma_fla - ma_bef
y_as = 0
for y in range(ma_bef,ma_fla):
    cnt = 0
    for x in range(h):
        ar = slis[x][y]
        if ar == '.':
            cnt += 1
        elif ar == '#':
            if y_as < cnt:
                y_as = cnt
            cnt = 0
    if y_as < cnt:
        y_as = cnt
ans += y_as      
#print('ans')
print(ans)
#print('len','#','#')
#print(ma,ma_bef,ma_fla)
#print(y_as)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
orimap = []
yoko = [[-1] for i in range(h)]
tate = [[-1] for i in range(w)]
for i in range(h):
    y = input()
    orimap.append(y)
    for j in range(w):
        if y[j] == "#":
            yoko[i].append(j)
            tate[j].append(i)
    yoko[i].append(w)
for i in range(len(tate)):
    tate[i].append(h)
best = 0
for i in range(h):
    for j in range(w):
        count = 0
        if orimap[i][j] == ".":
            for k in range(len(yoko[i])-1):
                if yoko[i][k] < j < yoko[i][k+1]:
                    count += yoko[i][k+1] - yoko[i][k] -1
            for k in range(len(tate[j])-1):
                if tate[j][k] < i < tate[j][k-1]:
                    count += tate[j][k+1] - tate[j][k] -1
        if count > best:
            best = count
print(best-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

h, w = map(int, input().split())

grid = []  # grid[h][w]
for _ in range(h):
    grid.append(list(map(lambda c: [c == "#", 0, 0], input())) + [[True, 0, 0]])
grid.append([[True, 0, 0]] * (w + 1))

buf = deque()
for y in range(h + 1):
    sight = 0
    buf.clear()
    for x in range(w + 1):
        if grid[y][x][0]:
            for i, j in buf:
                grid[j][i][1] = sight
            grid[y][x][1] = 0
            sight = 0
            buf.clear()
        else:
            buf.append((x, y))
            sight += 1

for x in range(w + 1):
    sight = 0
    buf.clear()
    for y in range(h + 1):
        if grid[y][x][0]:
            for i, j in buf:
                grid[j][i][2] = sight
            grid[j][i][2] = 0
            sight = 0
            buf.clear()
        else:
            buf.append((x, y))
            sight += 1

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(grid[y][x][1] + grid[y][x][2] - 1, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))
    
def dfs(i, j):
    num = 1
    n = 0
    while i + n < h and s[i+n][j] != '#':
        n += 1
        num += 1
    n = 0
    while 0 <= i - n and s[i-n][j] != '#':
        n += 1
        num += 1
    n = 0
    while j + n < w and s[i][j+n] != '#':
        n += 1
        num += 1
    n = 0
    while 0 <= j - n < w and s[i][j-n] != '#':
        n += 1
        num += 1
    return num

max_ = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            ans = dfs(i, j)
            if ans > max_:
                max_ = ans

print(ans)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)

Gh=[[0]*W for i in range(H)]
for i in range(H):
    tmp=0
    s=0
    j=0
    while(j!=W):
        if S[i][j]=="#":
            Gh[i][j]==0
            for k in range(s,j):
                Gh[i][k]=tmp
            s=j+1
            j+=1
            tmp=0
        else:
            tmp+=1
            j+=1
    if s!=j:
        for k in range(s,j):
            Gh[i][k]=tmp
Gv=[[0]*W for i in range(H)]
for j in range(W):
    tmp=0
    s=0
    i=0
    while(i!=H):
        if S[i][j]=="#":
            Gv[i][j]==0
            for k in range(s,i):
                Gv[k][j]=tmp
            s=i+1
            i+=1
            tmp=0
        else:
            tmp+=1
            i+=1
    if s!=j:
        for k in range(s,i):
            Gv[k][j]=tmp
ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,Gh[i][j]+Gv[i][j]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))
    
def dfs(i, j):
    num = 0
    n = 0
    while i + n < h and s[i+n][j] != '#':
        n += 1
        num += 1
    n = 0
    while 0 <= i - n and s[i-n][j] != '#':
        n += 1
        num += 1
    n = 0
    while j + n < w and s[i][j+n] != '#':
        n += 1
        num += 1
    n = 0
    while 0 <= j - n < w and s[i][j-n] != '#':
        n += 1
        num += 1
    return num

max_ = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            ans = dfs(i, j) + 1
            if ans > max_:
                max_ = ans

print(ans)

Submission status: Wrong Answer

Solution code:
H,W  = map(int, input().split())
table = []
for i in range(H):
    A = list(input())
    table.append(A)

H_max = [0]*W
H_tmp = [0]*W
# 列
W_max = 0
for i in range(H):
    W_tmp = 0
    for j in range(W):
        if table[i][j] == ".":
            H_tmp[j] += 1
            W_tmp += 1
        else:
            H_max[j] = max(H_tmp[j],H_max[j])
            W_max = max(W_max,W_tmp)
            H_tmp[j] = 0
            W_tmp = 0
    # 最後まで"."だったとき
    W_max = max(W_max,W_tmp)
# 最後まで"."だったとき
for j in range(W):
    H_max[j] = max(H_tmp[j],H_max[j])
    
print(max(H_max)+W_max-1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def main():
    H,W = ints_raw()
    Ss = ["#"+input()[:-1]+"#" for _ in range(H)]
    W = W+2
    H = H+2
    Ss = ["#"*W]+Ss+["#"*W]
    lenHor = [[0]*W for _ in range(H)]
    lenVer = [[0]*W for _ in range(H)]
    for h,S in enumerate(Ss):
        buf = 0
        last_idx = 1
        for idx,c in enumerate(S):
            if c == '#':
                for x in range(last_idx,idx-1):
                    lenHor[h][x] = buf
                buf =0
                last_idx = idx
            else:
                buf+=1
    
    for w in range(W):
        buf = 0
        last_idx = 1
        for idx in range(H):
            c = Ss[idx][w]
            if c == '#':
                for x in range(last_idx, idx-1):
                    lenVer[x][w] = buf
                buf = 0
                last_idx = idx
            else:
                buf += 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, max(lenVer[h][w]-1,0)+max(lenHor[h][w]-1,0)+1)
    return ans

print(main())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def solve(H: int, W: int, S: "List[str]"):
    tab = [0 for i in range(H*W)]
    for i in range(W):
        acc0, acc1 = 0, 0
        for j in range(H):
            j2 = H-1-j
            tab[W*j+i] += acc0
            tab[W*j2+i] += acc1
            acc0 = 0 if S[j][i] == "#" else acc0+1
            acc1 = 0 if S[j2][i] == "#" else acc1+1
    for j in range(H):
        acc2, acc3 = 0, 0
        for i in range(W):
            i2 = W-1-i
            tab[W*j+i] += acc2
            tab[W*j+i2] += acc3
            if S[j][i] != "#": tab[W*j+i] += 1
            acc2 = 0 if S[j][i] == "#" else acc2+1
            acc3 = 0 if S[j][i2] == "#" else acc3+1
    print(max(tab))

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w = list(map(int, input().split()))
ss = np.array([list(input()) for _ in range(h)])
print(ss)

ans = 0
ws = np.zeros((h, w))
hs = np.zeros((h, w))

i = 0
while i < h:
	j = 0
	while j < w:
		if ss[i, j] == ".":
			end = w
			for k in range(j, w):
				if ss[i, k] == "#":
					end = k
			ws[i, j:end] = end - j
			j = end + 1
		else:
			j += 1
	i += 1

j = 0
while j < w:
	i = 0
	while i < h:
		if ss[i, j] == ".":
			end = h
			for k in range(i, h):
				if ss[k, j] == "#":
					end = k
			hs[i:end, j] = end - i
			i = end + 1
		else:
			i += 1
	j += 1

#print(ws)
#print(hs)
print(int(np.amax(ws + hs) - 1))

Submission status: Wrong Answer

Solution code:

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()
grid = []
for i in range(H):
    grid.append(s())

yoko = [[0] * W for h in range(H)]
for row in range(H):
    prev = 0
    count = 0
    for col in range(W):
        if grid[row][col] == '#':
            for i in range(prev, col):
                yoko[row][i] = count
            prev = col+1
            count = 0
        else:
            count += 1
    for i in range(prev, W):
        yoko[row][i] = count

tate = [[0] * W for h in range(H)]
for col in range(W):
    prev = 0
    count = 0
    for row in range(H):
        if grid[row][col] == '#':
            for i in range(prev, row):
                tate[i][col] = count
            prev = col+1
            count = 0
        else:
            count += 1
    for i in range(prev, H):
        tate[i][col] = count

res = 0
for row in range(H):
    for col in range(W):
        res = max(res, yoko[row][col] + tate[row][col] - 1)

print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  r, c = map(int, input().split())
  g = [input().strip() for _ in range(r)]
  v = numpy.zeros((2, r, c), dtype=numpy.int)

  for y in range(r):
    s = 0
    for x in range(c):
      if g[y][x] == '#':
        v[0, y, s:x] = x - s
        s = x + 1

    v[0, y, s:] = c - s

  for x in range(c):
    s = 0
    for y in range(r):
      if g[y][x] == '#':
        v[1, s:y, x] = y - s
        s = x + 1

    v[1, s:, x] = r - s

  v = v[0] + v[1]

  print(numpy.max(v) - 1)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    [h, w] = li()
    s_list = [list(input()) for _ in range(h)]

    light_num = [[0] * w for _ in range(h)]
    # print([row[0] for row in s_list][2:])
    for hi in range(h):
        seq_len = {}
        for wi in range(w):
            if wi in seq_len:
                light_num[hi][wi] = light_num[hi][wi] + seq_len[wi]
            else:
                if s_list[hi][wi] == "#":
                    light_num[hi][wi] = light_num[hi][wi] - 4000
                else:
                    blank_num = 0
                    for s in s_list[hi][wi:]:
                        if s == ".":
                            blank_num = blank_num + 1
                        else:
                            break
                    light_num[hi][wi] = blank_num
                    for i in range(blank_num):
                        seq_len[wi + i] = blank_num
    for wi in range(w):
        seq_len = {}
        for hi in range(h):
            if hi in seq_len:
                light_num[hi][wi] = light_num[hi][wi] + seq_len[hi]
            else:
                if s_list[hi][wi] == "#":
                    light_num[hi][wi] = light_num[hi][wi] - 4000
                else:
                    blank_num = 0
                    for s in [row[wi] for row in s_list][hi:]:
                        if s == ".":
                            blank_num = blank_num + 1
                        else:
                            break
                    light_num[hi][wi] = blank_num
                    for i in range(blank_num):
                        seq_len[hi + i] = blank_num

    print(max(sum(light_num, [])) - 1)
    # print(s_list)
    # print(light_num)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())

s=[]
for _ in range(h):
    s.append(input())

max_row1=0
for i in range(h):
    tmp_row=0
    for j in range(w):
        if s[i][j]=='#':
            break
        else:
            tmp_row+=1
    if max_row1<tmp_row:
        max_row1=tmp_row
max_col1=0
for j in range(w):
    tmp_col=0
    for i in range(h):
        if s[i][j]=='#':
            break
        else:
            tmp_col+=1
    if max_col1<tmp_col:
        max_col1=tmp_col

max_row2=0
for i in range(h):
    tmp_row=0
    for j in reversed(range(w)):
        if s[i][j]=='#':
            break
        else:
            tmp_row+=1
    if max_row2<tmp_row:
        max_row2=tmp_row
max_col2=0
for j in range(w):
    tmp_col=0
    for i in reversed(range(h)):
        if s[i][j]=='#':
            break
        else:
            tmp_col+=1
    if max_col2<tmp_col:
        max_col2=tmp_col
ans=0
if max_col1>max_col2:
    ans+=max_col1
else:
    ans+=max_col2
if max_row1>max_row2:
    ans+=max_row1
else:
    ans+=max_row2

print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def main():
    H,W = ints_raw()
    Ss = ["#"+input()[:-1]+"#" for _ in range(H)]
    W = W+2
    H = H+2
    Ss = ["#"*W]+Ss+["#"*W]
    lenHor = [[0]*W for _ in range(H)]
    lenVer = [[0]*W for _ in range(H)]
    for h,S in enumerate(Ss):
        buf = 0
        last_idx = 1
        for idx,c in enumerate(S):
            if c == '#':
                for x in range(last_idx,idx-1):
                    lenHor[h][x] = buf
                buf =0
                last_idx = idx
            else:
                buf+=1
    
    for w in range(W):
        buf = 0
        last_idx = 1
        for idx in range(H):
            c = Ss[idx][w]
            if c == '#':
                for x in range(last_idx, idx-1):
                    lenVer[x][w] = buf
                buf = 0
                last_idx = idx
            else:
                buf += 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, lenVer[h][w]+lenHor[h][w]-1)
    return ans

print(main())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def solve(H: int, W: int, S: "List[str]"):
    tab = [[0,0,0,0,0] for i in range(H*W)]
    for i in range(W):
        acc0, acc1 = 0, 0
        for j in range(H):
            j2 = H-1-j
            tab[W*j+i][0] = acc0
            tab[W*j2+i][1] = acc1
            acc0 = 0 if S[j][i] == "#" else acc0+1
            acc1 = 0 if S[j2][i] == "#" else acc1+1
    for j in range(H):
        acc2, acc3 = 0, 0
        for i in range(W):
            i2 = W-1-i
            tab[W*j+i][2] = acc2
            tab[W*j+i2][3] = acc3
            tab[W*j+i][4] = 0 if S[j][i] == "#" else 1
            acc2 = 0 if S[j][i] == "#" else acc2+1
            acc3 = 0 if S[j][i2] == "#" else acc3+1
    print(max([sum(t) for t in tab]))

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
s = [input() for j in range(H)]

def counter(x, y):
    count = 1
    h1 = x - 1
    while h1 >= 0 and s[h1][y] == ".":
        count += 1
        h1 -= 1
    
    h2 = x + 1
    while h2 < H and s[h2][y] == ".":
        count += 1
        h2 += 1
    
    w1 = y -1
    while w1 >= 0 and s[x][w1] == ".":
        count += 1
        w1 -= 1
    
    w2 = y + 1
    while w2 < W and s[x][w2] == ".":
        count += 1
        w2 += 1
    
    return count

c = []
for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            c.append(counter(i, j))

print(c)
print(max(c))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
L=[[0 for i in range(w)] for i in range(h)]
x=0;ct=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      if ct==0:
        x=j
      ct+=1
    if ct!=0 and (s[i][j]=='#' or j==w-1):
      for k in range(ct):
        L[i][x+k]+=ct
      ct=0

for j in range(w):
  for i in range(h):
    if s[i][j]=='.':
      if ct==0:
        x=i
      ct+=1
    if ct!=0 and (s[i][j]=='#' or i==h-1):
      for k in range(ct):
        L[x+k][j]+=ct
      ct=0
print(max(max(L))-1)

Submission status: Wrong Answer

Solution code:
def right(MAP, X, Y, W, H):
    ret = 0
    for i in range(X+1, W):
        if c[Y][i] == '#':
            break
        ret += 1
    return ret

def left(MAP, X, Y, W, H):
    ret = 0
    for i in range(X):
        if c[Y][X-i-1] == '#':
            break
        ret += 1
    return ret

def up(MAP, X, Y, W, H):
    ret = 0
    for i in range(Y):
        if c[Y-i-1][X] == '#':
            break
        ret += 1
    return ret

def down(MAP, X, Y, W, H):
    ret = 0
    for i in range(Y+1, H):
        if c[Y][X] == '#':
            break
        ret += 1
    return ret

h, w = map(int, input().split())
c = [[char for char in input()] for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            continue
        r = right(c, j, i, w, h)
        l = left(c, j, i, w, h)
        u = up(c, j, i, w, h)
        d = down(c, j, i, w, h)
        ans = max(ans, r+l+u+d+1)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())

s=[]
for _ in range(h):
    s.append(input())

max_row1=0
for i in range(h):
    tmp_row=0
    for j in range(w):
        if s[i][j]=='#':
            break
        else:
            tmp_row+=1
    if max_row1<tmp_row:
        max_row1=tmp_row
max_col1=0
for j in range(w):
    tmp_col=0
    for i in range(h):
        if s[i][j]=='#':
            break
        else:
            tmp_col+=1
    if max_col1<tmp_col:
        max_col1=tmp_col

max_row2=0
for i in range(h):
    tmp_row=0
    for j in reversed(range(w)):
        if s[i][j]=='#':
            break
        else:
            tmp_row+=1
    if max_row2<tmp_row:
        max_row2=tmp_row
max_col2=0
for j in range(w):
    tmp_col=0
    for i in reversed(range(h)):
        if s[i][j]=='#':
            break
        else:
            tmp_col+=1
    if max_col2<tmp_col:
        max_col2=tmp_col

if (max_col1+max_row1-1)>(max_col2+max_row2-1):
    print(max_col1+max_row1-1)
else:
    print(max_col2+max_row2-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def solve():
    H, W = map(int, input().split())
    S = [list(input())for _ in range(H)]
    Map = [[0]*W for _ in range(H)]
    Map1 = [[0]*W for _ in range(H)]
    for i in range(H):
        if S[i][0]=='.':
            Map[i][0]=1
        for j in range(1, W):
            if S[i][j]=='.':
                Map[i][j]=Map[i][j-1]+1
        tmp=0
        for j in range(W)[::-1]:
            if Map[i][j]>0:
                if tmp==0:
                    tmp = Map[i][j]
                Map[i][j]=tmp
            else:
                tmp = 0
    for i in range(W):
        if S[0][i]=='.':
            Map1[0][i]=1
        for j in range(H):
            if S[j][i]=='.':
                Map1[j][i]=Map1[j-1][i]+1
        tmp = 0
        for j in range(H)[::-1]:
            if Map1[j][i]>0:
                if tmp==0:
                    tmp = Map1[j][i]
                Map1[j][i]=tmp
            else:
                tmp = 0
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, Map[i][j]+Map1[i][j])
    print(ans-1)
        
solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):
    tab = [[0,0,0,0,0] for i in range(H*W)]
    for i in range(W):
        acc0, acc1 = 0, 0
        for j in range(H):
            j2 = H-1-j
            tab[W*j+i][0] = acc0
            tab[W*j2+i][1] = acc1
            acc0 = 0 if S[j][i] == "#" else acc0+1
            acc1 = 0 if S[j2][i] == "#" else acc1+1

    for j in range(H):
        acc2, acc3 = 0, 0
        for i in range(W):
            i2 = W-1-i
            tab[W*j+i][2] = acc2
            tab[W*j+i2][3] = acc3
            acc2 = 0 if S[j][i] == "#" else acc2+1
            acc3 = 0 if S[j][i2] == "#" else acc3+1

    for j in range(H):
        for i in range(W):
            tab[W*j+i][4] = 0 if S[j][i] == "#" else 1

    #for j in range(1,H):
    #    print(tab[W*(j-1):W*j])
            
    print(max([sum(t) for t in tab]))

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H, W = [int(c) for c in input().split()]
S = [input() for _ in range(H)]

dL = [[0 for _ in range(W)] for _ in range(H)]
dR = [[0 for _ in range(W)] for _ in range(H)]

dU = [[0 for _ in range(W)] for _ in range(H)]
dD = [[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
    ml = -1
    for w in range(W):
        if S[h][w]=='.':
            dL[h][w] = w-ml
        else:
            ml=w
            
    mr = W
    for w in range(W-1, -1, -1):
        if S[h][w]=='.':
            dR[h][w] = mr-w
        else:
            mr=w

for w in range(W):
    mu = -1
    for h in range(H):
        if S[h][w]=='.':
            dU[h][w] = h-mu
        else:
            mu=h
            
    md = H
    for h in range(H-1, -1, -1):
        if S[h][w]=='.':
            dD[h][w] = md-h
        else:
            mr=h

max_lite = -1
for h in range(H):
    for w in range(W):
        max_lite = max(max_lite, dL[h][w] + dR[h][w] + dU[h][w] + dD[h][w] -3 )

print(max_lite)

Submission status: Wrong Answer

Solution code:
def main():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    points = [[0 for _ in range(w)] for _ in range(h)]

    for i in range(h):
        left = 0
        for j in range(w):
            if field[i][j] == '#':
                for k in range(left, j):
                    points[i][k] += j-left
                left = j+1
                continue
        for k in range(left, w):
            points[i][k] += w-left

    #print("\n".join(str(point) for point in points))
    for j in range(w):
        up = 0
        for i in range(h):
            if field[i][j] == '#':
                for k in range(up, i):
                    points[k][j] += i-up
                up = i+1
                continue
        for k in range(h):
            points[k][j] += h-up

    psoudo_ans = max(max(line) for line in points)
    print(max(0, psoudo_ans-1))
    #print("\n".join(str(point) for point in points))


main()

Submission status: Wrong Answer

Solution code:
H,W  = map(int, input().split())
grid_h = []
grid_w = []
grid = []
for i in range(H):
    S = input()
    grid_h.append(max([len(i) for i in S.split('#')]))
    grid.append(S)
for i in range(W):
    tmp = ''.join([s[i] for s in grid])
    grid_w.append(max([len(i) for i in tmp.split('#')]))
print(max(grid_h) + max(grid_w)-1)

Submission status: Wrong Answer

Solution code:
import numpy as np


R, C = map(int, input().split())
F = [0] * R
R_no_obstacle = [0] * R
C_no_obstacle = [0] * C

for i in range(R):
    s = input()
    F[i] = list(s)
    tmp = s.split("#")
    R_no_obstacle[i] = max([len(t) for t in tmp])

for j in range(C):
    s = "".join([F[i][j] for i in range(R)])
    tmp = s.split("#")
    C_no_obstacle[j] = max([len(t) for t in tmp])

R_no_obstacle_ind = np.argsort(R_no_obstacle)[::-1]
C_no_obstacle_ind = np.argsort(C_no_obstacle)[::-1]

r = 0
c = 0



while True:
    i = R_no_obstacle_ind[r]
    j = C_no_obstacle_ind[c]

    if F[i][j] == ".":
        print(R_no_obstacle[i] + C_no_obstacle[j] - 1)
        break
    else:
        if r == R - 1:
            if c == C - 1:
                print(0)
                break
            else:
                c += 1
        elif c == C - 1:
            r += 1
        else:
            if R_no_obstacle[R_no_obstacle_ind[r+1]] + C_no_obstacle[C_no_obstacle_ind[c]] >= R_no_obstacle[R_no_obstacle_ind[r]] + C_no_obstacle[C_no_obstacle_ind[c+1]]:
                r += 1
            else:
                c += 1