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())
mp=[]
h_wall=[]
for i in range(h):
    h_wall_l=[]
    l=input()
    mp.append(l)
    for a in range(len(l)):
        if l[a]=='#':
            h_wall_l.append(a)
    h_wall.append(h_wall_l)
v_wall=[]
for i in range(w):
    vl=''
    for j in range(h):
      vl+=mp[j][i]
    v_wall_vl=[]
    for a in range(len(vl)):
        if vl[a]=='#':
            v_wall_vl.append(a)
    v_wall.append(v_wall_vl)
# h_mp=[]
# for i in h_wall:
#     if len(i)!=0:
#         hll=[]
#         first=i[0]
#         for j in range(first):
#             hll.append(first)
#         hll.append(-1)
#         if len(i)>=2:
#             for j in range(len(i)-1):
#                 mid=i[j+1]-i[j]-1
#                 for z in range(mid):
#                     hll.append(mid)
#                 hll.append(-1)
#         if len(hll)<w:
#             diff = w-len(hll)
#             for z in range(diff):
#                 hll.append(diff)
#     else:
#         hll=[w for zz in range(w)]
#     h_mp.append(hll)
# v_mp = []
# for i in v_wall:
#     if len(i)!=0:
#         vll=[]
#         first=i[0]
#         for j in range(first):
#             vll.append(first)
#         vll.append(-1)
#         if len(i)>=2:
#             for j in range(len(i)-1):
#                 mid=i[j+1]-i[j]-1
#                 for z in range(mid):
#                     vll.append(mid)
#                 vll.append(-1)
#         if len(vll)<h:
#             diff = h-len(vll)
#             for z in range(diff):
#                 vll.append(diff)
#     else:
#         vll=[h for zz in range(h)]
#     v_mp.append(vll)
# # for i in v_mp:
# #     print(i)
# # print("---")

# v_mp = [list(x) for x in zip(*v_mp)]
# # for i in h_mp:
# #     print(i)
# # print("---")
# # for i in v_mp:
# #     print(i)

# maxx=0

# for i in range(h):
#     for j in range(w):
#         hhh = h_mp[i][j]
#         vvv = v_mp[i][j]
#         if hhh != -1 and vvv != -1:
#             temp = hhh+vvv-1
#             if temp >= maxx:
#                 maxx=temp
# print(maxx)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    s = input()
    a = []
    for j in range(W):
        if s[j] == '.':
            a.append(1)
        else:
            a.append(0)
    S.append(a)

ST = [list(s) for s in zip(*S)]

wmap = [[0 for i in range(W)] for j in range(H)]
hmap = [[0 for i in range(H)] for j in range(W)]


for h in range(H):
    c = 0
    for w in range(W):
        if S[h][w] == 0:
            if c > 0:
                wmap[h][w-c:w] = [c for _ in range(c)]
            c = 0
        else:
            c += 1

    if c > 0:
        wmap[h][w-c+1:] = [c for _ in range(c)]

for w in range(W):
    c = 0
    for h in range(H):
        if ST[w][h] == 0:
            if c > 0:
                hmap[w][h-c+1:h] = [c for _ in range(c)]
            c = 0
        else:
            c += 1

    if c > 0:
        hmap[w][h-c+1:] = [c for _ in range(c)]



max_s = 0
hmap = [list(h) for h in zip(*hmap)]

for w in range(W):
    for h in range(H):
        max_s = max(max_s, hmap[h][w] + wmap[h][w] - S[h][w])

print(max_s)

Submission status: Wrong Answer

Solution code:
import numpy as np

val = list(map(int, input().strip().split()))
width = val[1]
height = val[0]

walls = np.zeros((height, width))

for y in range(height):
    val = input().strip()
    for x in range(width):
        walls[y, x] = 1 if val[x] == '#' else 0

# left = np.zeros((height, width))
# right = np.zeros((height, width))
# up = np.zeros((height, width))
# down = np.zeros((height, width))
all = np.zeros((height, width))

