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:
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['#'*(w+2)]+['#'+input().strip()+'#' for i in range(h)]+['#'*(w+2)]
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][0] == 0:
      dfsw(i,j,1)
    
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
c = [0]*w
r = 0
mr = 0
ar = [list(map(str,input().split())) for _ in range(h)]
#print(ar)
for i in range(len(ar)):
  r = 0
  for j in ar[i]:
    #print(j)
    for k in range(len(j)):
      if j[k]=='.':
        c[k] += 1
        r += 1
        if r > mr:
          mr = r
      elif j[k]=='#':
        r = 0
#print('mr',mr)
#print('c',c)
print(mr+max(c)-1)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
c = [0]*w
r = 0
mr = 0
ar = [list(map(str,input().split())) for _ in range(h)]
#print(ar)
for i in range(len(ar)):
  r = 0
  for j in ar[i]:
    #print(j)
    for k in range(len(j)):
      if j[k]=='.':
        c[k] += 1
        r += 1
        if r > mr:
          mr = r
#print('mr',mr)
#print('c',c)
print(mr+max(c)-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools


def g(acc, x):
    if x == "#":
        res = 0
    elif acc:
        res = acc[-1] + 1
    else:
        res = 1
    acc.append(res)
    return acc


def h(acc, x):
    if x == 0:
        res = 0
    elif acc:
        res = max(acc[-1], x)
    else:
        res = x
    acc.append(res)
    return acc


def f(line):
    res = functools.reduce(g, line, [])
    res = functools.reduce(h, reversed(list(res)), [])
    return res


H, W = map(int, input().split())
grid = [list(input().strip()) for _ in range(H)]


# row_wise = list(map(f, grid))
# col_wise = list(zip(*map(f, zip(*grid))))

## numpy
row_wise = np.apply_along_axis(f, 0, np.array(grid))
col_wise = np.apply_along_axis(f, 1, np.array(grid))

# ans = 0
# for i in range(H):
#     for j in range(W):
#         ans = max(ans, row_wise[i][j] + col_wise[i][j] - 1)

## numpy
ans = (row_wise + col_wise).max() - 1

print(ans)

Submission status: Wrong Answer

Solution code:
input_line = input()
H,W = [int(s) for s in input_line.split(' ') if s]
S = []
matrix = [[0 for _ in range(W+1)] for _ in range(H+1)]

for _ in range(H):
    input_line = input()
    S.append(input_line+'#')
S.append('#'*W)

for i in range(H):
    start = 0
    flag = False
    for j in range(W+1):
        if S[i][j] == '#' and flag:
            for k in range(start, j):
                matrix[i][k] += j-start
            flag = False
        elif S[i][j] == '.' and not flag:
            start = j
            flag = True

# print(matrix)

for i in range(W):
    start = 0
    flag = False
    for j in range(H+1):
        if S[j][i] == '#' and flag:
            for k in range(start, j):
                matrix[k][i] += j-start
            flag = False
        elif S[j][i] == '.' and not flag:
            start = j
            flag = True

print(max(max(matrix))-1)

Submission status: Wrong Answer

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


P = [[None if x == "#" else 0 for x in input()] for _ in range(H)]

Submission status: Wrong Answer

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


P = [[None if x == "#" else [[1],[1]] for x in input()] for _ in range(H)]

Submission status: Wrong Answer

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


class Cell:
    def __init__(self):
        self.Horizon = None
        self.Vertical = None


P = [[None if x == "#" else Cell() for x in input()] for _ in range(H)]

Submission status: Wrong Answer

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


class Cell:
    def __init__(self):
        self.Horizon = None
        self.Vertical = None
    def __repr__(self):
        return str((self.Horizon[0], self.Vertical[0]))

P = [[None if x == "#" else Cell() for x in input()] for _ in range(H)]

Submission status: Wrong Answer

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


class Cell:
    def __init__(self):
        self.Horizon = [1]
        self.Vertical = [1]
    def __repr__(self):
        return str((self.Horizon[0], self.Vertical[0]))

P = [[None if x == "#" else Cell() for x in input()] for _ in range(H)]

Submission status: Wrong Answer

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


class Cell:
    def __init__(self):
        self.Horizon = [1]
        self.Vertical = [1]
    def __repr__(self):
        return str((self.Horizon[0], self.Vertical[0]))

P = [[None if x == "#" else Cell() for x in input()] for _ in range(H)]

for i in range(1, H):
    for j in range(1, W):
        if not P[i][j] is None:
            if not P[i-1][j] is None:
                w = P[i-1][j].Vertical
                w[0] += 1
                P[i][j].Vertical = w
            if not P[i][j-1] is None:
                w = P[i][j-1].Horizon
                w[0] += 1
                P[i][j].Horizon = w

#print(P)
w = 0
for i in range(H):
    for j in range(W):
        if not P[i][j] is None:
            w = max(w, P[i][j].Horizon[0] + P[i][j].Vertical[0]-1)

print(w)

Submission status: Wrong Answer

Solution code:
import functools


def g(acc, x):
    if x == "#":
        res = 0
    elif acc:
        res = acc[-1] + 1
    else:
        res = 1
    acc.append(res)
    return acc


def h(acc, x):
    if x == 0:
        res = 0
    elif acc:
        res = max(acc[-1], x)
    else:
        res = x
    acc.append(res)
    return acc


def f(line):
    res = functools.reduce(g, line, [])
    res = functools.reduce(h, reversed(res), [])
    return res


H, W = map(int, input().split())
grid = [list(input().strip()) for _ in range(H)]

row_wise = list(map(f, grid))
col_wise = list(zip(*map(f, zip(*grid))))

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, row_wise[i][j] + col_wise[i][j] - 1)

