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: Runtime Error

Solution code:
H, W = map(int, input().split())
import sys
input = sys.stdin.readline
def sc(s):
    b = None
    nc = 0
    kk = [0]*len(s)
    for i, c in enumerate(s):
        if c == ".":
            if c == b:
                nc += 1
            else:
                si = i
        else:
            if b == ".":
                for j in range(si, i):
                    kk[j] = i - si
            nc = 0
        b = c
    return kk
d = []
d2 = []
d3 = [[0]*W for _ in range(H)]
for h in range(H):
    s = input().strip() + "#"
    d.append(s)
    d2.append(sc(s))

r = 0
for i in range(H):
    for j in range(W):
        r = max(r, d2[i][j] + d3[j][i]-1)
print(r)

Submission status: Runtime Error

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

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() for _ in range(h)]

  L=[[0 for _ in range(w)]for __ in range(h)]
  R=[[0 for _ in range(w)]for __ in range(h)]
  D=[[0 for _ in range(w)]for __ in range(h)]
  U=[[0 for _ in range(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 i==0:
        U[i][j]=1

      if j==0:
        L[i][j]=1

      if i!=0 and j!=0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if s[i][j]=='#':
        R[i][j]=0
        continue

      if i==h-1:
        D[i][j]=1

      if j==w-1:
        R[i][j]=1

      if i!=h-1 and j!=w-1:
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1

  ans=0
  for i in range(h):
    for j in range(w):
      ans=max(ans,R[i][j]+L[i][j]+U[i][j]+D[i][j]-3)

  return ans

# main()
print(main())
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() for _ in range(h)]

  L=[[0 for _ in range(w)]for __ in range(h)]
  R=[[0 for _ in range(w)]for __ in range(h)]
  D=[[0 for _ in range(w)]for __ in range(h)]
  U=[[0 for _ in range(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 i==0:
        U[i][j]=1

      if j==0:
        L[i][j]=1

      if i!=0 and j!=0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if s[i][j]=='#':
        R[i][j]=0
        continue

      if i==h-1:
        D[i][j]=1

      if j==w-1:
        R[i][j]=1

      if i!=h-1 and j!=w-1:
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1

  ans=0
  for i in range(h):
    for j in range(w):
      ans=max(ans,R[i][j]+L[i][j]+U[i][j]+D[i][j]-3)

  return ans

# main()
print(main())

Submission status: Runtime Error

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

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() for _ in range(h)]

  ans=0
  for i in range(h):
    for j in range(w):
      if s[i][j]=='#':
        continue

      _ans=-1
      s1=s[a]
      for a in range(i)[::-1]:
        if s1[j]=='.':
          _ans+=1
        else:
          break
      for a in range(i,h):
        if s1[j]=='.':
          _ans+=1
        else:
          break
      for a in range(j)[::-1]:
        if s[i][a]=='.':
          _ans+=1
        else:
          break
      for a in range(j,w):
        if s[i][a]=='.':
          _ans+=1
        else:
          break

      ans=max(ans,_ans)
  return ans

# main()
print(main())

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
yoko=[[0]*w for _ in range(h)]
tate=[[0]*w for _ in range(h)]
count=0
for i in range(h):
    a=[0]
    for j in range(w):
        if s[i][j]=="#":
            a.append(j+1)
    a.append(w+1)
    for j in range(1,len(a)):
        for k in range(a[j-1],a[j]-1):
            yoko[i][k]=a[j]-a[j-1]-1
for i in range(w):
    a=[0]
    for j in range(h):
        if s[j][i]=="#":
            a.append(j+1)
    a.append(h+1)
    for j in range(1,len(a)):
        for k in range(a[j-1],a[j]-1):
            tate[k][i]=a[j]-a[j-1]-1

ans=1
for i in range(w):
    for j in range(h):
        ans=max(ans,yoko[i][j]+tate[i][j]-1)
print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=input()
  
L=[[0 for i in range(w)] for j in range(h)]
R=[[0 for i in range(w)] for j in range(h)]
U=[[0 for i in range(w)] for j in range(h)]
D=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  if grid[i][0]=="#":
    L[i][0]=0
  else:
    L[i][0]=1
  for l in range(1,w):
    if grid[i][l]=="#":
      L[i][l]=0
    else:
      L[i][l]=L[i][l-1]+1
      
  if grid[i][-1]=="#":
    R[i][-1]=0
  else:
    R[i][-1]=1
  for r in range(w-2,-1,-1):
    if grid[i][r]=="#":
      R[i][r]=0
    else:
      R[i][r]=R[i][r+1]+1
      
for j in range(w):
  if grid[0][j]=="#":
    U[0][j]=0
  else:
    U[0][j]=1
  for u in range(1,h):
    if grid[u][j]=="#":
      U[u][j]=0
    else:
      U[u][j]=U[u][j-1]+1
      
  if grid[-1][j]=="#":
    D[-1][j]=0
  else:
    D[-1][j]=1
  for d in range(h-2,-1,-1):
    if grid[d][j]=="#":
      D[d][j]=0
    else:
      D[d][j]=D[d][j+1]+1
      
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j])

print(ans-3)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
grid=[None]*h

for i in range(h):
  grid[i]=input()

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="#":
      left+=1
      right=left
      continue
    while s[right+1]=="." and right+1<len(s):
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="#":
      up+=1
      down=up
      continue
    while grid[down+1][i]=="." and down+1<h:
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-right
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
grid = []
# h, w = 4, 6
ans = 0
max_ans = 0
for i in range(h):
    array = input()
    grid.append(array)
# grid = ['#..#..',
#         '.....#',
#         '....#.',
#         '#.#...']

def step(i,j, direction):
    global count
    if i < 0 or i >= h or j < 0 or j >= w:
        return count
    if grid[i][j] == '#':
        return count
    else:
        if direction == 'left':
            count += 1
            step(i, j-1, 'left')
        elif direction == 'right':
            count += 1
            step(i, j+1, 'right')
        elif direction == 'up':
            count += 1
            step(i-1, j, 'up')
        elif direction == 'down':
            count += 1
            step(i+1, j, 'down')

def check(y_loc, x_loc):
    global count
    count = 0
    step(y_loc, x_loc-1, 'left')
    (x_loc, y_loc) = (x_loc, y_loc)
    step(y_loc, x_loc+1, 'right')
    (x_loc, y_loc) = (x_loc, y_loc)
    step(y_loc-1, x_loc, 'up')
    (x_loc, y_loc) = (x_loc, y_loc)
    step(y_loc+1, x_loc, 'down')
    return count

for i in range(h):
    for j in range(w):
        if grid[i][j] == '.':
            ans = check(i, j)
            if ans >= max_ans:
                max_ans = ans

print(max_ans+1)

Submission status: Runtime Error

Solution code:
Unsolved

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)


def calc(x, isTrans):
    if isTrans:
        y = np.copy(x.T)
    else:
        y = np.copy(x)

    for i in range(len(y)):
        xxx = np.copy(y[i])
        tmp_l = np.arange(len(xxx))
        tmp_l[xxx > 0] = 0
        np.maximum.accumulate(tmp_l, out=tmp_l)
        left = tmp_l

        xxx_reverse = xxx[::-1]
        tmp_r = np.arange(len(xxx_reverse))
        tmp_r[xxx_reverse > 0] = 0
        np.maximum.accumulate(tmp_r, out=tmp_r)
        right = len(xxx)-tmp_r[::-1]-1

        y[i] = right-left-1
        y[i][xxx == 0] = 0

    if isTrans:
        return np.transpose(y)
    else:
        return y


if __name__ == "__main__":
    h, w = map(int, readline().split())
    room = np.zeros((h+2, w+2), dtype=np.int)
    for i in range(1, h+1):
        room[i][1:-1] = [0 if i == "#" else 1 for i in input()]

    a = calc(room, True)
    b = calc(room, False)
    ans = (a + b).max() - 1
    print(ans)

Submission status: Runtime Error

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

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,cnt+1):
                yoko[i][k] = cnt
            cnt = 0
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,cnt+1)
                tate[k][i] = cnt
            cnt = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j])
