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:
#coding:utf-8
#R[i][j]:i行j列目に光を置いた時右に伸びる光の長さ
H,W = list(map(int,input().split()))
S = [0] * (H+2)
wall = ''
for _ in range(W+2):
    wall += '#'
S[0] = wall
S[H+1] = wall
for h in range(H):
    S[h+1] = '#' + input() + '#'
#print(S)
# R = [[0] * (W+2) for _ in range(H+2)]
# L = [[0] * (W+2) for _ in range(H+2)]
# U = [[0] * (W+2) for _ in range(H+2)]
# D = [[0] * (W+2) for _ in range(H+2)]
dp = [[0] * (W+2) for _ in range(H+2)]
start = 0
maxdp = 1
for h in range(1,H+1):
    flag = False
    for w in range(W+2):
        if S[h][w] == '#' :
            if flag == False :
                start = w
            else:
                for i in range(start+1,w):
                    dp[h][i] += w - i - 1
                    dp[h][i] += i - start - 1
                    if dp[h][i] > maxdp:
                        maxdp = dp[h][i]
                    flag = False
                start = w
        else:
            flag = True
for w in range(1,W+1):
    for h in range(H+2):
        if S[h][w] == '#':
            if flag == False:
                start = h
            else:
                for i in range(start+1,h):
                    dp[i][w] += h - i - 1
                    dp[i][w] += i - start -1
                    if dp[i][w] > maxdp:
                        maxdp = dp[i][w]
                    flag = False
                start = h
        else:
            flag = True
print(maxdp+1)

Submission status: Wrong Answer

Solution code:
h, w = [int(x) for x in input().split()]
s = [input() for x in range(h)]
l = [[0 for j in range(w)] for i in range(h)]
r = [[w for j in range(w)] for i in range(h)]
u = [[0 for j in range(w)] for i in range(h)]
d = [[h for j in range(w)] for i in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      l[i][j] = j
      if (j > 0) and (s[i][j-1] == '.'):
        l[i][j] = l[i][j-1]
      u[i][j] = i
      if (i > 0) and (s[i-1][j] == '.'):
        u[i][j] = u[i-1][j]
        
for i in range(h-1, -1, -1):
  for j in range(w-1, -1, -1):
    if s[i][j] == '#':
      r[i][j] = j
      d[i][j] = j
    else:
      if j < w - 1:
        r[i][j] = r[i][j+1]
      if i < h - 1:
        d[i][j] = d[i+1][j]
        
ans = 0
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
    	ans = max(ans, r[i][j] - l[i][j] + d[i][j] - u[i][j] - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	H, W = map(int, input().split(" "))
	S = []
	for i in range(H):
		s = list(input())
		S.append(s)
	
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			side = get_side(S[i], i)
			
			V = []
			for x in range(H):
				v = S[x][j]
				V.append(v)
			varti = get_side(V, j)
			
			tmp = side + varti
			tmp -= 1
			if tmp > ans:
				ans = tmp
				
			#print("{} {} -> {} {}".format(i, j, side, varti))
				
	print(ans)
	
def get_side(S, k):
	ret = 0
	flg = False
	
	for i, val in enumerate(S):
		if val == ".":
			ret += 1
		elif val == "#" and flg == False:
			ret = 0
		elif val == "#" and flg == True:
			return ret
			
		if i == k:
			flg = True
			
	return ret
	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
hw = list(map(int, input().split()))
# "."は障害物なし、"#"は障害物
s = [input() for l in range(hw[0])]
result = 0

# 各方向ごとの照らせるマス数を座標ごとに少ない計算量で事前計算することで、総計算量を定量的にする
L = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]):
    for j in range(hw[1]):
        if s[i][j] != "#":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
                
R = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]):
    for j in range(hw[1]-1, 0, -1):
        if s[i][j] != "#":
            if j == hw[1]-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1]+1
                
U = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]):
    for j in range(hw[1]):
        if s[i][j] != "#":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j]+1
                
D = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]-1, 0, -1):
    for j in range(hw[1]):
        if s[i][j] != "#":
            if i == hw[0]-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j]+1
                
# 4方向の明かりの合計値の最大を抽出
for i in range(hw[0]):
    for j in range(hw[1]):
        if s[i][j] != "#":
            tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            if result < tmp:
                result = tmp
                
print(result)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
s_Blank_matrix = []
s_Blank_column = []

for i in range(h):
    s_max = 0
    s_count = 0
    for j in range(w):
        if s[i][j] != '#':
            s_count += 1
        elif s[i][j] == '#':
            s_max = max(s_max, s_count)
            if s_max > w - j:
                break
            s_count = 0
    s_max = max(s_max, s_count)
    s_Blank_matrix.append(s_max)

for i in range(w):
    s_max = 0
    s_count = 0
    for j in range(h):
        if s[j][i] != '#':
            s_count += 1
        elif s[j][i] == '#':
            s_max = max(s_max, s_count)
            if s_max > h - j:
                break
            s_count = 0
    s_max = max(s_max, s_count)
    s_Blank_column.append(s_max)

print(max(s_Blank_matrix) + max(s_Blank_column) - 1)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
s_Blank_matrix = []
s_Blank_column = []

for i in range(h):
    s_max = 0
    s_count = 0
    for j in range(w):
        if s[i][j] != '#':
            s_count += 1
        elif s[i][j] == '#':
            s_max = max(s_max, s_count)
            s_count = 0
    s_max = max(s_max, s_count)
    s_Blank_matrix.append(s_max)

for i in range(w):
    s_max = 0
    s_count = 0
    for j in range(h):
        if s[j][i] != '#':
            s_count += 1
        elif s[j][i] == '#':
            s_max = max(s_max, s_count)
            s_count = 0
    s_max = max(s_max, s_count)
    s_Blank_column.append(s_max)

# print(s_Blank_matrix)
# print(s_Blank_column)
print(max(s_Blank_matrix) + max(s_Blank_column) - 1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate


def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    t = [[1 if __s == "#" else 0 for __s in _s] for _s in s]
    hi = [list(accumulate(_t)) for _t in t]
    vi = [list(accumulate(_t)) for _t in zip(*t)]
    hg = [list(map(len, _s.split("#"))) for _s in s]
    vg = [list(map(len, "".join(_s).split("#"))) for _s in zip(*s)]
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
    return str(ans - 1)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

yoko = []
for v in s:
    v.append('-')
    tmp = []
    nc =v[0]
    nn = 0
    for c in v:
        if nc == c:
            nn += 1
            continue
        else:
            if nc == '#':
                tmp = tmp + [0 for _ in range(nn)]
            else:
                tmp = tmp + [nn for _ in range(nn)]
            nc = c
            nn = 1
    yoko.append(tmp)

tate = []
for j in range(w):
    tmp = []
    nc = s[0][j]
    nn = 0
    for i in range(h):
        if nc == c:
            nn += 1
            continue
        else:
            if nc == '#':
                tmp = tmp + [0 for _ in range(nn)]
            else:
                tmp = tmp + [nn for _ in range(nn)]
            nc = c
            nn = 1
    if nc == '#':
        tmp = tmp + [0 for _ in range(nn)]
    else:
        tmp = tmp + [nn for _ in range(nn)]
    tate.append(tmp)

print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys


class UnionFind:

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]


# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

columns = UnionFind(W*H)
rows = UnionFind(W*H)

# init columns
for row in range(H):
    for col1, col2 in zip(range(W), range(1, W)):
        if grid[row][col1] == "." and grid[row][col2] == ".":
            columns.union(row*W+col1, row*W+col2)

# init rows:
for col in range(W):
    for row1, row2 in zip(range(H), range(1, H)):
        if grid[row1][col] == "." and grid[row2][col] == ".":
            rows.union(row1*W+col, row2*W+col)