# grid = np.array([list(input().strip()) for _ in range(H)])

# row_wise = np.apply_along_axis(f, 0, grid)
# col_wise = np.apply_along_axis(f, 1, grid)
# print((row_wise + col_wise).max() - 1)

# print(row_wise)
# print(col_wise)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
 
H, W = list(map(int, input().split()))
board = []

# H, W = 4, 6
# board = [['#', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '.'], ['#', '.', '#', '.', '.', '.']]

# insert elements to the board
for i in range(H):
	a = list(input())
	board.append(a)


# high_score is output values
high_score = 0
	
# round robin
for h in range(H):
	for w in range(W):
		# print(h, w)
		# board put light is envolved
		score = 1
		# if not obstacle in board[h][w]
		if board[h][w] != "#":
			# DOWN
			for i in range(1, H):
				if h + i == H:
					break
				elif board[h + i][w] == "#":
					break
			score += i - 1
			
			# UP
			for i in range(1, H):
				if h - i == -1:
					break
				elif board[h - i][w] == "#":
					break
			score += i - 1
			
			# RIGHT
			for i in range(1, W):
				if w + i == W:
					break
				elif board[h][w + i] == "#":
					break
			score += i - 1
			
			# LEFT
			for i in range(1, W):
				if w - i == -1:
					break
				elif board[h][w - i] == "#":
					break
			score += i - 1
			
			# print(score)
			if score > high_score:
				high_score = score
				
print(high_score)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
maze = [['#']*(W+2)]
for i in range(H):
    append_str = '#' + input() + '#'
    maze.append(list(append_str))
maze.append(['#']*(W+2))
L = [[0]*(W+2)]
for i in range(H+1):
    L.append([0]*(W+2))
import sys
sys.setrecursionlimit(10000000)
import copy
R = copy.deepcopy(L)
U = copy.deepcopy(L)
D = copy.deepcopy(L)

for h in range(H+2):
    for w in range(W+2):
       if maze[h][w] == '.':
           L[h][w] = L[h][w-1]+1
           U[h][w] = U[h-1][w]+1
       if maze[h][W+2-w-1]=='.':
           R[h][W+2-w-1] = R[h][W+2-w]+1
       if maze[H+2-h-1][w]=='.':
           D[H+2-h-1][w] = D[H+2-h][w]+1
           
