Problem p03014 (python)

Fixed submission:
import numpy as np
import sys


def get_data(stream):
    buf = b''
    b = stream.buffer.read(1)
    while b != b'\n':
        buf += b
        b = stream.buffer.read(1)
    H, W = map(int, buf.split())
    c = stream.buffer.read(H * (W + 1))
    arr = np.array(c.split())
    arr = np.frombuffer(arr, dtype='S1').reshape((H, W))
    return H, W, arr


def main():
    H, W, arr = get_data(sys.stdin)
    a = arr == b'.'
    L = np.empty((H, W), dtype='i8')
    R = np.empty((H, W), dtype='i8')
    T = np.empty((H, W), dtype='i8')
    B = np.empty((H, W), dtype='i8')
    T[0] = a[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * a[i]
    B[-1] = a[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * a[i]
    L[:, 0] = a[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * a[:, i]
    R[:, -1] = a[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * a[:, i]

    print((T + B + L + R - 3).max())


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys


def calc(a, H, W):
    # 横方向
    for j in range(H):
        prev = 0
        start = 0
        for i in range(W + 1):
            if a[j, i] > 0:
                if prev == 0:
                    start = i
                    prev = 1
            else:
                if prev == 1:
                    num = i - start
                    a[j, start:i] = num
                    prev = 0
    # 縦方向
    for i in range(W):
        prev = 0
        start = 0
        for j in range(H + 1):
            if a[j, i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    num = j - start - 1
                    a[start:j, i] += num
                    prev = 0


def get_data(stream):
    buf = b''
    b = stream.buffer.read(1)
    while b != b'\n':
        buf += b
        b = stream.buffer.read(1)
    H, W = map(int, buf.split())
    c = stream.buffer.read(H * (W + 1))
    arr = np.array(c.split())
    arr = np.frombuffer(arr, dtype='S1').reshape((H, W))
    return H, W, arr


def main():
    H, W, arr = get_data(sys.stdin)
    a = np.zeros((H + 1, W + 1), dtype='i8')
    a[:-1, :-1] = arr == b'.'

    calc(a, H, W)
    print(a.max())


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys


def calc(a, H, W):
    # 横方向
    for j in range(H):
        prev = 0
        start = 0
        for i in range(W + 1):
            if a[j, i] > 0:
                if prev == 0:
                    start = i
                    prev = 1
            else:
                if prev == 1:
                    num = i - start
                    a[j, start:i] = num
                    prev = 0
    # 縦方向
    for i in range(W):
        prev = 0
        start = 0
        for j in range(H + 1):
            if a[j, i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    num = j - start - 1
                    a[start:j, i] += num
                    prev = 0


def get_data(stream):
    buf = b''
    b = stream.buffer.read(1)
    while b != b'\n':
        buf += b
        b = stream.buffer.read(1)
    H, W = map(int, buf.split())
    c = stream.buffer.read(H * (W + 1))
    arr = np.array(c.split())
    arr = np.frombuffer(arr, dtype='S1').reshape((H, W))
    return H, W, arr


def main():
    start = time.time()
    H, W, arr = get_data(sys.stdin)
    a = np.zeros((H + 1, W + 1), dtype='i8')
    a[:-1, :-1] = arr == b'.'
    end = time.time()
    print(end - start)

    calc(a, H, W)
    print(a.max())


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int H, W;

int main() {
    cin >> H >> W;
    vector<vector<int>> a(H + 1, vector<int>(W + 1));
    for(int i = 0; i < W + 1; i++){
        a.at(H).at(i) = 0;
    }
    for(int j = 0; j < H; j++){
        string str;
        cin >> str;
        a.at(j).at(W) = 0;
        for(int i = 0; i < W; i++){
            if(str.at(i) == '.')
                a.at(j).at(i) = 1;
            else
                a.at(j).at(i) = 0;
        }
    }

    //横方向
    for(int j = 0; j < H; j++){
        int prev = 0;
        int start = 0;
        for(int i = 0; i < W + 1; i++){
            if (a.at(j).at(i) > 0){
                if(prev == 0){
                    start = i;
                    prev = 1;
                }
            }else{
                if(prev == 1){
                    int num = i - start;
                    for(int k = start; k < i; k++){
                        a.at(j).at(k) = num;
                    }
                    prev = 0;
                }
            }
        }
    }

    //縦方向
    for(int i = 0; i < W; i++){
        int prev = 1;
        int start = 0;
        for(int j = 0; j < H + 1; j++){
            if (a.at(j).at(i) > 0){
                if(prev == 0){
                    start = j;
                    prev = 1;
                }
            }else{
                if(prev == 1){
                    int num = j - start;
                    for(int k = start; k < j; k++){
                        a.at(k).at(i) += num - 1;
                    }
                    prev = 0;
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j < H; j++){
        int m1 = *max_element(a.at(j).begin(), a.at(j).end());
        ans = max(ans, m1);
    }
    cout << ans << endl;
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int H, W;

int main() {
    cin >> H >> W;
    vector<vector<int>> a(H + 1, vector<int>(W + 1));
    vector<vector<int>> b(H + 1, vector<int>(W + 1, 0));
    for(int i = 0; i < W + 1; i++){
        a.at(H).at(i) = 1;
    }
    for(int j = 0; j < H; j++){
        string str;
        cin >> str;
        a.at(j).at(W) = 1;
        for(int i = 0; i < W; i++){
            if(str.at(i) == '.')
                a.at(j).at(i) = 0;
            else
                a.at(j).at(i) = 1;
        }
    }

    //横方向
    for(int j = 0; j < H; j++){
        int prev = 1;
        int start = 0;
        for(int i = 0; i < W + 1; i++){
            if (a.at(j).at(i) == 0){
                if(prev == 1){
                    start = i;
                    prev = 0;
                }
            }else{
                if(prev == 0){
                    int num = i - start;
                    for(int k = start; k < i; k++){
                        b.at(j).at(k) = num;
                    }
                    prev = 1;
                }
            }
        }
    }

    //縦方向
    for(int i = 0; i < W; i++){
        int prev = 1;
        int start = 0;
        for(int j = 0; j < H + 1; j++){
            if (a.at(j).at(i) == 0){
                if(prev == 1){
                    start = j;
                    prev = 0;
                }
            }else{
                if(prev == 0){
                    int num = j - start;
                    for(int k = start; k < j; k++){
                        b.at(k).at(i) += num - 1;
                    }
                    prev = 1;
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j < H; j++){
        int m1 = *max_element(b.at(j).begin(), b.at(j).end());
        ans = max(ans, m1);
    }
    cout << ans << endl;
}