ans = 0
for row in range(H):
    for col in range(W):
        if grid[row][col] == ".":
            tmp = rows.get_size(row)+columns.get_size(col)-1
            ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys


class UnionFind:

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.parent[x]]


# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

columns = UnionFind(W*H)
rows = UnionFind(W*H)

# init columns
for row in range(H):
    for col1, col2 in zip(range(W), range(1, W)):
        if grid[row][col1] == "." and grid[row][col2] == ".":
            columns.union(row*W+col1, row*W+col2)

# init rows:
for col in range(W):
    for row1, row2 in zip(range(H), range(1, H)):
        if grid[row1][col] == "." and grid[row2][col] == ".":
            rows.union(row1*W+col, row2*W+col)

ans = 0
for row in range(H):
    for col in range(W):
        if grid[row][col] == ".":
            tmp = rows.get_size(row)+columns.get_size(col)-1
            ans = max(ans, tmp)
print(rows.size)
print(columns.size)
print(ans)

Submission status: Wrong Answer

Solution code:
# # -*- coding: utf-8 -*-
import sys


class UnionFind:

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.parent[x]]


# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

columns = UnionFind(W*H)
rows = UnionFind(W*H)

# init columns
for row in range(H):
    for col1, col2 in zip(range(W), range(1, W)):
        if grid[row][col1] == "." and grid[row][col1] == grid[row][col2]:
            columns.union(row*W+col1, row*W+col2)

# init rows:
for col in range(W):
    for row1, row2 in zip(range(H), range(1, H)):
        if grid[row1][col] == "." and grid[row1][col] == grid[row2][col]:
            rows.union(row1*W+col, row2*W+col)

ans = 0
for row in range(H):
    for col in range(W):
        if grid[row][col] == ".":
            tmp = rows.get_size(row)*columns.get_size(col)
            ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys


class UnionFind:

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.parent[x]]


# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

columns = UnionFind(W*H)
rows = UnionFind(W*H)

# init columns
for row in range(H):
    for col1, col2 in zip(range(W), range(1, W)):
        if grid[row][col1] == "." and grid[row][col1] == grid[row][col2]:
            columns.union(row*W+col1, row*W+col2)

# init rows:
for col in range(W):
    for row1, row2 in zip(range(H), range(1, H)):
        if grid[row1][col] == "." and grid[row1][col] == grid[row2][col]:
            rows.union(row1*W+col, row2*W+col)

ans = 0
for row in range(H):
    for col in range(W):
        tmp = rows.get_size(row)*columns.get_size(col)
        ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math, heapq
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

H, W = read_int()
grid = []
import numpy as np
L = np.zeros((H, W))
R = np.zeros((H, W))
U = np.zeros((H, W))
D = np.zeros((H, W))
res = np.zeros((H, W))
# L = [[0 for _ in range(W)] for _ in range(H)]
# R = [[0 for _ in range(W)] for _ in range(H)]
# U = [[0 for _ in range(W)] for _ in range(H)]
# D = [[0 for _ in range(W)] for _ in range(H)]
# res = [[0 for _ in range(W)] for _ in range(H)]

for _ in range(H):
    row = list(" ".join(input()).split())
    grid.append(row)

# r = []
# heapq.heapify(r)
# for i in range(H * W):
#     heapq.heappush(r, 0)
# r = [3 for i in range(H*W)]
def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == "#":
                L[i][j] = U[i][j] = 0
            else:
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)
                # r[i* W + j] -= L[i][j] + U[i][j]

            if grid[H - i - 1][W - j - 1] == "#":
                R[H - i - 1][W - j - 1] = D[H - i - 1][W - j - 1] = 0
            else:
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
                # r[i* W + j] -= R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
    # print(res)
    return ans - 3

# if __name__ == "__main__":
#     print(solve())

if __name__ == "__main__":
    import timeit
    loop = 1
    n = 1000
    time = timeit.timeit(lambda: solve(), number=loop)
    print(time/loop)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s=[]