ans = -1
for h in range(H):
    for w in range(W):
        ans = max(ans,(L[h][w]+R[h][w]+U[h][w]+D[h][w]-3))
print(ans)

Submission status: Wrong Answer

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

sq = [input() for _ in range(h)]
up = [[0] * (w + 2) for _ in range(h + 2)]
down = [[0] * (w + 2) for _ in range(h + 2)]
left = [[0] * (w + 2) for _ in range(h + 2)]
right = [[0] * (w + 2) for _ in range(h + 2)]

ans = 0

for i in range(h):
    for j in range(w):
        if sq[i][j] == '#':
            left[i][j] = 0
            up[i][j] = 0
        elif i == 0:
            up[i][j] = 1
        elif j == 0:
            left[i][j] = 1
        else:
            left[i][j] = left[i][j - 1] + 1
            up[i][j] = up[i - 1][j] + 1
for _i in range(h - 1, 0, -1):
    for _j in range(w - 1, 0, -1):
        if sq[_i][_j] == '#':
            right[_i][_j] = 0
            down[_i][_j] = 0
        else:
            right[_i][_j] = right[_i][_j + 1] + 1
            down[_i][_j] = down[_i + 1][_j] + 1

            temp = up[_i][_j] + down[_i][_j] + left[_i][_j] + right[_i][_j] 
            if temp > ans:
                ans = temp

print(ans - 3)

Submission status: Wrong Answer

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

sq = [input() for _ in range(h)]
up = [[0] * (w + 2) for _ in range(h + 2)]
down = [[0] * (w + 2) for _ in range(h + 2)]
left = [[0] * (w + 2) for _ in range(h + 2)]
right = [[0] * (w + 2) for _ in range(h + 2)]

ans = 0

for i in range(h):
    for j in range(w):
        if sq[i][j] == '#':
            left[i][j] = 0
            up[i][j] = 0
        else:
            left[i][j] = left[i][j - 1] + 1
            up[i][j] = up[i-1][j] + 1
for _i in range(h - 1, 0, -1):
    for _j in range(w - 1, 0, -1):
        if sq[_i][_j] == '#':
            right[_i][_j] = 0
            down[_i][_j] = 0
        else:
            right[_i][_j] = right[_i][_j + 1] + 1
            down[_i][_j] = down[_i + 1][_j] + 1

            temp = up[_i][_j] + down[_i][_j] + left[_i][_j] + right[_i][_j] 
            if temp > ans:
                ans = temp

print(ans - 3)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int,input().split())
S = np.array([list(input()) for _ in range(H)])
horizon = np.zeros((H, W))
vertical = np.zeros((H, W))

