Problem:


Score : 500 points

Problem Statement

We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Constraints

All values in input are integers.

1 \leq H, W \leq 3 \times 10^5

1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)

1 \leq h_i \leq H

1 \leq w_i \leq W

\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

We can destroy all the targets by placing the bomb at \left(1, 2\right).

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4

Sample Output 3

6



Sample input:
2 3 3
2 2
1 1
1 3


Sample output:
3

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())

mp = []
hp = [0] * h
wp = [0] * w

for i in range(m):
    l = list(map(int, input().split()))
    mp.append(l)
    hp[l[0]-1] += 1
    wp[l[1]-1] += 1

maxhp = max(hp)
maxwp = max(hp)
hpdex = [i for i, x in enumerate(hp) if x == maxhp]
wpdex = [i for i, x in enumerate(wp) if x == maxwp]

for i in range(len(hpdex)):
    for j in range(len(wpdex)):
        if [hpdex[i] + 1, wpdex[j] + 1] not in mp:
            print(max(hp) + max(wp))
            exit()

print(maxhp + maxwp - 1)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
hsum = [0 for i in range(H)]
wsum = [0 for i in range(W)]
s = set()
for i in range(M):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    s.add((h, w))
    hsum[h] += 1
    wsum[w] += 1
if (hsum.index(max(hsum)), wsum.index(max(wsum))) in s:
    print(max(hsum) + max(wsum) - 1)
else:
    print(max(hsum) + max(wsum))

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w):
    if bm==b[i]:
        wmax[i]+=1
ans=(am+bm) #基本解
k=sum(hmax)*sum(wmax)
if k>m: #鳩ノ巣原理
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# import numpy as np

h, w, m = map(int, input().split())
hw_array = [list(map(int, input().split())) for _ in range(m)]

h_array = [0]*h
w_array = [0]*w

for hw in hw_array:
    h, w = hw
    h_array[h - 1] += 1
    w_array[w - 1] += 1

h_max = max(h_array)
h_argmax_array = [i for i in h_array if i == h_max]
w_max = max(w_array)
w_argmax_array = [j for j in w_array if j == w_max]

flag = False
for h_argmax in h_argmax_array:
    for w_argmax in w_argmax_array:
        if not [h_argmax + 1, w_argmax + 1] in hw_array:
            flag = True
            break

ans = h_max + w_max
if not flag:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
h = [0] * M
w = [0] * M

nh = [0] * H  # number of h == i+1
nw = [0] * W  # number of w == i+1
dic = {}

for i in range(M):
    h[i], w[i] = map(int, input().split())
    h[i] -= 1
    w[i] -= 1
    nh[h[i]] += 1
    nw[w[i]] += 1
    dic["{}-{}".format(h[i],w[i])] = True

mnh = max(nh)
mnw = max(nw)

mh = [i for i, nh1 in enumerate(nh) if nh1 == mnh]
mw = [i for i, nw1 in enumerate(nw) if nw1 == mnw]

for h1 in mh:
    for w1 in mw:
        if dic["{}-{}".format(h[i],w[i])] == False:
            print(mnh + mnw)
            exit()
print(mnh + mnw - 1)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    s = set()
    h,w,m = map(int,input().split())
    a = [0]*h
    b = [0]*w
    for i in range(m):
        x,y = map(int,input().split())
        x -= 1
        y -= 1
        a[x] += 1
        b[y] += 1
        s.add((x,y))
    amax = max(a)
    bmax = max(b)
    c = []
    d = []
    for x in a:
      if amax == x:
        c.append(x)
    for x in b:
      if bmax == x:
        d.append(x)
    minus = 1
    for x in c:
      for y in d:
        if not (x,y) in s:
          minus = 0
    print(amax+bmax-minus)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w):
    if bm==b[i]:
        wmax[i]+=1
ans=(am+bm) #基本解
if sum(hmax)*sum(wmax)>m: #鳩ノ巣原理
    print(ans)
    exit()