print(ans)

Submission status: Runtime Error

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

a = [[0]*w for _ in range(w)]
for i in range(h):
    k = 0
    for j in range(w):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
for i in range(h):
    k = 0
    for j in reversed(range(w)):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
for j in range(w):
    k = 0
    for i in range(h):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
for j in range(w):
    k = 0
    for i in reversed(range(h)):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
b = max([max(i) for i in a])
print(0 if b == 0 else b-3)

Submission status: Runtime Error

Solution code:
# 2019-11-14 10:01:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    H, W = [int(x) for x in sys.stdin.readline().split()]
    grid = ['#' * (W + 2)]
    for _ in range(H):
        s = f'#{sys.stdin.readline().rstrip()}#'
        grid.append(s)
    grid.append('#' * (W + 2))
    
    lighted_squares = []
    for h in range(1, H+1):
        for w in range(1, W+1):
            if grid[h][w] == '#':
                lighted_squares.append(0)
            else:
                count = 1
                for j in range(w-1, -1, -1):
                    if grid[h][j] == '.':
                        count += 1
                        continue
                    else:
                        break
                for j in range(w+1, W+2):
                    if grid[h][j] == '.':
                        count += 1
                        continue
                    else:
                        break
                for i in range(h-1, -1, -1):
                    if grid[i][w] == '.':
                        count += 1
                        continue
                    else:
                        break
                for i in range(h+1, H+2):
                    if grid[i][w] == '.':
                        count += 1
                        continue
                    else:
                        break
                lighted_squares.append(count)
    
    print(max(lighted_squares))




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

