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())
fs = []
for i in range(H):
    fs.append(input())

lefts = [[0]*W for i in range(H)]
rights = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if fs[i][j] == "#":
            lefts[i][j] == 0
        if fs[i][j] == ".":
            if j == 0:
                lefts[i][j] == 0
            else:
                lefts[i][j] = lefts[i][j-1] + 1
        jr = W - j - 1
        if fs[i][jr] == "#":
            rights[i][jr] == 0
        else:
            if jr == W-1:
                rights[i][jr] == 0
            else:
                rights[i][jr] = rights[i][jr+1] + 1
ups = [[0]*W for i in range(H)]
downs = [[0]*W for i in range(H)]
for j in range(W):
    for i in range(H):
        if fs[i][j] == "#":
            ups[i][j] == 0
        else:
            if i == 0:
                ups[i][j] == 0
            else:
                ups[i][j] = ups[i-1][j] + 1
        ir = H - i - 1
        if fs[ir][j] == "#":
            downs[ir][j] == 0
        else:
            if ir == H-1:
                downs[ir][j] == 0
            else:
                downs[ir][j] = downs[ir+1][j] + 1


# for l in lefts:
#     print(*l)
# print("-----------")
# for r in rights:
#     print(*r)
# print("updown")
# for l in ups:
#     print(*l)
# print("-----------")
# for r in downs:
#     print(*r)

ans = 0
for i in range(H):
    for j in range(W):
        x = lefts[i][j] + rights[i][j] + ups[i][j] + downs[i][j]
        ans = max(x,ans)
print(ans)

Submission status: Wrong Answer

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

graph = []
for i in range(H):
    s = input()
    graph.append(s)


def dfs(now, increment, count):
    now = (now[0] + increment[0], now[1] + increment[1])
    x, y = now

    if (not 0 <= x < W) or (not 0 <= y < H):
        return count - 1

    if graph[y][x] == "#":
        return count - 1

    if count == 5:
        return 4

    return dfs(now, increment, count+1)

ans = 1
for y in range(H):
    for x in range(W):
        if graph[y][x] == '.':
            a = dfs((x, y), (0, 1), 1)
            b = dfs((x, y), (0, -1), 1)
            c = dfs((x, y), (1, 0), 1)
            d = dfs((x, y), (-1, 0), 1)
            ans = max(ans, 1 + a + b + c + d)

print(ans)

Submission status: Wrong Answer

Solution code:

n,m = map(int, input().split())

S = [[] for _ in range(n)]

for i in range(n):
    S[i] = list(input())

ans = 0

for i in range(n):
    for j in range(m):
        cnt = 0
        if(S[i][j] == 'O'):
            for k in range(i,0,-1):
                if(S[k][j] == 'X'):
                    break
                cnt += 1
            
            for k in range(i+1,n):
                if(S[k][j] == 'X'):
                    break
                cnt += 1
            
            for k in range(j,0,-1):
                if(S[i][k] == 'X'):
                    break
                cnt += 1
            
            for k in range(j+1,m):
                if(S[i][k] == 'X'):
                    break
                cnt += 1
        ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
H,W=list(map(int,input().split()))
import numpy as np
m=np.array([[0 if i=="#" else 1 for i in input()] for i in range(H)])
l,r,u,d=np.zeros((4,H,W))
for i in range(H):
   u[i]=(u[i-1]+1)*m[i]
   d[-i-1]=(d[-i]+1)*m[i]
for i in range(W):
   r[:,i]=(r[:,i-1]+1)*m[:,i]
   l[:,-i-1]=(l[:,-i]+1)*m[:,-i-1]
print(int(np.max(u+r+l+d)-3))

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np

r, c = map(int, input().split())

map = []
map.append("#"*(c + 2))

for i in range(r):
    map.append("#" + input() + "#")

map.append("#"*(c + 2))

move = [[0, 1], [1, 0], [0, -1], [-1, 0]]
visit = [[0]*(c + 2) for i in range(r + 2)]

for i in range(1, r + 1):
    for j in range(1, c + 1):
        if map[i][j] == ".":
            visit[i][j] += 1
        for k, l in move:
            y = i + k
            x = j + l
            while map[y][x] == ".":
                visit[i][j] += 1
                y += k
                x += l
print(np.amax(np.array(visit)))