count=0
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        count+=1
if sum(hmax)*sum(wmax)<=count:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m= map(int,input().split(" "))
ys, xs=[0 for i in range(h)],[0 for j in range(w)]
ms=set()
for i in range(m):
    y,x= map(lambda x: int(x)-1,input().split(" "))
    ys[y]+=1
    xs[x]+=1
    ms.add((y,x))
y_max,x_max= max(ys),max(xs)
largest_ys, largest_xs=[],[]
for i in range(h):
    if ys[i]==y_max:
        largest_ys.append(i)
for i in range(w):
    if xs[i]==x_max:
        largest_xs.append(i)
ans=y_max+x_max-1
for i in largest_ys:
    for j in largest_xs:
        if (i,j) not in ms:
            ans=y_max+x_max
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


h, w, m = map(int, input().split())

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

ans = ch_max + cw_max
for (y, x) in points:
    index_y = bisect.bisect_left(ys, y)
    index_x = bisect.bisect_left(xs, x)
    if (index_y < len(ys) and ys[index_y] == y) and (index_x < len(xs) and xs[index_x] == x):
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

h, w, m = inpm()
rl = []
cl = []
for i in range(0, w):
    cl.append(0)
for i in range(0, h):
    rl.append(0)
maxr = 0
ri = []
maxc = 0
ci = []
l = []
for i in range(0, m):
    a , b = inpm()
    l.append([a- 1, b- 1])
    rl[a - 1] += 1
    cl[b - 1] += 1
    if(maxr < rl[a- 1]):
        maxr = rl[a- 1]
        ri.append(a- 1)
    if(maxc < cl[b- 1]):
        maxc = cl[b- 1]
        ci.append(b- 1)
ans = maxr + maxc
ri.sort(reverse=True)
ci.sort(reverse=True)
isSame = True
for r in ri:
    if(r < maxr):
         break
    for c in ci:
        if(c < maxc):
            if([r, c] in l == False):
                isSame = False
            break
if(isSame):
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w):
    if bm==b[i]:
        wmax[i]+=1
ans=(am+bm) #基本解
count=0
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        count+=1
if sum(hmax)*sum(wmax)==count:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m= map(int,input().split(" "))
ys, xs=[0 for i in range(h)],[0 for j in range(w)]
ms=set()
for i in range(m):
    y,x= map(lambda x: int(x)-1,input().split(" "))
    ys[y]+=1
    xs[x]+=1
    ms.add((y,x))
y_max,x_max= max(ys),max(xs)
largest_ys, largest_xs=[],[]
for i in range(h):
    if ys[i]==y_max:
        largest_ys.append(i)
for i in range(w):
    if xs[i]==x_max:
        largest_xs.append(i)
ans=y_max+x_max-1
for i in largest_ys:
    for j in largest_xs:
        if (i,j) not in ms:
            ans=y_max+x_max
            break
    break
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置
a=[0 for i in range(h+1)] #各行のbombの個数
b=[0 for _ in range(w+1)] #各列のbombの個数
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) #１行にあるbombの最大値
bm=max(b) #１列にあるbombの最大値
hmax=[0]*(h+1) #最大値をとるh全部
wmax=[0]*(w+1) #最大値をとるw全部
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w):
    if bm==b[i]:
        wmax[i]+=1
ans=(am+bm) #基本解
if sum(hmax)*sum(wmax)>m: #鳩ノ巣原理
    print(ans)
    exit()
count=0
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        count+=1
if sum(hmax)*sum(wmax)==count:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = []
for _ in range(m):
    h, w = map(int, input().split())
    inputs.append([h,m])
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)
 
inputs.sort()
max_h_l.sort()

flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if [i,j] not in inputs:
            ans = max_h + max_w
            flag = 1
        else:
            ans = max_h + max_w - 1
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
lsh = [0] * h
lsw = [0] * w

