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=[]
d=[]
ans=0
for i in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            d.append((i,j))
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            l,r=-1,w-1
            t,u=-1,h-1
            tmp=0
            for x,y in d:
                if x==i:
                    if l<y<j:
                        l=y
                    if j<y<r:
                        r=y
                if y==j:
                    if t<x<i:
                        t=x
                    if i<x<u:
                        u=x
            tmp=r-l+u-t-1
            if tmp>ans:
                ans=tmp
print(ans)

Submission status: Wrong Answer

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

for j in range(H):
    for i in range(W):
        if L[j][i] !="#":
            cnt =0
            nj = j
            while  0<=nj < H:
                if nj+1<H and L[nj+1][i] !="#":
                    cnt +=1
                else:
                    break
                nj+=1
            nj = j
            while  0<=nj < H:
                if 0<=nj+1<H and L[nj+1][i] !="#":
                    cnt +=1
                else:
                    break
                nj-=1
        
            ni = i
            while  0<=ni < W:
                if ni+1<W and L[j][ni+1] !="#":
                    cnt +=1
                else:
                    break
                ni+=1

            ni = i
            while  0<=ni < W:
                if ni+1<W and L[j][ni+1] !="#":
                    cnt +=1
                else:
                    break
                ni-=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = ["#" * w] + ["w" + read() + "w" for _ in range(h)] + ["w" * w]
    left = [[0] * (w + 2) for _ in range(h + 2)]
    right = [[0] * (w + 2) for _ in range(h + 2)]
    up = [[0] * (w + 2) for _ in range(h + 2)]
    down = [[0] * (w + 2) for _ in range(h + 2)]
    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if s[y][x] == ".":
                left[y][x] = left[y][x - 1] + 1
                up[y][x] = up[y - 1][x] + 1
            if s[-y - 1][-x - 1] == ".":
                right[-y - 1][-x - 1] = right[-y - 1][-x] + 1
                down[-y - 1][-x - 1] = down[-y][-x - 1] + 1
    c = 0
    for y in range(h):
        for x in range(w):
            c = max(left[y][x] + right[y][x] + up[y][x] + down[y][x], c)
    print(c - 3)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(list(input()))