# left
for y in range(height):
    cache = 0
    for x in range(width):
        if walls[y, x] == 1:
            cache = x + 1
            all[y, x] = 100
        else:
            all[y, x] += cache

# right
for y in range(height):
    cache = 0
    for x in range(width - 1, -1, -1):
        if walls[y, x] == 1:
            cache = width - x
        else:
            all[y, x] += cache

# up
for x in range(width):
    cache = 0
    for y in range(height):
        if walls[y, x] == 1:
            cache = y + 1
        else:
            all[y, x] += cache

# down
for x in range(width):
    cache = 0
    for y in range(height - 1, -1, -1):
        if walls[y, x] == 1:
            cache = height - y
        else:
            all[y, x] += cache


print(int(width + height - np.amin(all) - 1))

Submission status: Wrong Answer

Solution code:
from collections import deque

def solve():
    H, W = [int(_) for _ in raw_input().split()]
    S = []
    for i in range(H):
        Si = [_ for _ in raw_input()]
        S.append(Si)
    rowm = [None] * H
    for i in range(H):
        start = -1
        end = 0
        save = (start, end, i)
        for j in range(W):
            if S[i][j] == '.':
                end = j
            else:
                start = j
                end = j
            if end - start > save[1] - save[0]:
                save = (start, end, i)
        rowm[i] = save
    colm = [None] * W
    for j in range(W):
        start = -1
        end = 0
        save = (start, end, j)
        for i in range(H):
            if S[i][j] == '.':
                end = i
            else:
                start = i
                end = i
            if end - start > save[1] - save[0]:
                save = (start, end, j)
        colm[j] = save
    rowm.sort(key = lambda x: x[1] - x[0], reverse = True)
    colm.sort(key = lambda x: x[1] - x[0], reverse = True)
    # priority queue
    queue = deque()
    queue.append((0,0))
    ret = 0
    while len(queue) > 0:
        def max_ans(i,j):
            s1, e1, row = rowm[i]
            s2, e2, col = colm[j]
            return e1 - s1 + e2 - s2 - 1

        i, j = queue.popleft()
        s1, e1, row = rowm[i]
        s2, e2, col = colm[j]
        tmp = max_ans(i,j)
        if tmp == 1:
            ret = tmp
            break
        if row >= s2 and row <=e2 and col >= s1 and col <= e1:
            ret = tmp
            break
        if i + 1 < H and j + 1 < W:
            if max_ans(i + 1, j) >= max_ans(i, j + 1):
                queue.append((i+1, j))
                queue.append((i, j+1))
            else:
                queue.append((i, j+1))
                queue.append((i+1, j))
        else:
            if i + 1 < H:
                queue.append((i+1, j))
            if j + 1 < W:
                queue.append((i, j+1))
    print ret

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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


def solve(H: int, W: int, S: "List[str]"):
    from collections import deque

    q = deque()
    ans = 0
    for x in range(H):
        for y in range(W):
            if(S[x][y] == '.'):
                if(0 <= x-1 < H and 0 <= x+1 < H):
                    if(S[x-1][y] == '#' and S[x+1][y] == '#'):
                        continue
                elif(0 <= y-1 < W and 0 <= y+1 < W):
                    if(S[x][y-1] == '#' and S[x][y+1] == '#'):
                        continue


                t = 1
                
                # 上
                s = 1
                while(0 <= x-s < H and 0 <= y < W and S[x-s][y] == '.'):
                    t += 1
                    s += 1

                # 下
                s = 1
                while(0 <= x+s < H and 0 <= y < W and S[x+s][y] == '.'):
                    t += 1
                    s += 1

                # 左
                s = 1
                while(0 <= x < H and 0 <= y-s < W and S[x][y-s] == '.'):
                    t += 1
                    s += 1

                # 右
                s = 1
                while(0 <= x < H and 0 <= y+s < W and S[x][y+s] == '.'):
                    t += 1
                    s += 1

                ans = max(ans, t)

    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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=[[i=="." for i in input()+"#"] for _ in range(H)]+[[False]*(W+1)]