bom = []
for _ in range(m):
    m1, m2 = map(int, input().split())
    lsh[m1 - 1] += 1
    lsw[m2 - 1] += 1
    bom.append((m1-1, m2-1))

lshmax = max(lsh)
lswmax = max(lsw)
hin = [i for i in lsh if i == lshmax]
win = [i for i in lsw if i == lswmax]
#print(win)

jd = False

for i in hin:
    for j in win:
        if (i, j) not in bom:
            jd= True
                    #print(i,j)
if jd:
    print(lshmax+lswmax)
else:
    print(lshmax + lswmax -1)

Submission status: Wrong Answer

Solution code:
H,W,M = list(map(int,input().split()))
import numpy as np
targets = []
lines = [0]*(H+1)
rows = [0]*(W+1)
for i in range(M):
    l,r = list(map(int,input().split()))
    targets.append((l,r))
    lines[l] += 1
    rows[r] += 1
lmax = max(lines)
lmax_cand = []
rmax = max(rows)
rmax_cand = []
for i in range(H+1):
    if lines[i] == lmax:
        lmax_cand.append(i)
for i in range(W+1):
    if rows[i] == rmax:
        rmax_cand.append(i)
res = 0
import sys
for target in targets:
    if target[0] in lmax_cand and target[1] in rmax_cand:
        res = lmax + rmax - 1
    else:
        res = lmax + rmax
        print(res)
        sys.exit()
print(res)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])




H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

#H_only_most = [x for x in H_most if x[1]==H_most_num]
#H_kouho = [x[0] for x in H_only_most]

H_kouho = [x[0] for x in H_most if x[1]==H_most_num]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

#W_only_most = [x for x in W_most if x[1]==W_most_num]
#W_kouho = [x[0] for x in W_only_most]
W_kouho = [x[0] for x in W_most if x[1]==W_most_num]

ans = H_most_num + W_most_num

#マイナス1するかどうか
ans_minus = True

len_H_kouho=len(H_kouho)
len_W_kouho=len(W_kouho)
num_kouho = len_H_kouho*len_W_kouho

bakuha_1d = [W * (x[0]-1) + x[1] for x in bakuha]
bakuha_1d.sort()
bakuha_1d_max = bakuha_1d[-1]
bakuha_1d_min = bakuha_1d[0]

if num_kouho <= M:
    kouho_1d = []
    for h_k in H_kouho:
        for w_k in W_kouho:
            kouho_1d.append(W*(h_k-1)+w_k)
    kouho_1d.sort()
    kouho_1d_max = kouho_1d[-1]
    kouho_1d_min = kouho_1d[0]
    
    
#    if kouho_1d_max <= bakuha_1d_max and kouho_1d_min >= bakuha_1d_min:
#        for k1 in kouho_1d:
#            tuzuku = True
#            while tuzuku:
#                b1_0 = bakuha_1d.pop(0)
#                if b1_0 >= k1:
#                    tuzuku = False
#                    if b1_0 != k1:
#                        ans_minus = False
#    else:
#        ans_minus = False
    for i in range(M):
        b1_0 = bakuha_1d.pop(0)
        
        
        
else:
    ans_minus = False
#
#if ans_minus:
#    ans-=1
    

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

h, w, m = map(int, input().split())
lsh = [0] * h
lsw = [0] * w

bom = []
for _ in range(m):
    m1, m2 = map(int, input().split())
    lsh[m1 - 1] += 1
    lsw[m2 - 1] += 1
    bom.append((m1-1, m2-1))

lshmax = max(lsh)
lswmax = max(lsw)
hin = [i for i in lsh if i == lshmax]
win = [i for i in lsw if i == lswmax]
#print(win)

jd= False

for i in hin:
    for j in win:
        if (i, j) not in bom:
                    jd= True
                    #print(i,j)
if jd:
    print(lshmax+lswmax)
else:
    print(lshmax + lswmax -1)

Submission status: Wrong Answer