Submission status: Wrong Answer

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


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    H, W = MI()
    room = [["" for j in range(W)] for i in range(H)]
    roomT = [["" for i in range(H)] for j in range(W)]
    num_yoko = [[0 for j in range(W)] for i in range(H)]
    for i in range(H):
        row = input()

        splited = list(map(len, row.split('#')))
        tmp = 0
        for j in range(W):
            roomT[j][i] = row[j]
            room[i][j] = row[j]
            if row[j] == "#":
                num_yoko[i][j] = 0
                tmp += 1
            else:
                num_yoko[i][j] = splited[tmp]

    ans = 0

    for j in range(W):
        target = roomT[j]
        splited = list(map(len, "".join(target).split('#')))
        tmp = 0
        for i in range(H):
            num_tate = 0 if target[i] == "#" else splited[tmp]

            ans = max(ans,  num_tate + num_yoko[i][j] - 1)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
H,W=list(map(int,input().split()))
l=[list(input()) for i in range(H)]
import numpy as np
l_r=np.zeros((H,W))
l_l=np.zeros((H,W))
l_u=np.zeros((H,W))
l_d=np.zeros((H,W))
for i in range(H):
   tmp=0
   for j in range(W):
      if l[i][j] == ".":
         tmp+=1
         l_r[i][j]=tmp
      else:
         tmp=0
for i in range(H):
   tmp=0
   for j in reversed(range(W)):
      if l[i][j] == ".":
         tmp+=1
         l_l[i][j]=tmp
      else:
         tmp=0
for i in range(W):
   tmp=0
   for j in range(H):
      if l[j][i]==".":
         tmp+=1
         l_d[j][i]=tmp
      else:
         tmp=0
for i in range(W):
   tmp=0
   for j in reversed(range(H)):
      if l[j][i]==".":
         tmp+=1
         l_u[j][i]=tmp
      else:
         tmp=0
ans=0
for i in range(H):
   for j in range(W):
      ans=max(ans,l_u[i][j]+l_d[i][j]+l_l[i][j]+l_r[i][j]-3)
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
from copy import copy

HS = [[0 for w in range(W)] for h in range(H)]
VS = [[0 for w in range(W)] for h in range(H)]

# 横方向の連続を見る
for lix in range(len(S)):
    con = 0
    l = S[lix]
    for cix in range(len(l)):
        if l[cix] != '#':
            con += 1
        else:
            score = con
            while con > 0:
                # print(cix, con)
                HS[lix][cix-con] = score
                con -= 1
            HS[lix][cix] = 0

    if con > 0:
        score = con 
        while con > 0:
            HS[lix][cix-con+1] = score
            con -= 1
# print(HS)

# 縦方向の連続を見る
for ix in range(W):
    con = 0
    for iy in range(H):
        # print(iy, ix, S[iy][ix])
        if S[iy][ix] == '#':
            print(iy, ix, con)
            # refresh
            score = con
            while con > 0:
                VS[iy-con][ix] = score
                con -= 1
            VS[iy][ix] = 0
        else:
            con += 1
    # last
    while con > 0:
        score = con
        while con > 0:
            VS[iy-con+1][ix] = score
            con -= 1

# print(VS)

# 最大値を求める
ans = 0
for iy in range(H):
    for ix in range(W):
        ans = max(HS[iy][ix] + VS[iy][ix] - 1, ans)

print(ans)


# 3 * H * Wでいけるのでは?

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W=MI()
    S=[]
    S.append(["#"]*(W+2))
    for i in range(H):
        s=["#"]+list(input())+["#"]
        S.append(s)
    S.append(["#"]*(W+2))
    
    L=[[-1]*(W+2) for _ in range(H+2)]
    R=[[-1]*(W+2) for _ in range(H+2)]
    U=[[-1]*(W+2) for _ in range(H+2)]
    D=[[-1]*(W+2) for _ in range(H+2)]
    
    for i in range(1,H+2):
        for j in range(1,W+2):
            if S[i][j]!="#":
                L[i][j]=L[i][j-1]+1
                U[i][j]=U[i-1][j]+1
                
    for i in range(H,-1,-1):
        for j in range(W,-1,-1):
            if S[i][j]!="#":
                R[i][j]=R[i][j+1]+1
                D[i][j]=D[i+1][j]+1
                
    ans=0
    
    for i in range(H+2):
        for j in range(W+2):
            if S[i][j]!="#":
                temp=L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
                ans=max(ans,temp)
                
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from itertools import groupby
def input(): return sys.stdin.readline().rstrip()