L = R = D = U = [[] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            L[i].append(0)
        elif j == 0:
            L[i].append(1)
        else:
            L[i].append(L[i][-1] + 1)
for i in range(H):
    for j in range(-1,-W-1,-1):
        if S[i][j] == '#':
            R[i].insert(0,0)
        elif j == -1:
            R[i].append(1)
        else:
            R[i].insert(0,R[i][0] + 1)
for i in range(W):
    for j in range(H):
        if S[j][i] == '#':
            U[j].append(0)
        elif j == 0:
            U[j].append(1)
        else:
            U[j].append(U[j-1][-1] + 1)
for i in range(W):
    for j in range(-1,-H-1,-1):
        if S[j][i] == '#':
            D[j].append(0)
        elif j == -1:
            D[j].append(1)
        else:
            D[j].append(D[j+1][-1] + 1)
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(list(input()))
L = [[] for _ in range(H)]
R = L
D = L
U = L
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            L[i].append(0)
        elif j == 0:
            L[i].append(1)
        else:
            L[i].append(L[i][-1] + 1)
for i in range(H):
    for j in range(-1,-W-1,-1):
        if S[i][j] == '#':
            R[i].insert(0,0)
        elif j == -1:
            R[i].append(1)
        else:
            R[i].insert(0,R[i][0] + 1)
for i in range(W):
    for j in range(H):
        if S[j][i] == '#':
            U[j].append(0)
        elif j == 0:
            U[j].append(1)
        else:
            U[j].append(U[j-1][-1] + 1)
for i in range(W):
    for j in range(-1,-H-1,-1):
        if S[j][i] == '#':
            D[j].append(0)
        elif j == -1:
            D[j].append(1)
        else:
            D[j].append(D[j+1][-1] + 1)
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
area = []
area.append("#"*W)
for i in range(H):
    area.append("#"+input()+"#")
area.append("#"*W)

def func(x, y, area):
    cnt = 0
   
    for i in range(x, H+1):
        if(area[i][y] == "."):
            cnt += 1
    for ii in range(x-1, 0, -1):
        if(area[ii][y] == "."):
            cnt += 1
        else:
            break
                
    for j in range(y+1, W+1):
        if(area[x][j] == "."):
            cnt += 1
        else:
            break
    for jj in range(y-1, 0, -1):
        if(area[x][jj] == "."):
            cnt += 1
        else:
            break
            
    return cnt    
        
ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if(area[i][j] == "#"):
            continue
        ans = max(ans, func(i, j, area))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


H, W = map(int, input().split())
field = [[c == "." for c in input()] for _ in range(H)]
field = np.array(field, dtype=np.int16)

u = field.copy()
d = field.copy()
l = field.copy()
r = field.copy()

for i in range(1, H):
    u[i] = (u[i - 1] + 1) * u[i]
    d[-i - 1] = (d[-i] + 1) * d[-i - 1]

for j in range(1, W):
    l[:, j] = (l[:, j - 1] + 1) * l[:, j]
    r[:, -j - 1] = (d[:, -j] + 1) * r[:, -j - 1]

print((u + d + l + r - 3).max())

Submission status: Wrong Answer

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

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

field = [list(f) for f in s]

from copy import deepcopy

dist = [[[0]*2 for _ in range(w)] for _ in range(h)]

res = 0

for x in range(h):
    for y in range(w):
        if field[x][y] == '.' and not dist[x][y][0]:
            tmp = 1
            for dx in [-1, 1]:
                nx = x + dx
                while 0 <= nx and nx < h and field[nx][y] == '.':
                    tmp += 1
                    # x方向にdx, y方向にdy移動した場所を(nx, ny)とする
                    nx += dx
            for dx in [-1, 1]:
                nx = x + dx
                while 0 <= nx and nx < h and field[nx][y] == '.':
                    dist[nx][y][0] = tmp
                    # x方向にdx, y方向にdy移動した場所を(nx, ny)とする
                    nx += dx
        if field[x][y] == '.' and not dist[x][y][1]:
            tmp = 1
            for dy in [-1, 1]:
                ny = y + dy
                while 0 <= ny and ny < w and field[x][ny] == '.':
                    tmp += 1
                    # x方向にdx, y方向にdy移動した場所を(nx, ny)とする
                    ny += dy
            for dy in [-1, 1]:
                ny = y + dy
                while 0 <= ny and ny < w and field[x][ny] == '.':
                    dist[x][ny][1] = tmp
                    # x方向にdx, y方向にdy移動した場所を(nx, ny)とする
                    ny += dy
        res = max(sum(dist[x][y])-1, res)

print(res)

Submission status: Wrong Answer

Solution code:

def main():
    H,W = list(map(int, input().split()))
    S = [input() for _ in range(H)]

    count_h = [[0] * W for _ in range(H)]
    count_w = [[0] * W for _ in range(H)]

    tmp_cnt_h = [0] * W
    for i in range(H):
        w_cnt = 0
        for j,c in enumerate(S[i]):
            if c == '.':
                tmp_cnt_h[j] += 1
                w_cnt += 1
            else:
                count_w[i][j-w_cnt:j] = [w_cnt]*w_cnt
                w_cnt = 0

                h_cnt = tmp_cnt_h[j]
                for x in range(i-tmp_cnt_h[j],i):
                    count_h[x][j] = h_cnt
                tmp_cnt_h[j] = 0

        count_w[i][j-w_cnt:j] = [w_cnt]*w_cnt

    for i, h_cnt in enumerate(tmp_cnt_h):
        for x in range(H-h_cnt,H):
            count_h[x][i] = h_cnt

    max_light = 0
    for i in range(H):
        for j in range(W):
            max_light = max(max_light, count_h[i][j] + count_w[i][j])
    print(max_light-1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w = map(int, input().split())
arr = np.array([list(input()) for _ in range(h)]) == "."
print(arr)
l = np.zeros((h, w), dtype=int)
r = np.zeros((h, w), dtype=int)
u = np.zeros((h, w), dtype=int)
d = np.zeros((h, w), dtype=int)

for i in range(h):
    u[i] = (u[i - 1] + 1) * arr[i] #arrがFalseだと0になる
    d[- i - 1] = (d[- i] + 1) * arr[- i - 1]

for j in range(w):
    l[:, j] = (l[:, j-1] + 1) * arr[:, j]
    r[:, - j - 1] = (r[:, - j] + 1) * arr[:, - j - 1]
# print(u)
print(np.max(u + d + l + r) - 3)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    h, w = map(int, input().split())
    col = [[0, w + 1] for _ in range(h)]
    row = [[0, h + 1] for _ in range(w)]
    for i in range(h):
        s = list(input()[:-1].decode())
        for j in range(w):
            if s[j] == '#':
                col[i].append(j + 1)
                row[j].append(i + 1)

    cc = [[0] * (w + 2) for _ in range(h)]
    rc = [[0] * (h + 2) for _ in range(w)]

    for i in range(h):
        col[i].sort()
        for j in range(len(col[i]) - 1):
            cc[i][col[i][j] + 1:col[i][j + 1]] = [col[i][j + 1] - col[i][j] - 1] * (col[i][j + 1] - col[i][j] - 1)

    for i in range(w):
        row[i].sort()
        for j in range(len(row[i]) - 1):
            rc[i][row[i][j] + 1:row[i][j + 1]] = [row[i][j + 1] - row[i][j] - 1] * (row[i][j + 1] - row[i][j] - 1)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cc[i][j] + rc[j][i] - 1)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

a,b = map(int,input().split())
L = [list(input()) for _ in range(a)]

def yoko(i,j):
    yoko = L[i]
    ans = 0
    for k in range(j+1,b):
        if yoko[k] == ".":
            ans += 1
        elif yoko[k] == "#":
            break

    for k in range(j+1):
        if yoko[j-k] == ".":
            ans += 1
        elif yoko[j-k] == "#":
            break
    return ans

def tate(i,j):
    ans = 0
    for k in range(i+1,a):
        if L[k][j] == ".":
            ans += 1
        elif L[k][j] == "#":
            break

    for k in range(i):
        if L[i-k][j] == ".":
            ans += 1
        elif L[i-k][j] == "#":
            break
    return ans

ans = 0
for i in range(a):
    for j in range(b):
        ans = max(ans,yoko(i,j)+tate(i,j))
        

print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = []
for i in range(h):
  t = input()
  s.append(t)
yoko = [[0 for i in range(w)] for j in range(h)]
tate = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  cnt = 0
  for j in range(w):
    if s[i][j] == '#':
      for k in range(j-cnt,j):
        yoko[i][k] = cnt
      cnt =0
    else:
      cnt += 1
  if cnt > 1:
    for k in range(w-cnt,w):
      yoko[i][k] = cnt


wk = [['' for i in range(h)] for j in range(w)]

for i in range(w):
  for j in range(h):
    wk[i][j] += s[j][i]

for i in range(w):
  cnt = 0
  for j in range(h):
    if wk[i][j] == '#':
      for k in range(j-cnt,j):
        tate[k][i] = cnt
      cnt =0
    else:
      cnt += 1
  if cnt > 1:
    for k in range(h-cnt,h):
      tate[k][i] = cnt

ans = 0
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      continue
    x = tate[i][j] + yoko[i][j] -1
    ans = max(ans,x)
print (ans)

Submission status: Wrong Answer

Solution code:
h,w=[int(x) for x in input().rstrip().split()]
l=[list(input()) for i in range(h)]

move=[[1,0],[-1,0],[0,1],[0,-1]]
upx,upy=move[2]
downx,downy=move[3]
rix,riy=move[0]
lefx,lefy=move[1]

def bfs(stack):
  ans=0
  now=0
  while(stack):
    nx,ny,nd = stack.pop()
 
    if nd=="up":
      mx=nx+upx
      my=ny+upy
      if not(0<=mx<w) or not(0<=my<h) or l[my][mx]=="#":
        ans+=now
        now=0
      else:
        stack.append([mx,my,"up"])
        now+=1

    elif nd=="down":
      mx=nx+downx
      my=ny+downy
      if not(0<=mx<w) or not(0<=my<h) or l[my][mx]=="#":
        ans+=now
        now=0
      else:
        stack.append([mx,my,"down"])
        now+=1
    
    elif nd=="right":
      mx=nx+rix
      my=ny+riy
      if not(0<=mx<w) or not(0<=my<h) or l[my][mx]=="#":
        ans+=now
        now=0
      else:
        stack.append([mx,my,"right"])
        now+=1
    
    elif nd=="left":
      mx=nx+downx
      my=ny+downy
      if not(0<=mx<w) or not(0<=my<h) or l[my][mx]=="#":
        ans+=now
        now=0
      else:
        stack.append([mx,my,"left"])
        now+=1

  return ans

ans=0
for i in range(w):
  for j in range(h):
    first=[]
    if l[j][i]==".":
      if 0<=j-1<h and l[j][i]!="#":
        first.append([i,j-1,"down"])
      if 0<=j+1<h and l[j][i]!="#":
        first.append([i,j+1,"up"])
      if 0<=i+1<w and l[j][i]!="#":
        first.append([i+1,j,"right"])
      if 0<=i-1<w and l[j][i]!="#":
        first.append([i,j-1,"left"])
    now=bfs(first)
    ans=max(ans,now)

print(ans+1)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from itertools import groupby
    h, w = map(int, input().split())
    m = []

    for i in range(h):
        m.append(tuple(sys.stdin.readline()))

    mt = []
    for i in zip(*m):
        mt.append(i)

    ans = 0
    for line in m:
        l = 0
        for k, gr in groupby(line):
            c_r = len(list(gr))
            r = l + c_r
            if k == '#':
                l = r
                continue
            for j in range(l, r):
                t = mt[j]
                lt = 0
                for kl, gl in groupby(t):
                    c_l = len(list(gl))
                    rt = lt + c_l
                    if k == '#':
                        lt = rt
                        continue

                    ans = max(ans, c_r + c_l - 1)
                    lt = rt

            l = r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#初期入力
map1 =[]
H,W = (int(x) for x in input().split())
for i in range(H):
    *s, = input() 
    map1.append(s)

#上下左右、ライトが届く距離を配列
u =[[0]*W for _ in range(H)]
d =[[0]*W for _ in range(H)]
r =[[0]*W for _ in range(H)]
l =[[0]*W for _ in range(H)]
ans =[[0]*W for _ in range(H)]

#各方向別にそれぞれの位置でのライトの届く距離
for h in range(H):
    for w in range(W):
        if map1[h][w] ==".":
            if w ==0:
                l[h][w] =1
            else:
                l[h][w] =l[h][w-1] +1
for h in range(H):
    for w in range(W-1,-1,-1):
        if map1[h][w] ==".":
            if w ==W-1:
                r[h][w] =1
            else:
                r[h][w] =r[h][w+1] +1
for w in range(W):
    for h in range(H):
        if map1[h][w] ==".":
            if h ==0:
                u[h][w] =1
            else:
                u[h][w] =u[h-1][w] +1
for w in range(W-1):
    for h in range(H-1,-1,-1):
        if map1[h][w] ==".":
            if h ==H-1:
                d[h][w] =1
            else:
                d[h][w] =d[h+1][w] +1

#それぞれの位置で、各方向を足す。（自分の位置は4方向分足しているからー３）
for h in range(H):
    for w in range(W):
        ans[h][w] =l[h][w] +r[h][w] +u[h][w] +d[h][w] -3
print(max(max(i) for i in ans))

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
lt = set(list(t))
ls = list(s)
ss = set(ls)
it = {}
mod = len(s)
p = -1
ans = 0
ind = 0
for x in lt:
    if x in ss: 
        if x not in it: it[x] = []
    else:
        print(-1)
        exit()
for i in range(len(s)):
    x = s[i]
    if x in it: it[x].append(i)
#print(it)
for x in t:
    l = it[x]
    k = True
    for y in l:
        if y >= ans % mod:
            ans = ans // mod * mod + y
            k = False
            break
        ans = l[0]
    if k:
        ind += 1
    #print(ans,ind,k)
print(ans + 1 + mod * ind)

Submission status: Wrong Answer

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

Ss = []
for _ in range(H):
    s = list(input())
    Ss.append(s)

# 各マスから左に何マスいったら壁にぶつかるか
left = [[-1 for _ in range(W)] for _ in range(H)]
right = [[-1 for _ in range(W)] for _ in range(H)]
top = [[-1 for _ in range(W)] for _ in range(H)]
bottom = [[-1 for _ in range(W)] for _ in range(H)]


# 右に何マスいったらぶつかるか
for i in range(H):
    count = 0
    for j in range(W):
        if Ss[i][j] == "#":
            count = 0
        else:
            count += 1
            right[i][j] = count

# 左に何マスいったらぶつかるか
for i in range(H):
    count = 0
    for j in range(W):
        k = W-j-1
        if Ss[i][k] == "#":
            count = 0
        else:
            count += 1
            left[i][k] = count

# 下に何マスいったらぶつかるか
for j in range(W):
    count = 0
    for i in range(H):
        if Ss[i][j] == "#":
            count = 0
        else:
            count += 1
            bottom[i][j] = count

# 上に何マスいったらぶつかるか
for j in range(W):
    count = 0
    for i in range(H):
        k = H - i - 1
        if Ss[k][j] == "#":
            count = 0
        else:
            count += 1
            bottom[k][j] = count


max_score = 0
for i in range(H):
    for j in range(W):
        if Ss[i][j] != "#":
            score = left[i][j] + right[i][j] + top[i][j] + bottom[i][j] + 1
            max_score = max(max_score, score)

print(max_score)

Submission status: Wrong Answer

Solution code:
def main():
    h, w = map(int, input().split())
    S = [input() for _ in range(h)]
    hs = [0]*h
    ws = [0]*w
    for i in range(h):
        piyo = 0
        hoge = []
        for j in range(w):
            s = S[i][j]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    ws[k] = max(ws[k], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            ws[k] = max(ws[k], piyo)
    for i in range(w):
        piyo = 0
        hoge = []
        for j in range(h):
            s = S[j][i]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    hs[k] = max(hs[k], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            hs[k] = max(hs[k], piyo)
    result = 0
    for i in hs:
        for j in ws:
            result = max(result, i + j - 1)
    print(result)
main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
H, W = list(map(int, input().split()))
S = ['']*H
for i in range(H):
    S[i] = input()


L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
A = [[0] * W for _ in range(H)]

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

for i in range(H):
    for j in reversed(range(W)):
        if S[i][j] == '.' and j == (W-1):
            R[i][j] = 1
        elif (S[i][j] == '.'):
            R[i][j] = R[i][j + 1] + 1


for i in range(H):
    for j in range(W):
        if S[i][j] == '.' and i == 0:
            U[i][j] = 1
        elif (S[i][j] == '.'):
            U[i][j] = U[i-1][j] + 1


for i in reversed(range(H)):
    for j in range(W):
        if S[i][j] == '.' and i == (H-1):
            D[i][j] = 1
        elif (S[i][j] == '.'):
            D[i][j] = D[i+1][j] + 1
ans = 0

for i in reversed(range(H)):
    for j in range(W):
        # A[i][j] = R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3
        # if (ans < R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3):
        #     ans = R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3
        #     # hoge = [i, j]
        ans = max(ans, R[i][j] + L[i][j] + U[i][j] + L[i][j] - 3)
# print(ans)
# print(hoge)
# print('=========L=========')
# for i in range(H):
#     print(L[i])
# print('======R===========')
# for i in range(H):
#     print(R[i])
# print('=======U==========')
# for i in range(H):
#     print(U[i])
# print('========D==========')
# for i in range(H):
#     print(D[i])

# for i in range(H):
#     print(A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
def burst(S,H,W):
    for i in range(H):
        S[i] += "d" #dummy
    S.append("d" * (W+1))
    tate_burst = [[] for _ in range(W)]
    yoko_burst = [[] for _ in range(H)]
    #tate_burst[j]:j列目の連続する"."の(左端,右端)
    #yoko_burst[i]:i行目の連続する"."の(上端,下端)

    for j in range(W):
        sp,ep = None,None
        for i in range(H):
            if S[i][j] == ".":
                if sp == None:
                    sp = i
                elif S[i+1][j] != ".":
                    ep = i
                    tate_burst[j].append((sp,ep))
                    sp,ep = None,None

    for i in range(H):
        sp,ep = None,None
        for j in range(W):
            if S[i][j] == ".":
                if sp == None:
                    sp = j
                elif S[i][j+1] != ".":
                    ep = j
                    yoko_burst[i].append((sp,ep))
                    sp,ep = None,None

    return tate_burst,yoko_burst

def score(tate_burst,yoko_burst,H,W):
    T = [[0 for _ in range(W)] for _ in range(H)]

    for j in range(W):
        for st,go in tate_burst[j]:
            for i in range(st,go+1):
                T[i][j] += (go-st+1)

    for i in range(H):
        for st,go in yoko_burst[i]:
            for j in range(st,go+1):
                T[i][j] += (go-st+1)

    return T

def max_score(T,H,W):
    output = 0
    for i in range(H):
        for j in range(W):
            output = max(output,T[i][j])

    if H > 1 and W > 1:
        output -= 1
    return output

def main():
    H,W = map(int,input().split())
    S = [input() for _ in range(H)]

    B = burst(S,H,W)
    tate_burst,yoko_burst = B[0],B[1]
    T = score(B[0],B[1],H,W)
    ans = max_score(T,H,W)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def burst(S,H,W):
    for i in range(H):
        S[i] += "d" #dummy
    S.append("d" * (W+1))
    tate_burst = [[] for _ in range(W)]
    yoko_burst = [[] for _ in range(H)]
    #tate_burst[j]:j列目の連続する"."の(左端,右端)
    #yoko_burst[i]:i行目の連続する"."の(上端,下端)

    for j in range(W):
        sp,ep = None,None
        for i in range(H):
            if S[i][j] == ".":
                if sp == None:
                    sp = i
                elif S[i+1][j] != ".":
                    ep = i
                    tate_burst[j].append((sp,ep))
                    sp,ep = None,None

    for i in range(H):
        sp,ep = None,None
        for j in range(W):
            if S[i][j] == ".":
                if sp == None:
                    sp = j
                elif S[i][j+1] != ".":
                    ep = j
                    yoko_burst[i].append((sp,ep))
                    sp,ep = None,None

    return tate_burst,yoko_burst

def score(tate_burst,yoko_burst,H,W):
    T = [[0 for _ in range(W)] for _ in range(H)]

    for j in range(W):
        for st,go in tate_burst[j]:
            for i in range(st,go+1):
                T[i][j] += (go-st+1)

    for i in range(H):
        for st,go in yoko_burst[i]:
            for j in range(st,go+1):
                T[i][j] += (go-st+1)

    return T

def max_score(T,H,W):
    output = 0
    for i in range(H):
        for j in range(W):
            output = max(output,T[i][j]-1)

    return output

def main():
    H,W = map(int,input().split())
    S = [input() for _ in range(H)]

    B = burst(S,H,W)
    T = score(B[0],B[1],H,W)
    ans = max_score(T,H,W)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
    
d = [[[0,0,0,0] for x in range(W)] for y in range(H)]
answer = 0
for i in range(H):
    for j in range(W):
        tmp = [0, 0, 0, 0]

        if S[i][j] == '#':
            continue
            
        # 上
        org_i = i
        
        while(org_i - 1>= 0):
            org_i -= 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[0] += 1
                c = d[org_i][j][0] 
                if c > 0:
                    print('a')
                    tmp[0] += c
                    break
                
        d[i][j][0] = tmp[0]
        
        # 下
        org_i = i
        
        while(org_i + 1 < H):
            org_i += 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[1] += 1
                c = d[org_i][j][1] 
                if c > 0:
                    tmp[1] += c
                    break
                
        d[i][j][1] = tmp[1]
        
        # 右
        org_j = j
        
        while(org_j -1 >= 0):
            org_j -= 1
            if S[i ][org_j] == '#':
                break
            else:
                tmp[2] += 1
                c = d[i][org_j][2] 
                if c > 0:
                    tmp[2] += c
                    break
        
        d[i][j][2] = tmp[2]
        
        # 左
        org_j = j
        
        while(org_j + 1 < W):
            org_j += 1
            if S[i][org_j] == '#':
                break
            else:
                tmp[3] += 1
                c = d[i][org_j][3] 
                if c > 0:
                    tmp[3] += c
                    break
            
        d[i][j][3] = tmp[3]
        
        m = sum(d[i][j]) + 1
        if m > answer:
            answer = m
                
print(answer)

Submission status: Wrong Answer

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

    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if j == 0:
                left[i][j] = 0
            else:
                left[i][j] = left[i][j-1] + 1

    for i in range(H):
        for j in range(W):
            if j == 0:
                right[-1-i][-1-j] = 0
            else:
                right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1

    for i in range(H):
        for j in range(W):
            if i == 0:
                up[i][j] = 0
            else:
                up[i][j] = up[i-1][j] + 1

    for i in range(H):
        for j in range(W):
            if i == 0:
                down[-1-i][-1-j] = 0
            else:
                down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = [[None]*W]*H
    right = [[None]*W]*H
    up = [[None]*W]*H
    down = [[None]*W]*H

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[-1-i][-1-j] = -1
                down[-1-i][-1-j] = -1

    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, left[i][j]+right[i][j]+up[i][j]+down[i][j])
    print(ans+1)
    
main()