map_=[[0]*W for _ in range(H)]
for i in range(H):
    cnt=0
    q=[]
    for j in range(W+1):
        if S[i][j]==False and cnt!=0:
            for Q in q:
                map_[Q[0]][Q[1]]=cnt
            cnt=0
        elif S[i][j]:
            cnt+=1
            q.append([i,j])
for j in range(W):
    cnt=0
    q=[]
    for i in range(H+1):
        if S[i][j]==False and cnt!=0:
            for Q in q:
                map_[Q[0]][Q[1]]+=cnt
            cnt=0
        elif S[i][j]:
            cnt+=1
            q.append([i,j])
print(max([max(i) for i in map_])-1)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
X = [[-10**2 for __ in range(W)] for _ in range(H)]
Y = [[-10**2 for __ in range(W)] for _ in range(H)]
last_ys = [-1] * W
for y in range(H):
  last_x = -1
  for x in range(W):
    if S[y][x] == "#":
      for t in range(last_x+1,x):
        X[y][t] = x-1-last_x
      for t in range(last_ys[x]+1,y):
        Y[t][x] = y-1-last_ys[x]
      last_x = x
      last_ys[x] = y
  for t in range(last_x+1,W):
    X[y][t] = W-1-last_x
for x in range(W):
  for t in range(last_ys[x]+1,H):
    Y[t][x] = y-1-last_ys[x]
ans = 0
for y in range(H):
  for x in range(W):
    ans = max(ans, Y[y][x]+X[y][x])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    h, w = map(int, input().split())
    mat = [input() for _ in range(h)]

    hor = [[0] * (w + 1) for _ in range(h + 1)]
    ver = [[0] * (h + 1) for _ in range(w + 1)]

    for i, row in enumerate(mat):
        hi = hor[i]
        for j in range(w):
            if row[j] == '.':
                hi[j + 1] = hi[j] + 1
            else:
                hi[j + 1] = 0
        for j in reversed(range(w)):
            if hi[j]:
                hi[j] = max(hi[j], hi[j + 1])

    for i, col in enumerate(zip(*mat)):
        vi = ver[i]
        for j in range(h):
            if col[j] == '.':
                vi[j + 1] = vi[j] + 1
            else:
                vi[j + 1] = 0
        for j in reversed(range(h)):
            if vi[j]:
                vi[j] = max(vi[j], vi[j + 1])

    ver = list(zip(*ver))

    res = 0
    for i in range(h + 1):
        hi = hor[i]
        vi = ver[i]
        for j in range(w + 1):
            res = max(res, hi[j] + vi[j] - 1)

    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import time
dbg = False
h, w = map(int, input().split())
maze = []
for hh in range(h):
  row = list(input())
  maze.append(row)
hscore = []

t = time.time()

for hh in range(h):
  hrow = [0] * w
  hrow[0] = 1 if maze[hh][0] == '.' else 0
  for ww in range(w):
    if maze[hh][ww] == '.':
      hrow[ww] = hrow[ww-1] + 1
    else:
      hrow[ww] = 0
  for ww in reversed(range(w-1)):
    if maze[hh][ww] == '#':
      hrow[ww] = 0
    elif maze[hh][ww+1] == '.':
      hrow[ww] = hrow[ww+1]

  hscore.append(hrow)

# transpose
if dbg:
  print('hscore done')
  print(time.time() - t)
  t = time.time()
maze_t = list(map(list, zip(*maze)))
vscore = []

h, w = w, h

for hh in range(h):
  hrow = [0] * w
  hrow[0] = 1 if maze_t[hh][0] == '.' else 0
  for ww in range(w):
    if maze_t[hh][ww] == '.':
      hrow[ww] = hrow[ww-1] + 1
    else:
      hrow[ww] = 0
  for ww in reversed(range(w-1)):
    if maze_t[hh][ww] == '#':
      hrow[ww] = 0
    elif maze_t[hh][ww+1] == '.':
      hrow[ww] = hrow[ww+1]
  vscore.append(hrow)