def lamp(arr):
    count = np.zeros_like(arr)
    for i in range(arr.shape[0]):
        lamp = []
        for key, value in groupby(arr[i]):
            n=len(list(value))
            if key == '.':
                lamp+=[n]*n
            else:
                lamp+=[0]*n
        count[i]=np.array(lamp)
    return count.astype(np.int32)



def main():
    h, w = map(int, input().split())
    s = np.array([list(input()) for i in range(h)])
    print(np.max(lamp(s)+lamp(s.T).T)-1)
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def make_mat(grid, H, W):
    res = [[0] * W for _ in range(H)]
    for h in range(H):
        cnt = 0
        for w in range(W):
            if (grid[h]>>w)&1 == 1:
                for i in range(cnt):
                    res[h][w - 1 - i] = cnt
                cnt = 0
            else:
                cnt += 1
        if (grid[h]>>w)&1 == 0:
            for i in range(cnt):
                res[h][w - i] = cnt
    return res

def max2(x,y):
    return x if x > y else y


import sys
input = sys.stdin.readline

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


grid = []
grid_t = [0]*W
for h in range(H):
    temp = 0
    for w, s in enumerate(input().rstrip()):
        if s=="#":
            temp += 1<<(W-1-w)
            grid_t[w] += 1<<(H-1-h)
    grid.append(temp)

A = make_mat(grid, H, W)
B = make_mat(grid_t, W, H)

res = 0
for h in range(H):
    for w in range(W):
        res = max2(A[h][w] + B[w][h], res)

print(res-1)

Submission status: Wrong Answer

Solution code:
def make_mat(grid, H, W):
    res = [[0] * W for _ in range(H)]
    for h in range(H):
        cnt = 0
        for w in range(W):
            if (grid[h]>>w)&1 == 1:
                for i in range(cnt):
                    res[h][w - 1 - i] = cnt
                cnt = 0
            else:
                cnt += 1
        if (grid[h]>>w)&1 == 0:
            for i in range(cnt):
                res[h][w - i] = cnt
    return res

def max2(x,y):
    return x if x > y else y


import sys
input = sys.stdin.readline

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

raw_grid = []
for _ in range(H):
    raw_grid.append(list(input().rstrip()))

grid = []
for h in range(len(raw_grid)):
    temp = 0
    for i, s in enumerate(raw_grid[h]):
        if s=="#":
            temp += 1<<(W-1-i)
    grid.append(temp)

grid_t = []
raw_grid = list(zip(*raw_grid))
for h in range(len(raw_grid)):
    temp = 0
    for i, s in enumerate(raw_grid[h]):
        if s=="#":
            temp += 1<<(H-1-i)
    grid_t.append(temp)

A = make_mat(grid, H, W)
B = list(zip(*make_mat(grid_t, W, H)))

res = 0
for h in range(H):
    for w in range(W):
        res = max2(A[h][w] + B[h][w], res)

print(res-1)

Submission status: Wrong Answer