Solution code:
h,w,m= map(int,input().split(" "))
ys, xs=[0 for i in range(h)],[0 for i in range(w)]
ms=set([])
for i in range(m):
    y,x= map(int,input().split(" "))
    ys[y-1]+=1
    xs[x-1]+=1
    ms.add((y-1,x-1))
y_max,x_max= max(ys),max(xs)
largest_ys, largest_xs=[],[]
for i in range(h):
    if ys[i]==y_max:
        largest_ys.append(i)
for i in range(w):
    if xs[i]==x_max:
        largest_xs.append(i)
ans=y_max+x_max-1
for i in largest_ys:
    for j in largest_xs:
        if (i,j) not in ms:
            ans+=1
            break
    break
print(ans)

Submission status: Wrong Answer

Solution code:
def max_bomb_set(l):
    l.sort(key=lambda x: x[0], reverse=True)
    res = 0
    for cnt, tag in l:
        if cnt == l[0][0]:
            res += 1
        else:
            break
    return res, l[0][0]


def main():
    h, w, m = map(int, input().split())
    height = [[0, i] for i in range(h)]
    width = [[0, i] for i in range(w)]
    target = []
    for _ in range(m):
        x, y = map(lambda x: int(x) - 1, input().split())
        target.append([x, y])
        height[x][0] += 1
        width[y][0] += 1
    max_height, max_h_val = max_bomb_set(height)
    max_width, max_w_val = max_bomb_set(width)
    ans = max_h_val + max_w_val
    if max_height * max_width != m:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

h, w, m= map(int, input().split())
line=np.zeros(h, dtype='int8')
colm=np.zeros(w, dtype='int8')
locline=np.zeros(m,dtype='int8')
loccolm=np.zeros(m,dtype='int8')

for i in range(0,m):
  hi, wi = map(int, input().split())
  line[hi-1]=line[hi-1]+1 
  colm[wi-1]=colm[wi-1]+1 
  locline[i]=hi-1
  loccolm[i]=wi-1
    
#colm=np.sum(ans, axis=0)
#line=np.sum(ans, axis=1)

colmarg=np.argsort(-colm)
linearg=np.argsort(-line)

hhh=int(h/2)
www=int(w/2)
if (h < 100): hhh=h
if (w < 100): www=w

ataimax=0
for ih in linearg[0:5]:
  for iw in colmarg[0:5]:
    cho=0
    for i in range(0,m):
      if ((locline[i] == ih) and (loccolm[i] == iw)): cho=1
    atai=colm[iw]+line[ih]-cho
    if (atai >= ataimax): ataimax=atai

print (ataimax)

Submission status: Wrong Answer

Solution code:
H, W, M = [int(x) for x in input().split()]

row = [0] * (H + 1)
column = [0] * (W + 1)
h_most = 0
w_most = 0
e = 0
bomb = []

for i in range(M):
    h, w = [int(x) for x in input().split()]
    bomb.append([h, w])
    row[h] += 1
    column[w] += 1
    if row[h] > row[h_most]:
        h_most = h
    if column[w] > column[w_most]:
        w_most = w
    if [h_most, w_most] in bomb:
        e = -1
    else:
        e = 0

ans = row[h_most] + column[w_most] + e

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

h = []
w = []
for _ in range(M):
    x, y = map(int, input().split())
    h.append(x)
    w.append(y)

ch = Counter(h)
cw = Counter(w)

h_max = max(ch.values())
w_max = max(cw.values())

h_idx = [x for (x, y) in ch.items() if y == h_max]
w_idx = [x for (x, y) in cw.items() if y == w_max]

boms = set([(x, y) for x, y in zip(h, w)])

minus = [0]
for x in h_idx:
    for y in w_idx:
        if (x, y) in boms:
            minus.append(-1)

print(h_max + w_max + min(minus))

Submission status: Wrong Answer

Solution code:
import collections

H,W,M = map(int, input().split())
h = [0]*M
w = [0]*M
for i in range(M):
    h[i], w[i] = map(int, input().split())