# まず横方向に走査
for i in range(H):
  j = 0
  while(j < W):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      j += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(j + l < W):
      if(S[i][j + l] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    horizon[i][j:j+inc] = inc
    j += inc
    
# お行儀悪いけど同じことを縦方向にします
for j in range(W):
  i = 0
  while(i < H):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      i += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(i + l < H):
      if(S[i + l][j] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    for a in range(i, i+inc):
      vertical[a][j] = inc
    i += inc
      
total = np.max(horizon + vertical) - 1
print(max(total, 0))

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W = map(int,input().split())
S = np.array([list(input()) for _ in range(H)])
horizon = np.zeros((H, W))
vertical = np.zeros((H, W))

# まず横方向に走査
for i in range(H):
  j = 0
  while(j < W):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      j += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(j + l < W):
      if(S[i][j + l] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    horizon[i][j:j+inc] = inc
    j += inc
    
# お行儀悪いけど同じことを縦方向にします
for j in range(W):
  i = 0
  while(i < H):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      i += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(i + l < H):
      if(S[i + l][j] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    for a in range(i, i+inc):
      vertical[a][j] = inc
    i += inc
      
      
print(np.max(horizon + vertical)-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
D - Lamp
https://atcoder.jp/contests/abc129/tasks/abc129_d

"""
import sys


def solve(H, W, grid):
    res_x = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while y < H:
        while x < W:
            if grid[y][x] == '#':
                x += 1
                continue
            rx = x
            while rx < W and grid[y][rx] != '#':
                rx += 1
            for xx in range(x, rx):
                res_x[y][xx] = rx-x
            x = rx
        x = 0
        y += 1

    res_y = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while x < W:
        while y < H:
            if grid[y][x] == '#':
                y += 1
                continue
            ry = y
            while ry < H and grid[ry][x] != '#':
                ry += 1
            for yy in range(y, ry):
                res_y[yy][x] = ry-y
            y += ry
        y = 0
        x += 1

    ans = 0
    for y in range(H):
        for x in range(W):
            t = res_x[y][x] + res_y[y][x] - 1
            if t > ans:
                ans = t
    return ans


def main(args):
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]
    ans = solve(H, W, grid)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
for i in range(h):
  l[i][0] = int(s[i][0] != "#")
  for j in range(1,w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "#")
  for j in range(w-2,-1,-1):
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "#")
  for j in range(1,h):
    if s[j][i] == "#":
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "#")
  for j in range(h-2,-1,-1):
    if s[j][i] == "#":
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019 6/10
# ABC129 D Lamp

import time

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

max_square = 1

# vector
dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]


def search_linear(x, y):
    count = 1
    for i in range(4):
        constant = 1
        while True:
            next_p = maze[y + dy[i] * constant][x + dx[i] * constant]
            print('y, dy[i], constant', y, dy[i], constant)
            if next_p == '#':
                break
            constant += 1
            count += 1
    return count


for height in range(1,  H + 1):
    for width in range(1, W + 1):
        if maze[height][width] != '#':
            tmp_max_square = search_linear(width, height)
            max_square = max(max_square, tmp_max_square)

print(max_square)

Submission status: Wrong Answer

Solution code:
# 2019 6/10
# ABC129 D Lamp

import time

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

max_square = 0

# vector
dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]


def search_linear(x, y):
    count = 0
    for i in range(4):
        constant = 1
        while True:
            next_p = maze[y + dy[i] * constant][x + dx[i] * constant]
            print('y, dy[i], constant', y, dy[i], constant)
            if next_p == '#':
                break
            constant += 1
            count += 1
    return count


for height in range(1,  H + 1):
    for width in range(1, W + 1):
        if maze[height][width] != '#':
            tmp_max_square = search_linear(width, height)
            max_square = max(max_square, tmp_max_square)

print(max_square)

Submission status: Wrong Answer

Solution code:
H,W =list(map(int,input().split(" ")))
mass  = []
for _ in range(H):
    mass.append(input() + "#")

mass.append((W+1)*"#")
tate = [[0 for _ in range(W+1)] for _ in range(H+1)]
yoko = [[0 for _ in range(W+1)] for _ in range(H+1)]
co = 0
for w in range(W+1):
    st = 0
    for h in range(H+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,h):
                tate[temp][w] = co
            st = h + 1
            co = 0
        else:
            co += 1

co = 0
for h in range(H+1):
    st = 0
    for w in range(W+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,w):
                yoko[h][temp] = co
            st = h + 1
            co = 0
        else:
            co += 1



ans = 0
for h in range(H):
    for w in range(W):
        if tate[h][w] + yoko[h][w]-1 > ans and mass[h][w] != "#":
            ans = tate[h][w] + yoko[h][w] -1

print(ans)

Submission status: Wrong Answer

Solution code:
H,W =list(map(int,input().split(" ")))
mass  = []
for _ in range(H):
    mass.append(input() + "#")

mass.append((W+1)*"#")
tate = [[0 for _ in range(W+1)] for _ in range(H+1)]
yoko = [[0 for _ in range(W+1)] for _ in range(H+1)]
co = 0
for w in range(W+1):
    st = 0
    for h in range(H+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,h):
                tate[temp][w] = co
            st = h + 1
            co = 0
        else:
            co += 1

co = 0
for h in range(H+1):
    st = 0
    for w in range(W+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,w):
                yoko[h][temp] = co
            st = h + 1
            co = 0
        else:
            co += 1



ans = 0
for h in range(H):
    for w in range(W):
        if tate[h][w] + yoko[h][w]-1 > ans and mass[h][w] != "#":
            ans = tate[h][w] + yoko[h][w] -1

print()

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
G=[list(input()) for i in range(h)]
L=[[0]*w for i in range(h)]
R=[[0]*w for i in range(h)]
U=[[0]*w for i in range(h)]
D=[[0]*w for i in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if G[i][j]=="#":
      L[i][j]=0
      R[i][j]=0
      U[i][j]=0
      D[i][j]=0
    else:
      if j==0:
        L[i][j]=1
        if G[i][w-1]=="#":
          R[i][w-1]=0
        else:
          R[i][w-1]=1
      else:
        L[i][j]=L[i][j-1]+1
        R[i][w-j-1]=R[i][w-j]+1
      if i==0:
        U[i][j]=1
        if G[h-1][j]=="#":
          D[h-1][j]=0
        else:
          D[h-1][j]=1
      else:
        U[i][j]=U[i-1][j]+1
        D[h-i-1][j]=D[h-i][j]+1

ans=0
for i in range(h):
  for j in range(w):
    if G[i][j]==".":
      if ans<L[i][j]+R[i][j]+U[i][j]+D[i][j]-3:
        ans=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3

print(ans)

Submission status: Wrong Answer

Solution code:
H,W =list(map(int,input().split(" ")))
mass  = []
for _ in range(H):
    mass.append(input() + "#")

mass.append((W+1)*"#")
tate = [[0 for _ in range(W+1)] for _ in range(H+1)]
yoko = [[0 for _ in range(W+1)] for _ in range(H+1)]
co = 0
for w in range(W+1):
    st = 0
    for h in range(H+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,h):
                tate[temp][w] = co
            st = h + 1
            co = 0
        else:
            co += 1

co = 0
for h in range(H+1):
    st = 0
    for w in range(W+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,w):
                yoko[h][temp] = co
            st = h + 1
            co = 0
        else:
            co += 1



ans = 0
for h in range(H):
    for w in range(W):
        if tate[h][w] + yoko[h][w] > ans and mass[h][w] != "#":
            ans = tate[h][w] + yoko[h][w]

print(ans-1)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
G=[list(input()) for i in range(h)]
  
def left(Y,X):
  ans=0
  if X>0:
    for i in range(X+1):
      if G[Y][i]==".":
        ans+=1
      else:
        ans=0
  return ans

def right(Y,X):
  ans=0
  if X<w:
    for i in range(X,w):
      if G[Y][i]==".":
        ans+=1
      else:
        break
  return ans

def up(Y,X):
  ans=0
  if Y>0:
    for i in range(Y+1):
      if G[i][X]==".":
        ans+=1
      else:
        ans=0
  return ans

def down(Y,X):
  ans=0
  if Y<h:
    for i in range(Y,h):
      if G[i][X]==".":
        ans+=1
      else:
        break
  return ans


max_ans=0
for i in range(h):
  for j in range(w):
#    print((i,j),G[i][j],left(i,j),right(i,j),up(i,j),down(i,j))
    if G[i][j]==".":
      if left(i,j)+right(i,j)+up(i,j)+down(i,j)-3>max_ans:
        max_ans=left(i,j)+right(i,j)+up(i,j)+down(i,j)-3
print(max_ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
G=[list(input()) for i in range(h)]
  
def left(Y,X):
  ans=0
  if X>0:
    for i in range(X+1):
      if G[Y][i]==".":
        ans+=1
      else:
        ans=0
  return ans

def right(Y,X):
  ans=0
  if X<w:
    for i in range(X,w):
      if G[Y][i]==".":
        ans+=1
      else:
        break
  return ans

def up(Y,X):
  ans=0
  if Y>0:
    for i in range(Y+1):
      if G[i][X]==".":
        ans+=1
      else:
        ans=0
  return ans

def down(Y,X):
  ans=0
  if Y<h:
    for i in range(Y,h):
      if G[i][X]==".":
        ans+=1
      else:
        break
  return ans


max_ans=0
for i in range(h):
  for j in range(w):
#    print((i,j),G[i][j],left(i,j),right(i,j),up(i,j),down(i,j))
    if left(i,j)+right(i,j)+up(i,j)+down(i,j)-3>max_ans:
      max_ans=left(i,j)+right(i,j)+up(i,j)+down(i,j)-3
print(max_ans)

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())

L = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            L[i][j]=0
            continue
        if(j==0):
            L[i][j]=1
            continue
        L[i][j]=L[i][j-1]+1

S = [[0]*w for _ in range(h)]
for j in range(w):
    for i in range(h):
        if(s[i][j]=="#"):
            S[i][j]=0
            continue
        if(i==0):
            S[i][j]=1
            continue
        S[i][j]=S[i-1][j]+1

W = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w-1,0,-1):
        if(s[i][j]=="#"):
            W[i][j]=0
            continue
        if(j==w-1):
            W[i][j]=1
            continue
        W[i][j]=W[i][j+1]+1

N = [[0]*w for _ in range(h)]
for j in range(w):
    for i in range(h-1,0,-1):
        if(s[i][j]=="#"):
            N[i][j]=0
            continue
        if(i==h-1):
            N[i][j]=1
            continue
        N[i][j]=N[i+1][j]+1

result=0
for i in range(h):
    for j in range(w):
        result=max(result,L[i][j]+S[i][j]+W[i][j]+N[i][j]-3)

print(result)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n,m = LI()
    a = [[c=='#' for c in l] for l in sys.stdin.readlines()] + [[True] * m]
    b = [[None] * m for _ in range(n)]
    for i in range(n):
        j = 0
        ai = a[i] + [True]
        bi = b[i]
        while j < m:
            if ai[j]:
                j += 1
            else:
                k = j+1
                while not ai[k]:
                    k += 1
                s = k - j
                bi[j] = s
                if k < m:
                    bi[k] = 0
                j = k

    r = 0
    c = [0] * n
    for j in range(m):
        for i in range(n):
            if b[i][j] is None:
                continue
            c[i] = b[i][j]
        i = 0
        while i < n:
            if a[i][j]:
                i += 1
            else:
                k = i+1
                while not a[k][j]:
                    k += 1
                s = k - i
                t = max(c[i:k]) + s
                if r < t:
                    r = t
                i = k


    return r - 1


print(main())

Submission status: Wrong Answer

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

if h == 1 and w == 1:
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

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

c = 0

for i in range(h):
    mode = 0
    for j in range(w):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                a[i][j] = 1
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                a[i][j] = c
            else:
                mode = 0

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

for j in range(w):
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                b[i][j] = c
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                b[i][j] = c
            else:
                mode = 0

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Submission status: Wrong Answer

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

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

c = 0

for i in range(h):
    mode = 0
    for j in range(w):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                a[i][j] = 1
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                a[i][j] = c
            else:
                mode = 0

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

for j in range(w):
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                b[i][j] = c
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                b[i][j] = c
            else:
                mode = 0

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    ans_width = 0
    for i in range(high):
        kari = 0
        for j in range(width):
            if data[i][j] == '.':
                kari += 1
            else:
                if kari > ans_width:
                    ans_width = kari
                    kari = 0
        if kari > ans_width:
            ans_width = kari


    ans_high = 0
    for i in range(width):
        kari = 0
        for j in range(high):
            if data[j][i] == '.':
                kari += 1
            else:
                if kari > ans_high:
                    ans_high = kari
                    kari = 0
        if kari > ans_high:
            ans_high = kari


    print(ans_width + ans_high - 1)



if __name__ == '__main__':
    main()