vector<string> read();
int think(const vector<string> &);
void write(int);

void debug(vector< vector<int> >);

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  auto input = read();
  auto output = think(input);
  write(output);

  return 0;
}

vector<string> read() {
  int h, w;
  string buf;
  auto input = vector<string>();

  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> buf;
    buf = buf.substr(0, w);
    input.push_back(buf);
  }
  return input;
}

int think(const vector<string> &input) {
  char WALL = '#';
  auto h = input.size();
  auto w = input.at(0).size();

  auto left = vector< vector<int> >(h, vector<int> (w, 0));
  auto right = vector< vector<int> >(h, vector<int> (w, 0));
  auto up = vector< vector<int> >(h, vector<int> (w, 0));
  auto down = vector< vector<int> >(h, vector<int> (w, 0));

  // update left
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (input.at(y).at(x) == WALL) {
        continue;
      }
      if (x == 0) {
        continue;
      }
      left.at(y).at(x) = (input.at(y).at(x - 1) == WALL ? 0 : left.at(y).at(x - 1) + 1);
    }
  }

  // update left
  for (int y = 0; y < h; y++) {
    for (int x = w - 1; x >= 0; x--) {
      if (input.at(y).at(x) == WALL) {
        continue;
      }
      if (x == w - 1) {
        continue;
      }
      right.at(y).at(x) = (input.at(y).at(x + 1) == WALL ? 0 : right.at(y).at(x + 1) + 1);
    }
  }

  // update up
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (input.at(y).at(x) == WALL) {
        continue;
      }
      if (y == 0) {
        continue;
      }
      up.at(y).at(x) = (input.at(y - 1).at(x) == WALL ? 0 : up.at(y - 1).at(x) + 1);
    }
  }

  // update down
  for (int y = h - 1; y >= 0; y--) {
    for (int x = 0; x < w; x++) {
      if (input.at(y).at(x) == WALL) {
        continue;
      }
      if (y == h - 1) {
        continue;
      }
      down.at(y).at(x) = (input.at(y + 1).at(x) == WALL ? 0 : down.at(y + 1).at(x) + 1);
    }
  }

  // debug(left);
  // cout << endl;
  // debug(right);
  // cout << endl;
  // debug(up);
  // cout << endl;
  // debug(down);
  // cout << endl;

  int maximumBrightCells = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (input.at(y).at(x) == WALL) {
        continue;
      }
      maximumBrightCells = max(maximumBrightCells, left.at(y).at(x) + right.at(y).at(x) + up.at(y).at(x) + down.at(y).at(x) + 1);
    }
  }
  return maximumBrightCells;
}