ch = collections.Counter(h).most_common()
mh = []
mnh = ch[0][1]
for ch1 in ch:
    if mnh == ch1[1]:
        mh.append(ch1[0])
        continue
    else:
        break
    break
cw = collections.Counter(w).most_common()
mw = []
mnw = cw[0][1]
for cw1 in cw:
    if mnw == cw1[1]:
        mw.append(cw1[0])
        continue
    else:
        break
    break
hw = zip(h,w)
for h1 in mh:
    for w1 in mw:
        if (h1,w1) not in hw:
            print(mnh+mnw)
            exit()
print(mnh+mnw-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
  h, w, m = map(int, input().split())
  #graph = np.zeros((h, w), dtype='int64')
  row_sum = np.zeros(h, dtype='int64')
  col_sum = np.zeros(w, dtype='int64')
  pos = []

  for _ in range(m):
    i, j = map(int, input().split())
    #graph[i-1][j-1] = 1
    row_sum[i-1] += 1
    col_sum[j-1] += 1
    pos.append((i-1, j-1))

  #print(row_sum)
  #print(col_sum)

  max_row = max(row_sum)
  max_col = max(col_sum)

  result = max_row+max_col

  ris = np.where(row_sum == max_row)
  cis = np.where(col_sum == max_col)
  
  #print(ris)
  #print(cis)
  #print(pos)

  for ri, ci in pos:
    if ri not in ris[0] and ci not in cis[0]:
      return result
  return result-1
  
print(main())

Submission status: Wrong Answer

Solution code:
from collections import Counter

H, W, M, *hw = map(int, open(0).read().split())
hw = [(h, w) for h, w in zip(*[iter(hw)] * 2)]
H_cnt = Counter()
W_cnt = Counter()
for h, w in hw:
    H_cnt += {h: 1}
    W_cnt += {w: 1}
H_max_idx, H_max_cnt = H_cnt.most_common(1)[0]
W_max_idx, W_max_cnt = W_cnt.most_common(1)[0]
ans = H_max_cnt + W_max_cnt
print(ans - 1) if (H_max_idx, W_max_idx) in hw else print(ans)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])




H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

#H_only_most = [x for x in H_most if x[1]==H_most_num]
#H_kouho = [x[0] for x in H_only_most]

H_kouho = [x[0] for x in H_most if x[1]==H_most_num]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

#W_only_most = [x for x in W_most if x[1]==W_most_num]
#W_kouho = [x[0] for x in W_only_most]
W_kouho = [x[0] for x in W_most if x[1]==W_most_num]

ans = H_most_num + W_most_num

#マイナス1するかどうか
ans_minus = True

len_H_kouho=len(H_kouho)
len_W_kouho=len(W_kouho)
num_kouho = len_H_kouho*len_W_kouho

bakuha_1d = [W * (x[0]-1) + x[1] for x in bakuha]
bakuha_1d.sort()
bakuha_1d_max = bakuha_1d[-1]

if num_kouho <= M:
    kouho_1d = []
    for h_k in H_kouho:
        for w_k in W_kouho:
            kouho_1d.append(W*(h_k-1)+w_k)
    kouho_1d.sort()
    kouho_1d_max = kouho_1d[-1]
    
#    if kouho_1d_max <= bakuha_1d_max:
#        for k1 in kouho_1d:
#            tuzuku = True
#            while tuzuku:
#                b1_0 = bakuha_1d.pop(0)
#                if b1_0 >= k1:
#                    tuzuku = False
#                    if b1_0 != k1:
#                        ans_minus = False
#    else:
#        ans_minus = False
else:
    ans_minus = False
#
#if ans_minus:
#    ans-=1
    

print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)
from collections import Counter as co
xs,ys=co(xs),co(ys)
xim,yim=xs.most_common(1)[0][1], ys.most_common(1)[0][1]
f=1
for a,b in setobj:
  if xs[a]==xim and ys[b]==yim:continue
  f=0
  break
