Problem p02580 (python)

Fixed submission:
h,w,m=map(int,input().split())
a=[0]*h
b=[0]*w
hw=[]
for _ in range(m):
    hh,ww=map(int,input().split())
    hw+=((hh-1,ww-1)),
    a[hh-1]+=1
    b[ww-1]+=1
    
ma=max(a)
mb=max(b)

# x_ind=[i for i,j in enumerate(a) if j==ma]
# y_ind=[i for i,j in enumerate(b) if j==mb]



cnt=0
# sonzai suru

for i,j in hw:
    if a[i]==ma and b[j]==mb:cnt+=1

if cnt==a.count(ma)*b.count(mb):
    print(ma+mb-1)
else:
    print(ma+mb)

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

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

"""
for x in hp:
    for y in wp:
        if time.time()-t1>2.1:
            print(hm+wm)
            exit()
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)
"""

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

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        if time.time()-t1>2.1:
            print(hm+wm)
            exit()
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)

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

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)

Buggy submission (verdict: Runtime Error):
test=1
Copy
H,W,M = list(map(int,input().split()))
 
h = [0] * H
w = [0] * W
 
hw = []
 
for _ in range(H):
    hw.append([0] * W)

    
for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)
 
hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

Buggy submission (verdict: Runtime Error):
def LI():return list(map(int,input().split()))
h,w,m=LI()
S=[[0]*w for i in range(h)]
a=[0]*(h+50)
b=[0]*(w+50)
for i in range(m):
    h,w=LI()
    S[h-1][w-1]=1
    a[h-1]+=1
    b[w-1]+=1

mx=max(a)
my=max(b)
ind_x=[i for i,j in enumerate(a) if j==mx]
ind_y=[i for i,j in enumerate(b) if j==my]

ans=0
for x in ind_x:
    for y in ind_y:
        if S[x][y]==0:
            tmp=mx+my
            print(tmp)
            exit()
        else:
            tmp=mx+my-1

        ans=max(ans,tmp)
        
print(ans)

Buggy submission (verdict: Runtime Error):



def LI():
    return list(map(int,input().split()))
    
def OPEN():
    return map(int,open(0).read().split())

h,w,m=LI()
S=[[0]*w for i in range(h)]
a=[0]*h
b=[0]*w
for i in range(m):
    h,w=LI()
    
    S[h-1][w-1]+=1
    a[h-1]+=1
    b[w-1]+=1

# print(S)

    
now=0
ind_x=[]
ind_y=[]
# Ssumx=[sum(i) for i in S]
# SS=S.T
# Ssumy=[sum(i) for i in SS]



mx=max(a)
# max(Ssumx)
for i,j in enumerate(a):
    if j==mx:
        ind_x.append((i,j))
my=max(b)
# max(Ssumy)
for i,j in enumerate(b):
    if j==my:
        ind_y.append((i,j))
ans=0
for x,numx in ind_x:
    for y,numy in ind_y:
        if S[x][y]==0:
            tmp=numx+numy
        else:
            tmp=numx+numy-1

            
        ans=max(ans,tmp)
        
print(ans)