void write(int output) {
  cout << output << endl;
}

void debug(vector< vector<int> > what) {
  auto h = what.size();
  auto w = what.at(0).size();

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cout << " " << what.at(y).at(x);
    }
    cout << endl;
  }
}

Submission status: Runtime Error

Solution code:
H, W = [int(i) for i in input().split(" ")]
S = []
for i in range(H):
  S.append(input())
  
import numpy as np

r_lens = []
for s in S:
  counts = [len(block) for block in s.split("#")]
  
  r_len = []
  for c in counts:
    r_len+=[c]*c
    r_len+=[0]
  r_lens.append(r_len)
r_lens = np.array(r_lens)

S2 = [""]*W
for h in range(H):
  for w in range(W):
    S2[w] += S[h][w]
    
c_lens = []
for s in S2:
  counts = [len(block) for block in s.split("#")]
  
  c_len = []
  for c in counts:
    c_len+=[c]*c
    c_len+=[0]
  c_lens.append(c_len)
c_lens = np.array(c_lens)

print((r_lens+c_lens+1).max())

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
s = ["#"*(w+2)]+["#"+input()+"#" for _ in range(h)]+["#"*(w+2)]
res = 0
def migi(i,j):
    if s[i][j+1] == ".":
        return migi(i,j+1)+1
    else:
        return 0
def hidari(i,j):
    if s[i][j-1] == ".":
        return hidari(i,j-1)+1
    else:
        return 0
def ue(i,j):
    if s[i-1][j] == ".":
        return ue(i-1,j)+1
    else:
        return 0
def shita(i,j):
    if s[i+1][j] == ".":
        return shita(i+1,j)+1
    else:
        return 0
    
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            res = max(res,migi(i,j)+hidari(i,j)+ue(i,j)+shita(i,j)+1)
            if res == h+w-1:break

print(res)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
res = 0
def migi(i,j):
    if j >= w-1:
        return 0
    if s[i][j+1] == ".":
        return migi(i,j+1)+1
    else:
        return 0
def hidari(i,j):
    if j <= 0:
        return 0
    if s[i][j-1] == ".":
        return hidari(i,j-1)+1
    else:
        return 0
def ue(i,j):
    if i <= 0:
        return 0
    if s[i-1][j] == ".":
        return ue(i-1,j)+1
    else:
        return 0
def shita(i,j):
    if i >= h-1:
        return 0
    if s[i+1][j] == ".":
        return shita(i+1,j)+1
    else:
        return 0
    
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            res = max(res,migi(i,j)+hidari(i,j)+ue(i,j)+shita(i,j)+1)
            if res == h+w-1:break

print(res)

Submission status: Runtime Error

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

def solve(H: int, W: int, S: "List[str]"):
    ss = [list(s) for s in S]
    answer = 0
    right = [[0]*W for _ in range(H)]
    left = [[0]*W for _ in range(H)]
    up = [[0]*W for _ in range(H)]
    down = [[0]*W for _ in range(H)]

    for h in range(H):
        for j in range(W):
            if ss[h][j] == ".":
                if j>0:
                    right[h][j] = 1+right[h][j-1]
                else:
                    right[h][j] += 1
            else:
                right[h][j] = 0

        for j in range(W-1,-1,-1):
            if ss[h][j] == ".":
                if j<W-1:
                    left[h][j] = 1+left[h][j+1]
                else:
                    left[h][j] += 1
            else:
                left[h][j] = 0
    for w in range(W):                
        for i in range(H-1,-1,-1):
            if ss[i][w] == '.':
                if i < H-1:
                    up[i][w] = 1 + up[i+1][w]
                else:
                    up[i][w] +=1
            else:
                up[i][w] = 0
        for i in range(0,H):
            if ss[i][w] == '.':
                if i > 0:
                    down[i][w] = 1 + down[i-1][w]
                else:
                    down[i][w] +=1
            else:
                down[i][w] = 0

    for i in range(H):
        for j in range(W):
            answer = max(answer,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)

    print(answer)
    return


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: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
dpr = [[None] * W for _ in range(H)]
dpl = [[None] * W for _ in range(H)]
dpd = [[None] * W for _ in range(H)]
dpu = [[None] * W for _ in range(H)]