for i in range(h):
  s.append(list(input()))

hidari=[[0 for i in range(w)] for j in range(h)]
migi=[[0 for i in range(w)] for j in range(h)]
ue=[[0 for i in range(w)] for j in range(h)]
sita=[[0 for i in range(w)] for j in range(h)]

for j in range(h):
  ct1=0
  ct2=0
  for i in range(w):
    if s[j][i]=="#":
      ct1=0
      hidari[j][i]=0
    else:
      ct1+=1
      hidari[j][i]=ct1
    if s[j][w-1-i]=="#":
      ct2=0
      migi[j][w-1-i]=0
    else:
      ct2+=1
      migi[j][w-1-i]=ct2

mx=0
for i in range(w):
  ct1=0
  ct2=0
  for j in range(h):
    if s[h-j-1][i]=="#":
      ct1=0
      sita[h-j-1][i]=0
    else:
      ct1+=1
      sita[h-j-1][i]=ct2
    if s[j][i]=="#":
      ct2=0
      ue[j][i]=0
    else:
      ct2+=1
      ue[j][i]=ct2
for i in range(w):
  for j in range(h):
    mx=max(mx,hidari[j][i]+migi[j][i]+ue[j][i]+sita[j][i])
print(mx-3)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s=[]
for i in range(h):
  s.append(list(input()))

hidari=[[0 for i in range(w)] for j in range(h)]
migi=[[0 for i in range(w)] for j in range(h)]
ue=[[0 for i in range(w)] for j in range(h)]
sita=[[0 for i in range(w)] for j in range(h)]

for j in range(h):
  ct1=0
  ct2=0
  for i in range(w):
    if s[j][i]=="#":
      ct1=0
      hidari[j][i]=0
    else:
      ct1+=1
      hidari[j][i]=ct1
    if s[j][w-1-i]=="#":
      ct2=0
      migi[j][w-1-i]=0
    else:
      ct2+=1
      migi[j][w-1-i]=ct2

mx=0
for i in range(w):
  ct1=0
  ct2=0
  for j in range(h):
    if s[h-j-1][i]=="#":
      ct1=0
      sita[h-j-1][i]=0
    else:
      ct1+=1
      sita[h-j-1][i]=ct2
    if s[j][i]=="#":
      ct2=0
      ue[j][i]=0
    else:
      ct2+=1
      ue[j][i]=ct2
    mx=max(mx,hidari[j][i]+migi[j][i]+ue[j][i]+sita[j][i])
print(mx-3)

Submission status: Wrong Answer

Solution code:
#ABC129D-Lamp.py

#import list
from sys import stdin, setrecursionlimit
from functools import lru_cache
import numpy as np

input = stdin.readline
setrecursionlimit(1000)

#constant
H, W = list(map(int,input().split()))
S = [input() for _ in range(H)]

#variable

#function
#@lru_cache(maxsize=None)

#class

#main function
def main():
    L = np.zeros((H,W))
    R = np.zeros((H,W))
    U = np.zeros((H,W))
    D = np.zeros((H,W))

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] = 0
            elif S[i][j] == ".":
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j-1] + 1

            if S[i][W-j-1] == "#":
                R[i][W-j-1] = 0
            elif S[i][W-j-1] == ".":
                if j == 0:
                    R[i][W-j-1] = 1
                else:
                    R[i][W-j-1] = R[i][W-j] + 1

            if S[i][j] == "#":
                U[i][j] = 0
            elif S[H-i-1][j] == ".":
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i-1][j]

            if S[H-i-1][j] == "#":
                D[H-i-1][j] = 0
            elif S[H-i-1][j] == ".":
                if i == 0:
                    D[H-i-1][j] = 1
                else:
                    D[H-i-1][j] = D[H-i][j] + 1

    maxScore = 0
    for i in range(H):
        for j in range(W):
            score = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
            if score > maxScore:
                maxScore = score
    print(maxScore)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
