Problem p02580 (python)

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

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

X = [0] * W
Y = [0] * H
Map = []

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))

MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = set()
Yans = set()
for i, x in enumerate(X):
    if x == MX:
        Xans.add(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.add(i)
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int, input().split())

X = [0] * W
Y = [0] * H
Map = [[0] * W for _ in range(H)]

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map[h][w] = 1

MX = max(X)
MY = max(Y)
ans = MX + MY - 1
Xans = []
Yans = []
for i, x in enumerate(X):
    if x == MX:
        Xans.append(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.append(i)
flag = False
for x in Xans:
    if flag:
        break
    for y in Yans:
        if Map[y][x] == 0:
            ans += 1
            flag = True
            break
print(ans)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int ,input().split())

X = [0] * W
Y = [0] * H
Map = [[0] * W for _ in range(H)]

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map[h][w] = 1

MX = max(X)
MY = max(Y)
ans = MX + MY - 1
Xans = []
Yans = []
for i, x in enumerate(X):
    if x == MX:
        Xans.append(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.append(i)
for x in Xans:
    for y in Yans:
        if Map[y][x] == 0:
            ans += 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
B = []
Bom = [[0] * W for _ in range(H)]
BomC = [0] * W
BomR = [0] * H
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Bom[h][w] = 1
    BomC[w] += 1
    BomR[h] += 1
    B.append((h, w))
C = set()
R = set()
cm = max(BomC)
rm = max(BomR)

for w, c in enumerate(BomC):
    if c == cm:
        C.add(w)
for h, r in enumerate(BomR):
    if r == rm:
        R.add(h)
flag = True
for c in C:
    for r in R:
        if Bom[r][c]:
            continue
        else:
            flag = False
            break
if flag:
    print(cm + rm - 1)
else:
    print(cm + rm)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
Bom = [[0] * W for _ in range(H)]
BomC = [0] * W
BomR = [0] * H
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Bom[h][w] = 1
    BomC[w] += 1
    BomR[h] += 1

C = []
R = []
ans = 0

for w, c in enumerate(BomC):
    C.append((c, w))
for h, r in enumerate(BomR):
    R.append((r, h))
C.sort(reverse=True)
R.sort(reverse=True)
cm = max(BomC)
rm = max(BomR)

for r, h in R:
    if r < rm - 1:
        break
    for c, w in C:
        if c < cm - 1:
            break
        ans = max(ans, r + c - Bom[h][w])

print(ans)

Buggy submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
Bom = [[0] * W for _ in range(H)]
BomC = [0] * W
BomR = [0] * H
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Bom[h][w] = 1
    BomC[w] += 1
    BomR[h] += 1

C = []
R = []
ans = 0

for i, c in enumerate(BomC):
    C.append((c, i))
for i, c in enumerate(BomR):
    R.append((c, i))
C.sort(reverse=True)
R.sort(reverse=True)
cm = C[0][0]
rm = R[0][0]

for r, h in R:
    if r < rm -1:
        break
    for c, w in C:
        if c < cm - 1:
            break
        ans = max(ans, r + c - Bom[h][w])

print(ans)