print(xim+yim-f)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
Hm,Wm = [0]*H,[0]*W
B = []
for _ in range(M):
  h,w= map(lambda x: int(x)-1,input().split())
  Hm[h]+=1
  Wm[w]+=1
  B.append((h,w))
Hmax,Wmax = max(Hm),max(Wm)
max_hs = set([v for v in Hm if v == Hmax])
max_ws = set([v for v in Wm if v == Wmax])

b = 0
for h,w in B:
  if h in max_hs and w in max_ws: b+=1
if b == len(max_hs)*len(max_ws): print(Hmax+Wmax-1)
else: print(Hmax+Wmax)

Submission status: Wrong Answer

Solution code:
H, W, m = map(int, input().split())
N = 10**6
hs = [0] * H
ws = [0] * W
from collections import defaultdict
fs = defaultdict(bool)
for i in range(m):
    hi,wi  = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[(hi-1)*N+wi-1] = True
mx = 0
Hs = [(h,i) for i,h in enumerate(hs)]
Ws = [(w,i) for i,w in enumerate(ws)]
Hs.sort(reverse=True)
Ws.sort(reverse=True)
cnt = 0
hmx = Hs[0][0]
wmx = Ws[0][0]
# for r in fs:
#     print(*r)
mx = 0
for nh, ih in Hs:
    for nw, iw in Ws:
        if nh < hmx and nw < wmx: continue
        mx = max(mx, nh+nw-fs[ih*N+iw])
        cnt += 1
        if cnt >= m:
            print(mx)
            exit()
print(mx)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])




H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

#H_only_most = [x for x in H_most if x[1]==H_most_num]
#H_kouho = [x[0] for x in H_only_most]

H_kouho = [x[0] for x in H_most if x[1]==H_most_num]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

#W_only_most = [x for x in W_most if x[1]==W_most_num]
#W_kouho = [x[0] for x in W_only_most]
W_kouho = [x[0] for x in W_most if x[1]==W_most_num]

ans = H_most_num + W_most_num

#マイナス1するかどうか
ans_minus = True

len_H_kouho=len(H_kouho)
len_W_kouho=len(W_kouho)
num_kouho = len_H_kouho*len_W_kouho

bakuha_1d = [W * (x[0]-1) + x[1] for x in bakuha]
bakuha_1d.sort()
bakuha_1d_max = bakuha_1d[-1]

#if num_kouho <= M:
#    kouho_1d = []
#    for h_k in H_kouho:
#        for w_k in W_kouho:
#            kouho_1d.append(W*(h_k-1)+w_k)
#    kouho_1d.sort()
#    kouho_1d_max = kouho_1d[-1]
#    
#    if kouho_1d_max <= bakuha_1d_max:
#        for k1 in kouho_1d:
#            tuzuku = True
#            while tuzuku:
#                b1_0 = bakuha_1d.pop(0)
#                if b1_0 >= k1:
#                    tuzuku = False
#                    if b1_0 != k1:
#                        ans_minus = False
#    else:
#        ans_minus = False
#else:
#    ans_minus = False
#
#if ans_minus:
#    ans-=1
    

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

h, w, m = inpm()
rl = []
cl = []
for i in range(0, w):
    cl.append(0)
for i in range(0, h):
    rl.append(0)
maxr = 0
ri = 0
maxc = 0
ci = 0
l = []
for i in range(0, m):
    a , b = inpm()
    l.append([a- 1, b- 1])
    rl[a - 1] += 1
    cl[b - 1] += 1
    if(maxr < rl[a- 1]):
        maxr = rl[a- 1]
        ri = a- 1
    if(maxc < cl[b- 1]):
        maxc = cl[b- 1]
        ci = b- 1
