Problem p02580 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    # 座標だけはsetで格納
    bomb_pos = set()
    # 爆弾情報を行と列ごとで格納
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(bomb_row) if v == bomb_row_max]
    col_index = [i for i, v in enumerate(bomb_col) if v == bomb_col_max]
    ans = bomb_col_max + bomb_row_max
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    # 座標だけはsetで格納
    bomb_pos = set()
    # 爆弾情報を行と列ごとで格納
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split())]
        bomb_col[r] += 1
        bomb_row[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(col) if v == bomb_col_max]
    col_index = [i for i, v in enumerate(row) if v == bomb_row_max]
    ans = max(col) + max(row)
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Buggy submission (verdict: Runtime Error):
def main():
    h, w, m = map(int, input().split())
    L = [list(map(int,input().split())) for _ in range(m)]
    table = [[0] * w for _ in range(h)]
    for a, b in L:
        table[a-1][b-1] = -1
    col = [0] * w
    row = [0] * h
    for i in range(w):
        col[i] = -sum([T[i] for T in table])
    for j in range(h):
        row[j] = -sum(table[j])
    for i in range(h):
      for j in range(w):
        table[i][j] += col[j] + row[i]
    print(max(max(T) for T in table))
main()

Buggy submission (verdict: Runtime Error):
def main():
    h, w, m = map(int, input().split())
    L = [list(map(int,input().split())) for _ in range(m)]
    table = [[0] * w for _ in range(h)]
    for a, b in L:
        table[a-1][b-1] = 1
    col = [0] * w
    row = [0] * h
    for i in range(w):
        col[i] = sum([T[i] for T in table])
    for j in range(h):
        row[j] = sum(table[j])
    mxCol = [i for i, v in enumerate(col) if v == max(col)]
    mxRow = [i for i, v in enumerate(row) if v == max(row)]
    ans = max(col) + max(row)
    for c in mxCol:
        for r in mxRow:
            if not table[r][c]:
                print(ans)
                return
    print(ans-1)
    
main()

Buggy submission (verdict: Runtime Error):
def main():
    h, w, m = map(int, input().split())
    L = [list(map(int,input().split())) for _ in range(m)]
    table = [[0] * w for _ in range(h)]
    for a, b in L:
        table[a-1][b-1] = 1
    col = [0] * w
    row = [0] * h
    for i in range(w):
        col[i] = sum([T[i] for T in table])
    for j in range(h):
        row[j] = sum(table[j])
    mxCol = [i for i, v in enumerate(col) if v == max(col)]
    mxRow = [i for i, v in enumerate(row) if v == max(row)]
    ans = max(col) + max(row)
    for c in mxCol:
        for r in mxRow:
            if not table[r][c]:
                print(ans)
                return
    print(ans-1)
    
main()