whole = [input() for _ in range(h)]
result = []
for hi in range(h):
  old = whole[hi]
  now = 0
  tmp = 0
  new = []
  while now < w:
    if old[now] == '#':
      new += [tmp]*tmp
      new += [0]
    else:
      tmp += 1
    now += 1
  new += [tmp]*tmp
  result.append(new)
print(result)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    S_list[h] = list(input())


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    for w in range(W):
        left_index = w
        right_index = W - w - 1

        #left
        if S_list[h][left_index] != '#':
            if left_index == 0:
                l_list[h][left_index] = 1
            else:
                l_list[h][left_index] = l_list[h][left_index - 1] + 1

        #right
        if S_list[h][right_index] != '#':
            if right_index == W - 1:
                r_list[h][right_index] = 1
            else:
                r_list[h][right_index] = r_list[h][right_index + 1] + 1


for w in range(W):
    for h in range(H):
        up_index = h
        down_index = H - h - 1
        #up
        if S_list[h][w] != '#':
            if up_index == 0:
                u_list[up_index][w] = 1
            else:
                u_list[up_index][w] = u_list[up_index - 1][w] + 1

        if S_list[h][w] != '#':
            if down_index == H - 1:
                d_list[down_index][w] = 1
            else:
                d_list[down_index][w] = d_list[down_index + 1][w] + 1


max_right = 0
for h in range(H):
    for w in range(W):
        rights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_right = max(max_right, rights)

print(max_right)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())

f = [list(input()) for _ in range(H)]

tmp = []
for i in range(H):
    for j in range(W):
        count = 0
        if f[i][j] == '.':
            count+=1
            I,J = i,j
            while j+1 <= W-1:
                if f[i][j+1] == '.':
                    count += 1
                    j += 1
                else:
                    break
                
            j = J
            while j-1 >= 0:
                if f[i][j-1] == '.':
                    count += 1
                    j -= 1
                else:
                    break
            j = J
            
            while i+1 <= H-1:
                if f[i+1][j] == '.':
                    count += 1
                    i += 1
                else:
                    break
            
            i = I
            
            while i-1 >= 0:
                if f[i-1][j] == '.':
                    count += 1
                    i -= 1
                else:
                    break
            
            tmp.append(count)
                
print(max(tmp))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

H, W = list(map(int, input().split()))
# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
A = [""]*H 
#INF = np.Inf
INF = 2000

#D = np.zeros((H+1, W+1))
D = [[0]*(W+1)]*(H+1)

for h in range(H):
    A[h] = input()
    for w in range(W):
        if A[h][w] == '.':
            D[h][w] = 1           

def main(): 
    #G = np.zeros((H+1, W+1))
    #T = np.zeros((H+1, W+1)) # 自分以外横に何マスつながっているか
    #Y = np.zeros((H+1, W+1)) # 自分以外縦に何マスつながっているか
    T = [[0]*(W+1)]*(H+1)
    Y = [[0]*(W+1)]*(H+1)
    
    for h in range(H):
        cnt = 0
        for w in range(W):
            if D[h][w] == 0:
                cnt = 0
                continue
            else:
                Y[h][w] += cnt
                cnt+=1    
    for h in range(H):
        for w in reversed(range(W)):
            if D[h][w] == 0:
               continue
            else:
               Y[h][w] = max(Y[h][w], Y[h][w+1])                           
            
    for w in range(W):
        cnt = 0
        for h in range(H):
            if D[h][w] == 0:
                cnt = 0
                continue
            else:
                T[h][w] += cnt
                cnt+=1
    for w in range(W):
        for h in reversed(range(H)):
            if D[h][w] == 0:
                continue
            else:
                T[h][w] = max(T[h][w], T[h+1][w])
    #G = D+Y+T
    #res = np.amax(G)
    res = 0
    for w in range(W):
        for h in range(H):
            res = max(res, D[h][w]+Y[h][w]+T[h][w])
    print(int(res))
            
            
                

    
if __name__ == '__main__':
    main()