Solution code:
import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]!='.':
            continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H-1,0,-1):
    for j in range(W-1,0,-1):
        if xs[i][j]==0:
            continue

        if xs[i][j+1]>0:
            x=xs[i][j]=xs[i][j+1]
        else:
            x=xs[i][j]

        if ys[i+1][j]>0:
            y=ys[i][j]=ys[i+1][j]
        else:
            y=ys[i][j]

        ans=max(ans,x+y-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]!='.':
            continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H-1,0,-1):
    for j in range(W-1,0,-1):
        if xs[i][j]==0:
            continue
        x=xs[i][j]=max(xs[i][j],xs[i][j+1])
        y=ys[i][j]=max(ys[i][j],ys[i+1][j])
        ans=max(ans,x+y-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]=='.':
            continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H-1,0,-1):
    for j in range(W-1,0,-1):
        if xs[i][j]==0:
            continue
        x=xs[i][j]=max(xs[i][j],xs[i][j+1])
        y=ys[i][j]=max(ys[i][j],ys[i+1][j])
        ans=max(ans,x+y-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

H,W=map(int,next(sys.stdin).split())

xs=[[0]*(W+2) for _ in range(H+2)]
ys=[[0]*(W+2) for _ in range(H+2)]
for i in range(1,H+1):
    row=next(sys.stdin)
    for j in range(1,W+1):
        if row[j-1]!='.':
            continue
        xs[i][j]=1+xs[i][j-1]
        ys[i][j]=1+ys[i-1][j]

ans=0
for i in range(H-1,0,-1):
    for j in range(W-1,0,-1):
        x=xs[i][j]=max(xs[i][j],xs[i][j+1])
        y=ys[i][j]=max(ys[i][j],ys[i+1][j])
        ans=max(ans,x+y-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import re
import sys
from collections import (
    Counter,
    defaultdict as ddict,
    deque,
    namedtuple as ntuple,
)
from functools import lru_cache
from heapq import *
from itertools import *
from pprint import pprint
from statistics import *
from string import (
    ascii_letters as letters,
    ascii_lowercase as ucletters,
    ascii_uppercase as lcletters,
    digits,
)

cache=lru_cache(None)

hexdigits=digits+'ABCDEFabcdef'

inf=float('inf')
int8_min=-128
int16_min=-32768
int32_min=-2147483648
int64_min=-9223372036854775808
int8_max=127
int16_max=32767
int32_max=2147483647
int64_max=9223372036854775807
uint8_max=255
uint16_max=65535
uint32_max=4294967295
uint64_max=18446744073709551615
ansmod=1000000007

rfs=lambda:rl().split()
ri=lambda:int(rl())
ris=lambda:list(map(int,rfs()))
rl=lambda:next(sys.stdin)
rrs=lambda:list(map(str.strip,sys.stdin))
rs=lambda:rl().strip()
rt=lambda:sys.stdin.read()
rg=lambda:list(map(list,rrs()))
rig=lambda:[[*map(int,x.split())] for x in rls()]

def nbs4(i,j):
    return [
                (i-1,j),
        (i,j-1),        (i,j+1),
                (i+1,j),
    ]

def nbs8(i,j):
    return [
        (i-1,j-1),(i-1,j),(i-1,j+1),
        (  i,j-1),        (  i,j+1),
        (i+1,j-1),(i+1,j),(i+1,j+1),
    ]

inb=lambda i,j,m,n:0<=i<m and 0<=j<n

sys.setrecursionlimit(int32_max)

################################################

H,W=ris()
S=rg()

xs=[[0]*(W+1) for _ in range(H+1)]
ys=[[0]*(W+1) for _ in range(H+1)]
for i in range(H):
    for j in range(W):
        if S[i][j]!='#':
            if j==0:
                xs[i][j]=1
            else:
                xs[i][j]+=1+xs[i][j-1]
            if i==0:
                ys[i][j]=1
            else:
                ys[i][j]+=1+ys[i-1][j]

ans=0
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if xs[i][j+1]:
            x=xs[i][j]=xs[i][j+1]
        else:
            x=xs[i][j]

        if ys[i+1][j]:
            y=ys[i][j]=ys[i+1][j]
        else:
            y=ys[i][j]

        if x+y-1>ans:
            ans=x+y-1

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w = MAP()
s = []
for i in range(h):
    s.append(input())

count_x = 0
for i in range(h):
    tmp = 0
    for j in range(w):
        if s[i][j] == '.':
            tmp += 1
        else:
            count_x = max(count_x, tmp)
            tmp = 0
    count_x = max(count_x, tmp)

count_y = 0
for j in range(w):
    tmp = 0
    for i in range(h):
        if s[i][j] == '.':
            tmp += 1
        else:
            count_y = max(count_y, tmp)
            tmp = 0
    count_y = max(count_y, tmp)

ans = count_x + count_y - 1
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s =["#"*(w+2)] + ["#"+input()+"#" for i in range(h)] + ["#"*(w+2)]
# print(s)
ans = 0
opt = [(0,1),(0,-1),(1,0),(-1,0)]
s2 = [[1]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "." and s2[i][j] == 1:
            cnt = 0
            for k in opt[0:2]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            for k in opt[0:2]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    s2[tempy+k[0]][tempx+k[1]] += cnt
                    tempy += k[0]
                    tempx += k[1]
            s2[i][j] += cnt
            cnt = 0
            for k in opt[2:4]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            for k in opt[2:4]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    s2[tempy+k[0]][tempx+k[1]] += cnt
                    tempy += k[0]
                    tempx += k[1]
            s2[i][j] += cnt
        ans = max(ans,s2[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([int(s == '.') for s in input()])
    S[i] = Si
    
top = np.zeros((H,W))
bottom = np.zeros((H,W))
left = np.zeros((H,W))
right = np.zeros((H,W))

for i in range(1, H):
    top[i] = (top[i-1] + 1) * S[i]
    bottom[-i-1] = (bottom[-i] + 1) * S[i-1]

for j in range(1, W):
    left[:,j] = (left[:,j-1] + 1) * S[:,j-1]
    right[:,-j-1] = (right[:,-j-1] + 1) * S[:,-j]

print(np.max((top + bottom + left + right - 3).astype(np.int)))

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([ 0 if s == '.' else 1 for s in input()])
    S[i] = Si

colmax = 0
for i in range(H):
    colmax = max(max(map(lambda s:np.sum(s==0), np.split(S[i], np.where(S[i] == 1)[0]))), colmax)

rowmax = 0
for j in range(W):
    Sj = S[:,j].flatten()
    rowmax = max(max(map(lambda s:np.sum(s==0), np.split(Sj, np.where(Sj == 1)[0]))), rowmax)

print(colmax + rowmax - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([ 0 if s == '.' else 1 for s in input()])
    S[i] = Si

column_max_spaces = []
for i in range(H):
    column_max_spaces.append(max([np.sum(s==0) for s in np.split(S[i], np.where(S[i] == 1)[0])]))
    
rows_max_spaces = []
for j in range(W):
    Sj = S[:,j].flatten()
    rows_max_spaces.append(max([np.sum(s==0) for s in np.split(Sj, np.where(Sj == 1)[0])]))

print(max(column_max_spaces) + max(rows_max_spaces) - 1)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
data = []
for i in range(h):
    s = input()
    data.append(s)
cnt = [[0] * w for _ in range(h)]
for i in range(h):
    start = 0
    while 1:
        while start <= w - 1 and data[i][start] == "#":
            start += 1
        end = start
        while end < w and data[i][end] == ".":
            end += 1
        for j in range(start, end):
            cnt[i][j] += end - start
        start += end
        if start >= w:
            break

for i in range(w):
    start = 0
    while 1:
        while start <= h - 1 and data[start][i] == "#":
            start += 1
        end = start
        while end < h and data[end][i] == ".":
            end += 1
        for j in range(start, end):
            cnt[j][i] += end - start
        start += end
        if start >= h:
            break
ans = 0

for i in range(h):
    ans = max(ans, max(cnt[i]))
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([ 0 if s == '.' else 1 for s in input()])
    S[i] = Si

# 壁で囲う
S1 = np.hstack((np.ones(H).reshape(-1,1), S))
S1 = np.hstack((S1, np.ones(H).reshape(-1,1)))
S1 = np.vstack((np.ones(W+2), S1))
S1 = np.vstack((S1, np.ones(W+2)))

column_max_spaces = np.zeros(H+2)
for i in range(H+2):
    s = np.cumsum(S1[i])
    max_count = int(np.max(np.unique(s, return_counts=True)[1]) - 1)
    column_max_spaces[i] = max_count

row_max_spaces = np.zeros(W+2)
for j in range(W+2):
    s = np.cumsum(S1[:,j].flatten())
    max_count = int(np.max(np.unique(s, return_counts=True)[1]) - 1)
    row_max_spaces[j] = max_count

print(int(np.max(column_max_spaces) + np.max(row_max_spaces) - 1))

Submission status: Wrong Answer

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

res=[[] for i in range(H)]
for i in range(H):
  count=0
  for j in range(W):
    if S[i][j]=='#':
      if j != 0:
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == W-1:
        res[i].append(count)

cum = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum[i].append(0)
    else:cum[i].extend([res[i][j]]*res[i][j])

res=[[] for i in range(W)]
for i in range(W):
  count=0
  for j in range(H):
    if S[j][i]=='#':
      if j != 0:
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == H-1:
        res[i].append(count)

cum2 = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum2[i].append(0)
    else:cum2[i].extend([res[i][j]]*res[i][j])

ans=0
for i in range(H):
  for j in range(W):
    tmp = cum[i][j]+cum2[j][i]-1
    if tmp > ans:ans=tmp

print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
d1=[[0]*(w+1) for _ in range(h+1)]
d2=[[0]*(w+1) for _ in range(h+1)]
for i in range(h):
  k=1
  for j in range(w):
    if s[i][j]=='.':d1[i+1][k]+=1
    else:k=j+2
  for j in range(w):
    if s[i][j]=='.':d1[i+1][j+1]+=d1[i+1][j]
for j in range(w):
  k=1
  for i in range(h):
    if s[i][j]=='.':d2[k][j+1]+=1
    else:k=i+2
  for i in range(h):
    if s[i][j]=='.':d2[i+1][j+1]+=d2[i][j+1]
ans=0
for i in range(h):
  for j in range(w):
    d1[i][j]+=d2[i][j]-1
  ans=max(ans,max(d1[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
w += 2
h += 2
grid = ["#" * w]

dpx = [[0] * w for _ in range(h)]
dpy = [[0] * w for _ in range(h)]
for y in range(1, h - 1):
    grid.append("#" + input() + "#")
    for x in range(1, w):
        if grid[y][x] == '.':
            dpx[y][x] = dpx[y][x - 1] + 1
            dpy[y][x] = dpy[y - 1][x] + 1
    for x in range(w - 2, 0, -1):
        if dpx[y][x] != 0 and dpx[y][x + 1] != 0:
            dpx[y][x] = dpx[y][x + 1]

max_val = 0
for y in range(h - 2, 0, -1):
    for x in range(1, w - 1):
        if dpy[y][x] != 0 and dpy[y + 1][x] != 0:
            dpy[y][x] = dpy[y + 1][x]
        val = dpy[y][x] + dpx[y][x]
        if dpy[y][x] != 1 and dpx[y][x] != 1:
            val -= 1
        if max_val < val:
            max_val = val
print(max_val)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
w += 2
h += 1
grid = ["#" * w]

dpx = [[0] * w for _ in range(h)]
dpy = [[0] * w for _ in range(h)]
for y in range(1, h):
    grid.append("#" + input() + "#")
    for x in range(1, w):
        if grid[y][x] == '.':
            dpx[y][x] = dpx[y][x - 1] + 1
            dpy[y][x] = dpy[y - 1][x] + 1
    for x in range(w - 2, 0, -1):
        if dpx[y][x] != 0 and dpx[y][x + 1] != 0:
            dpx[y][x] = dpx[y][x + 1]

max_val = 0
for y in range(h - 2, 0, -1):
    for x in range(1, w - 1):
        if dpy[y][x] != 0 and dpy[y + 1][x] != 0:
            dpy[y][x] = dpy[y + 1][x]
        val = dpy[y][x] + dpx[y][x]
        if dpy[y][x] != 1 and dpx[y][x] != 1:
            val -= 1
        if max_val < val:
            max_val = val

print(max_val)

Submission status: Wrong Answer

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  s = rs()
  S.append(s + '#')
S.append('#'*(W+1))

tab = [[0 for _ in range(W+1)] for _ in range(H+1)]

for i in range(H):
  k = 0
  prev = -1
  for j in range(W+1):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k] += n
        k += 1
      tab[i][k] = 0
      k += 1
      prev = j

for j in range(W):
  k = 0
  prev = -1
  for i in range(H+1):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j] += n-1
        k += 1
      tab[k][j] = 0
      k += 1

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, tab[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  S.append(rs())

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

for i in range(H):
  k = 0
  prev = -1
  for j in range(W):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k] += n
        k += 1
      prev = j
  while k < W:
    tab[i][k] += W-prev-1
    k += 1

for j in range(W):
  k = 0
  prev = -1
  for i in range(H):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j] += n
        k += 1
  while k < H:
    tab[k][j] += H-prev-1
    k += 1

ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#': continue
    ans = max(ans, tab[i][j]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  S.append(rs())

tab = [[[0, 0] for _ in range(W)] for _ in range(H)]

for i in range(H):
  k = 0
  prev = -1
  for j in range(W):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k][1] = n
        k += 1
      prev = j
  while k < W:
    tab[i][k][1] = W-prev-1
    k += 1

for j in range(W):
  k = 0
  prev = -1
  for i in range(H):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j][1] = n
        k += 1
  while k < H:
    tab[k][j][0] = H-prev-1
    k += 1

ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#': continue
    ans = max(ans, tab[i][j][0]+tab[i][j][1]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

SS = np.array([[0] * (W+2) for _ in range(H+2)])


for i in range(H+2):
    cnt = 0
    start = 0
    for j in range(W+2):
        if S[i][j] == '#':
            SS[i, start:j] += cnt
            cnt = 0
            start = j + 1
        else:
            cnt += 1

for j in range(W+2):
    cnt = 0
    start = 0
    for i in range(H+2):
        if S[i][j] == '#':
            SS[start:i, j] += cnt
            cnt = 0
            start = i + 1
        else:
            cnt += 1

ans = SS.max()

if ans > 2:
    print(ans - 1)
else:
    print(0)