vscore = list(map(list, zip(*vscore)))
if dbg:
  print('vscore done')
  print(time.time() - t)
  t = time.time()

h, w = w, h

max_score = 0
for hh in range(h):
  score = max([x + y - 1 for x, y in zip(hscore[hh], vscore[hh])])
  max_score = max([max_score, score])

print(max_score)

if dbg:
  print(time.time() - t)

Submission status: Wrong Answer

Solution code:
from collections import deque

def solve():
    H, W = [int(_) for _ in raw_input().split()]
    S = []
    for i in range(H):
        Si = [_ for _ in raw_input()]
        S.append(Si)
    rowm = [None] * H
    for i in range(H):
        start = -1
        end = 0
        save = (start, end, i)
        for j in range(W):
            if S[i][j] == '.':
                end = j
            else:
                start = j
                end = j
            if end - start > save[1] - save[0]:
                save = (start, end, i)
        rowm[i] = save
    colm = [None] * W
    for j in range(W):
        start = -1
        end = 0
        save = (start, end, j)
        for i in range(H):
            if S[i][j] == '.':
                end = i
            else:
                start = i
                end = i
            if end - start > save[1] - save[0]:
                save = (start, end, j)
        colm[j] = save
    rowm.sort(key = lambda x: x[1] - x[0], reverse = True)
    colm.sort(key = lambda x: x[1] - x[0], reverse = True)
    # priority queue
    queue = deque()
    queue.append((0,0))
    ret = 0
    while len(queue) > 0:
        def max_ans(i,j):
            s1, e1, row = rowm[i]
            s2, e2, col = colm[j]
            return e1 - s1 + e2 - s2 - 1

        i, j = queue.popleft()
        s1, e1, row = rowm[i]
        s2, e2, col = colm[j]
        tmp = max_ans(i,j)
        if tmp == -1:
            ret = tmp
            break
        if row >= s2 and row <=e2 and col >= s1 and col <= e1:
            ret = tmp
            break
        if i + 1 < H and j + 1 < W:
            if max_ans(i + 1, j) >= max_ans(i, j + 1):
                queue.append((i+1, j))
                queue.append((i, j+1))
            else:
                queue.append((i, j+1))
                queue.append((i+1, j))
        else:
            if i + 1 < H:
                queue.append((i+1, j))
            if j + 1 < W:
                queue.append((i, j+1))
    print ret

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)

H, W = map(int, input().split())
lst = [['#'] * (W+2)]
lst += [['#'] + list(input()) + ['#'] for i in range(H)]
lst += [['#'] * (W+2)]


lst_ue = [[-1] * (W+2) for i in range(H+2)]
lst_shita = [[-1] * (W+2) for i in range(H+2)]
lst_migi = [[-1] * (W+2) for i in range(H+2)]
lst_hidari = [[-1] * (W+2) for i in range(H+2)]

# print (lst_ue)
def ue(i, j):
    if lst_ue[i][j] != -1:
        return lst_ue[i][j]
    if lst[i][j] == '#':
        lst_ue[i][j] = 0
        return 0
    else:
        lst_ue[i][j] = ue(i-1, j) + 1
        return lst_ue[i][j]

def shita(i, j):
    if lst_shita[i][j] != -1:
        return lst_shita[i][j]
    if lst[i][j] == '#':
        lst_shita[i][j] = 0
        return 0
    else:
        lst_shita[i][j] = shita(i+1, j) + 1
        return lst_shita[i][j]        

def hidari(i, j):
    if lst_hidari[i][j] != -1:
        return lst_hidari[i][j]
    if lst[i][j] == '#':
        lst_hidari[i][j] = 0
        return 0
    else:
        lst_hidari[i][j] = hidari(i, j-1) + 1
        return lst_hidari[i][j]        

def migi(i, j):
    if lst_migi[i][j] != -1:
        return lst_migi[i][j]
    if lst[i][j] == '#':
        lst_migi[i][j] = 0
        return 0
    else:
        lst_migi[i][j] = migi(i, j+1) + 1
        return lst_migi[i][j]        