for i in range(H):
    s.append(input())

# to right
for i in range(H):
    for j in reversed(range(W-1)):
        if s[i][j] == '#':
            dpr[i][j] = 0
        else:
            dpr[i][j] = dpr[i][j+1] + 1

# to left
for i in range(H):
    for j in range(1, W):
        if s[i][j] == '#':
            dpl[i][j] = 0
        else:
            dpl[i][j] = dpr[i][j-1] + 1

# to down
for i in reversed(range(H-1)):
    for j in range(W):
        if s[i][j] == '#':
            dpd[i][j] = 0
        else:
            dpd[i][j] = dpd[i+1][j] + 1

# to up
for i in range(1, H):
    for j in range(W):
        if s[i][j] == '#':
            dpu[i][j] = 0
        else:
            dpu[i][j] = dpu[i-1][j] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        cnt = dpr[i][j] + dpl[i][j] + dpd[i][j] + dpu[i][j] - 3
        ans = max(ans, cnt)

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
        dpr[h][w] = dpr[h][w-1] - 1
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
                if dpr[h][i] is not None:
                    rcnt += dpr[h][i] + 1
                    break
                else:
                    rcnt += 1
            else:
                break
        dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
        dpl[h][w] = lcnt

    # to down
    if h > 0 and s[h-1][w] == '.' and s[h][w] == '.' and dpd[h-1][w] is not None:
        dpd[h][w] = dpd[h-1][w] - 1
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
                if dpr[i][w] is not None:
                    dcnt += dpd[i][w] + 1
                    break
                else:
                    dcnt += 1
            else:
                break
        dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
        dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
        dpr[h][w] = dpr[h][w-1] - 1
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
                if dpr[h][i] is not None:
                    rcnt += dpr[h][i] + 1
                    break
                else:
                    rcnt += 1
            else:
                break
        dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
        dpl[h][w] = lcnt

    # to down
    if h > 0 and s[h-1][w] == '.' and s[h][w] == '.' and dpr[h-1][w] is not None:
        dpr[h][w] = dpr[h-1][w] - 1
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
                if dpr[i][w] is not None:
                    dcnt += dpd[i][w] + 1
                    break
                else:
                    dcnt += 1
            else:
                break
        dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
        dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
        dpr[h][w] = dpr[h][w-1] - 1
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
                if dpr[h][i] is not None:
                    rcnt += dpr[h][i] + 1
                    break
                else:
                    rcnt += 1
            else:
                break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    if h > 0 and s[h-1][w] == '.' and s[h][w] == '.' and dpr[h-1][w] is not None:
        dpr[h][w] = dpr[h-1][w] - 1
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
                if dpr[i][w] is not None:
                    dcnt += dpd[i][w] + 1
                    break
                else:
                    dcnt += 1
            else:
                break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    # if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
    #     dpr[h][w] = dpr[h][w-1] - 1
    # else:
    for i in range(w+1, W):
        if s[h][i] == '.':
            if dpr[h][i] is not None:
                rcnt += dpr[h][i] + 1
                break
            else:
                rcnt += 1
        else:
            break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    for i in range(h+1, H):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                dcnt += dpd[i][w] + 1
                break
            else:
                dcnt += 1
        else:
            break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)