ans = maxr + maxc
if([ri, ci] in l):
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
  h, w, m = map(int, input().split())
  #graph = np.zeros((h, w), dtype='int64')
  row_sum = np.zeros(h, dtype='int64')
  col_sum = np.zeros(w, dtype='int64')
  pos = []

  for _ in range(m):
    i, j = map(int, input().split())
    #graph[i-1][j-1] = 1
    row_sum[i-1] += 1
    col_sum[j-1] += 1
    pos.append((i, j))

  #print(row_sum)
  #print(col_sum)

  max_row = max(row_sum)
  max_col = max(col_sum)

  result = max_row+max_col

  ris = np.where(row_sum == max_row)
  cis = np.where(col_sum == max_col)
  
  #print(ris)
  #print(cis)

  for ri in ris[0]:
    for ci in cis[0]:
      #if graph[ri][ci] == 0:
      if (ri, ci) not in pos:
        return result
  return result-1
  
print(main())

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
bomb_list = []
 
bomb_list = [list(map(int, input().split())) for i in range(m)]
 
for o in range(m):
    for p in range(2):
        bomb_list[o][p] -= 1
 
h_count_list = [0 for j in range(h)]
w_count_list = [0 for k in range(w)]
 
max_h_count = 0
max_w_count = 0
 
x_list = []
y_list = []
 
for l in range(m):
    a = bomb_list[l][0]
    h_count_list[a] += 1
 
max_h_count = max(h_count_list)
 
for c in range(h):
    if h_count_list[c] == max_h_count:
        x_list.append(c)
    
for n in range(m):
    b = bomb_list[n][1]
    w_count_list[b] += 1
 
max_w_count = max(w_count_list)
 
for d in range(w):
    if w_count_list[d] == max_w_count:
        y_list.append(d)
 
e = 0
 
for x in x_list:
    for y in y_list:
        if e < max_w_count + max_h_count - 1:
            if [x, y] in bomb_list:
                e = max_w_count + max_h_count - 1
            else:
                e = max_w_count + max_h_count 
 
print(e)

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis,mx):
  ret=[]
  for (i,j) in zip(range(len(lis)),lis):
    if j==mx:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append({-1})
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].add(ww)
  hb[hh]+=1
  wb[ww]+=1
mhb=max(hb)
mwb=max(wb)
hmx=putmx(hb,mhb)
wmx=set(putmx(wb,mwb))

#print(hb,wb,hmx,wmx)
fl=False
for i in hmx:
  if len(wmx|bmb[i])>len(wmx)+len(bmb[i]):
    print(mhb+mwb)
    break
else:
  print(mhb+mwb-1)

#print(hmx,wmx,bmb)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
flag = 0

for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[(tmp_h-1, tmp_w-1)] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) not in m.keys():
            flag = 1
            break

if flag == 1:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
A = [0]*H
B = [0]*W
D = set()
for _ in range(M):
    h,w = map(int, input().split())
    A[h-1] += 1
    B[w-1] += 1
    D.add((h-1,w-1))
a, b = max(A), max(B)
res = a+b-1
E, F = [], []
for i in range(H):
    if A[i] == a:
        E.append(i)
for j in range(W):
    if B[j] == b:
        F.append(j)
for i, j in zip(E,F):
    if (i,j) not in D:
        print(res+1)
        exit()
print(res)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)
from collections import Counter as co
xs,ys=co(xs),co(ys)
xim,yim=xs.most_common(1)[0][1], ys.most_common(1)[0][1]
for a,b in setobj:
  if xs[a]==xim and ys[b]==yim:continue
  xim-=1;break
print(xim+yim)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
Hm,Wm = [0]*H,[0]*W
B = []
for _ in range(M):
  h,w= map(lambda x: int(x)-1,input().split())
  Hm[h]+=1
  Wm[w]+=1
  B.append((h,w))
Hmax,Wmax = max(Hm),max(Wm)
max_hs = set([v for v in Hm if v == Hmax])
max_ws = set([v for v in Wm if v == Wmax])
for h,w in B:
  if h in max_hs and w in max_ws: continue
  else:
    print(Hmax+Wmax)
    exit()
print(Hmax+Wmax-1)