ans = 0

if H < 1800 and W < 1800:
    for i in range(1,H+1):
        for j in range(1, W+1):
            if lst[i][j] != '#':
                ans = max(ans, ue(i,j)+shita(i,j)+hidari(i,j)+migi(i,j)-3)
                if ans == H + W -1:
                    print (ans)
                    sys.exit()
else:
    for i in range(200,H+1-200):
        for j in range(200, W+1-200):
            if lst[i][j] != '#':
                ans = max(ans, ue(i,j)+shita(i,j)+hidari(i,j)+migi(i,j)-3)
                if ans == H + W -1:
                    print (ans)
                    sys.exit()

print (ans)

Submission status: Wrong Answer

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

room = [[True if c == "." else False for c in input()] for _ in range(H)]

count = []

for i in range(H):
    count.append([0] * W)

for row in range(H):
    start = 0
    for col in range(W):
        if not room[row][col]:
            if col != 0:
                plus = col - start
                for i in range(start, col):
                    count[row][i] += plus
            start = col + 1
    if room[row][W - 1]:
        plus = W - start + 1
        for i in range(start, W):
            count [row][i] += plus

for col in range(W):
    start = 0
    for row in range(H):
        if not room[row][col]:
            if row != 0:
                plus = row - start
                for i in range(start, row):
                    count[i][col] += plus
            start = row + 1
    if room[H - 1][col]:
        plus = H - start + 1
        for i in range(start, H):
            count[i][col] += plus

ans = 0

for rowline in count:
    ans = max(max(rowline), ans)

print((ans - 3))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
H,W=map(int,input().split())
L=[]
l=["#" for i in range(W+2)]
L.append(l)
#print(L)
for i in range(H):
    s=list(input().rstrip())
    s=["#"]+s+["#"]
    L.append(s)
L.append(s)

#print(L)
A=[[[0,0,0,0]for i in range(W+2)]for j in range(H+2)]
#print(A)
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j]==".":
            A[i][j][0]=A[i][j-1][0]+1
            A[i][j][1]=A[i-1][j][1]+1
#print(A)
ANS=0
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[H+1-i][W+1-j]==".":
            A[H+1-i][W+1-j][2]=A[H+1-i][W+2-j][2]+1
            A[H+1-i][W+1-j][3]=A[H+2-i][W+1-j][3]+1
            if sum(A[H+1-i][W+1-j])-3>ANS:
                ANS=sum(A[H+1-i][W+1-j])-3

Submission status: Wrong Answer

Solution code:
H,W  = map(int, input().split())
grid_w = []
grid = []
for i in range(H):
    S = input()
    tmp = [len(i) for i in S.split('#')]
    grid.append('#'.join([s.replace('.', str(t)) for t, s in zip(tmp, S.split('#'))]))
mx = 0
for i in range(W):
    cnt = 0
    tmp = 0
    for s in grid:
        if s[i] == '#':
            mx = max(cnt + tmp - 1, mx)
            cnt = 0
            tmp = 0
        else :
            cnt += 1
            tmp = max(tmp, int(s[i]))
    mx = max(cnt + tmp - 1, mx)
print(mx)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
l=['#'*(w+2)]+['#'+input()+'#' for i in range(h)]+['#'*(w+2)]
ans = 1

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      cnt = 1
      for k in range(1,w+2):
        if l[i+k][j] == '.':
          cnt += 1
        else:
          break
      for k in range(1,w+2):
        if l[i-k][j] == '.':
   	      cnt += 1
        else:
          break
      for k in range(1,h+2):
        if l[i][j+k] == '.':
          cnt += 1
        else:
          break
      for k in range(1,h+2):
        if l[i][j-k] == '.':
          cnt += 1
        else:
          break
      ans = max(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=(int(i) for i in input().split())
a=[]
b=[]
q=0
for i in range(h):
  s=input()
  r=[]
  c=0
  for j in range(w):
    if s[j]==".":
      c=c+1
      if j==w-1:
        for k in range(c):
          r.append(c)
    else:
      for k in range(c):
        r.append(c)
      r.append(0)
      c=0
  a.append(r)
for i in range(w):
  r=[]
  c=0
  for j in range(h):
    if a[j][i]!=0:
      c=c+1
      if j==h-1:
        for k in range(c):
          r.append(c)
    else:
      for k in range(c):
        r.append(c)
      r.append(0)
      c=0
  b.append(r)
print(q)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

result = 0
memo = {}


def terasu(x, y, d):
    #print(x, y, h, w)
    if y < 0 or x < 0 or y >= h or x >= w:
        return 0
    # if (x, y) in memo.keys():
    #    return 0
    if s[y][x] == "#":
        return 0
    #memo[(x, y)] = True
    if d == "f":
        return 1 + terasu(x + 1, y, "e") + terasu(x, y - 1, "s") + terasu(x, y+1, "n") + terasu(x-1, y, "w")
    elif d == "e":
        if (memo.get((x, y, "e")) != None):
            return memo[(x, y, "e")]
        memo[(x, y, "e")] = 1 + terasu(x + 1, y, "e")
        return memo[(x, y, "e")]
    elif d == "s":
        if (memo.get((x, y, "s")) != None):
            return memo[(x, y, "s")]
        memo[(x, y, "s")] = 1 + terasu(x, y+1, "s")
        return memo[(x, y, "s")]
    elif d == "n":
        if (memo.get((x, y, "n")) != None):
            return memo[(x, y, "n")]
        memo[(x, y, "n")] = 1 + terasu(x, y-1, "n")
        return memo[(x, y, "n")]
    elif d == "w":
        if (memo.get((x, y, "w")) != None):
            return memo[(x, y, "w")]
        memo[(x, y, "w")] = 1 + terasu(x - 1, y, "w")
        return memo[(x, y, "w")]


for y in range(h):
    for x in range(w):
        result = max(result, terasu(x, y, "f"))
print(result-4)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
sentence_list = []
for i in range(h):
    sentence_list.append(input())
max_lit = 0
verticle_lit_list = []
horizontal_lit_list = 0
for y in range(h):
    for x in range(w):
        if( y == 0):
            verticle_lit_list.append(0)
        if(sentence_list[y][x] == "#"):
            horizontal_lit_list = 0
            verticle_lit_list[x] = 0
            continue
        if(verticle_lit_list[x] == 0):
            # 数える.
            for y_2 in range(h-y):
                if (sentence_list[y+y_2][x] == "#"):
                    break
                verticle_lit_list[x] += 1
        if(horizontal_lit_list == 0):
            # 数える.
            for x_2 in range(w-x):
                if(sentence_list[y][x+x_2] == "#"):
                    break
                horizontal_lit_list += 1
        max_lit = max(max_lit, horizontal_lit_list + verticle_lit_list[x] - 1)
print(max_lit)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
maze = []
for hh in range(h):
  row = list(input())
  maze.append(row)
#print(maze)
hscore = []

for hh in range(h):
  hrow = [0] * w
  hrow[0] = 1 if maze[hh][0] == '.' else 0
  for ww in range(w):
    if maze[hh][ww] == '.':
      hrow[ww] = hrow[ww-1] + 1
    else:
      hrow[ww] = 0
  for ww in reversed(range(w-1)):
    if maze[hh][ww] == '#':
      hrow[ww] = 0
    elif maze[hh][ww+1] == '.':
      hrow[ww] = hrow[ww+1]

  hscore.append(hrow)

# transpose
#print(hscore)
maze_t = list(map(list, zip(*maze)))
vscore = []

h, w = w, h

for hh in range(h):
  hrow = [0] * w
  hrow[0] = 1 if maze_t[hh][0] == '.' else 0
  for ww in range(w):
    if maze_t[hh][ww] == '.':
      hrow[ww] = hrow[ww-1] + 1
    else:
      hrow[ww] = 0
  for ww in reversed(range(w-1)):
    if maze_t[hh][ww] == '#':
      hrow[ww] = 0
    elif maze_t[hh][ww+1] == '.':
      hrow[ww] = hrow[ww+1]
  vscore.append(hrow)

vscore = list(map(list, zip(*vscore)))
h, w = w, h

max_score = 0
for hh in range(h):
  for ww in range(w):
    score = hscore[hh][ww] + vscore[hh][ww] - 1
    max_score = max([max_score, score])
print(max_score)

Submission status: Wrong Answer

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

sh = "#" * (w+2)
T = [sh]
for i in range(h):
    T.append("#"+S[i]+"#")
T.append(sh)

U = [[] for i in range(h+2)]
V = [[] for i in range(w+2)]
for i in range(h+2):
    for j in range(w+2):
        if T[i][j] == "#":
            U[i].append(j)
            V[j].append(i)

A = [[0 for i in range(w+2)] for j in range(h+2)]

for i in range(len(U)):
    #print(U[i])
    for j in range(len(U[i])-1):
        #print(j)
        #print(U[i][j+1])
        for k in range(U[i][j]+1, U[i][j+1]):
            p = U[i][j+1]-U[i][j]-1
            A[i][k] += p
for i in range(len(V)):
    for j in range(len(V[i])-1):
        for k in range(V[i][j]+1, V[i][j+1]):
            p = V[i][j+1]-V[i][j]-1
            A[k][i] += p

ans = 0
for i in range(h):
    ans = max(ans, max(A[i]))

print(ans-1)

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
    tmp_tmp_row=0
    for j in range(w):
        if s[i][j]=='#':
            if tmp_tmp_row<tmp_row:
                tmp_tmp_row=tmp_row
                tmp_row=0
                continue
            else:
                tmp_row=0
                continue
        else:
            tmp_row+=1
    if tmp_tmp_row>tmp_row:
        if tmp_tmp_row>max_row1:
            max_row1=tmp_tmp_row
    else:
        if tmp_row>max_row1:
            max_row1=tmp_row
max_col1=0
for j in range(w):
    tmp_col=0
    tmp_tmp_col=0
    for i in range(h):
        if s[i][j]=='#':
            if tmp_col>tmp_tmp_col:
                tmp_tmp_col=tmp_col
                tmp_col=0
                continue
            else:
                tmp_col=0
                continue
        else:
            tmp_col+=1
    if tmp_tmp_col>tmp_col:
        if tmp_tmp_col>max_col1:
            max_col1=tmp_tmp_col
    else:
        if tmp_col>max_col1:
            max_col1=tmp_col

print(max_col1+max_row1-1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
H, W = map(int, input().split())
s = [input() for i in range(H)]

def length(index, block_idx, full_length):
    if len(block_idx) == 0:
        return full_length
    idx = bisect_left(block_idx, index)
    if idx == len(block_idx):
        return full_length - index
    return block_idx[idx] - index

rows = []

for i in range(H):
    row = [0 for k in range(W)]
    block_idx = []
    for k in range(len(s[i])):
        if s[i][k] == "#":
            block_idx.append(k)

    for j in range(W):
        if j == 0:
            if s[i][0] == "#":
                continue
            else:
                l = length(0, block_idx, W)
                row[j] = l
        else:
            if s[i][j] == "#":
                continue
            else:
                if s[i][j-1] != "#":
                    row[j] = row[j-1]
                else:
                    l = length(j, block_idx, W)
                    row[j] = l
    rows.append(row)

columns = []

for i in range(W):
    column = [0 for k in range(H)]

    _s = ""
    block_idx = []
    for k in range(H):
        _s += s[k][i]
        if s[k][i] == "#":
            block_idx.append(k)

    for j in range(H):
        if j == 0:
            if _s[0] == "#":
                continue
            else:
                l = length(0, block_idx, H)
                column[j] = l
        else:
            if _s[j] == "#":
                continue
            else:
                if _s[j - 1] != "#":
                    column[j] = column[j-1]
                else:
                    l = length(j, block_idx, H)
                    column[j] = l
    columns.append(column)
print(0)