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:
import sys

H, W, M = map(int, sys.stdin.readline().strip().split())

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

g = [[False] * W for _ in range(H)]
S = set()
for _ in range(M):
    Th, Tw = map(int, sys.stdin.readline().strip().split())

    h[Th - 1] += 1
    w[Tw - 1] += 1

    # g[Th - 1][Tw - 1] = True
    S.add((Th - 1, Tw - 1))

ans = max(h) + max(w)

index_h = [n for n, v in enumerate(h) if v == max(h)]
index_w = [n for n, v in enumerate(w) if v == max(w)]

sub = 1
# for ih in index_h:
#     for iv in index_w:
#         if g[ih][iv] is False:
#             sub = 0
#             break
#     else:
#         continue
#     break
# ans -= sub
# print(ans)


for ih in index_h:
    for iv in index_w:
        if (ih, iv) in S:
            print(ans)
            exit()
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append([h-1, w-1])
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    # for i in maxindex:
    #     for j in maxwindex:
    #         if [i, j] not in bombs:
    #             print(ans)
    #             exit()

    # print(ans-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H, W, m = map(int, input().split())

H_bomb = [0]*H
W_bomb = [0]*W
S = set()

for _ in range(m):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    S.add(tuple([h, w]))
    H_bomb[h] += 1
    W_bomb[w] += 1

H_max = max(H_bomb)
W_max = max(W_bomb)

H_memo = set()
W_memo = set()

for i in range(H):
    if H_bomb[i] == H_max:
        H_memo.add(i)

for j in range(W):
    if W_bomb[j] == W_max:
        W_memo.add(j)

ans = H_max + W_max

# for i in H_memo:
#     for j in W_memo:
#         if tuple([i, j]) not in S:
#             print(ans)
#             exit()

for s in S:
    if s[0] in H_memo and s[1] in W_memo:
        continue
    else:
        print(ans)
        exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
H, W, m = map(int, input().split())

H_bomb = [0]*H
W_bomb = [0]*W
S = set()

for _ in range(m):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    S.add(tuple([h, w]))
    H_bomb[h] += 1
    W_bomb[w] += 1

H_max = max(H_bomb)
W_max = max(W_bomb)

H_memo = []
W_memo = []

for i in range(H):
    if H_bomb[i] == H_max:
        H_memo.append(i)

for j in range(W):
    if W_bomb[j] == W_max:
        W_memo.append(j)

ans = H_max + W_max

# for i in H_memo:
#     for j in W_memo:
#         if tuple([i, j]) not in S:
#             print(ans)
#             exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W, M = map(int, input().split())
HW = []
print(1)
exit()
A = np.zeros((H, W), dtype='int')

for _ in range(M):
    h, w = map(int, input().split())
    h, w = h - 1, w - 1  # 0-indexed
    HW.append((h, w))
    A[h, w] = 1

arr = A.sum(axis=0)
col_max = arr.max()
col_idx = np.where(arr == col_max)[0]

arr = A.sum(axis=1)
row_max = arr.max()
row_idx = np.where(arr == row_max)[0]

# print(A.sum(axis=0).argsort()[-1])

ans = col_max + row_max
for r in row_idx:
    for c in col_idx:
        if A[r, c] == 0:
            print(ans)
            exit()
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H+1)
    ws = [0]*(W+1)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append([h, w])
        hs[h] += 1
        ws[w] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    isfound = False

    for i in range(H):
        if isfound == True:
            break
        if hs[i] == maxh:
            for j in range(W):
                if ws[j] == maxw:
                    if [i+1, j+1] not in bombs:
                        isfound = True
                        break
    if isfound == False:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    H, W, M = list(map(int, input().split()))
    h = []
    w = []

    bombs = []
    for i in range(M):
        hi, wi = list(map(int, input().split()))
        h.append(hi)
        w.append(wi)
        bombs.append(tuple([hi,wi]))
    count_h = []
    count_w = []
    for i in range(H):
        count_h.append(sum(x==i for x in h))
    for i in range(W):
        count_w.append(sum(x==i for x in w))

    max_h = max(count_h)
    indexes_h = [i for i, v in enumerate(count_h) if v == max(count_h)]

    max_w = max(count_w)
    indexes_w = [i for i, v in enumerate(count_w) if v == max(count_w)]

    ans = max_h + max_w
    if len(indexes_h) * len(indexes_w) > M:
        print(ans)
        exit()

    bombs = set(bombs)
    for i in indexes_h:
        for j in indexes_w:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print(ans-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H+1)
    ws = [0]*(W+1)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append([h, w])
        hs[h] += 1
        ws[w] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    isfound = False

    for h in hs:
        if isfound == True:
            break
        if h == maxh:
            for w in ws:
                if w == maxw:
                    if [h, w] not in bombs:
                        isfound = True
                        break
    if isfound == False:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    H, W, M = list(map(int, input().split()))
    h = []
    w = []

    bombs = []
    for i in range(M):
        hi, wi = list(map(int, input().split()))
        h.append(hi)
        w.append(wi)
        bombs.append(tuple([hi,wi]))
    count_h = []
    count_w = []
    for i in range(M):
        count_h.append(sum(x==i for x in h))
        count_w.append(sum(x==i for x in w))

    max_h = max(count_h)
    indexes_h = [i for i, v in enumerate(count_h) if v == max(count_h)]

    max_w = max(count_w)
    indexes_w = [i for i, v in enumerate(count_w) if v == max(count_w)]

    ans = max_h + max_w
    if len(indexes_h) * len(indexes_w) > M:
        print(ans)
        exit()

    bombs = set(bombs)
    for i in indexes_h:
        for j in indexes_w:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print(ans-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    H, W, M = list(map(int, input().split()))
    h = []
    w = []

    bombs = []
    for i in range(M):
        hi, wi = list(map(int, input().split()))
        h.append(hi)
        w.append(wi)
        bombs.append(tuple([hi,wi]))

    count_h = []
    count_w = []
    for i in range(M):
        count_h.append(sum(x==i for x in h))
        count_w.append(sum(x==i for x in w))

    max_h = max(count_h)
    indexes_h = [i for i, v in enumerate(count_h) if v == max(count_h)]

    max_w = max(count_w)
    indexes_w = [i for i, v in enumerate(count_w) if v == max(count_w)]

    ans = max_h + max_w

    bombs = set(bombs)
    for i in indexes_h:
        for j in indexes_w:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print(ans-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

cnt_x = [0] * h
cnt_y = [0] * w

for i in bomb:
    cnt_x[i[0]-1] += 1
    cnt_y[i[1]-1] += 1

ans_index_x = np.argmax(cnt_x)
ans_index_y = np.argmax(cnt_y)

if [ans_index_x+1, ans_index_y+1] in bomb:
    print(cnt_x[ans_index_x] + cnt_y[ans_index_y] - 1)
else:
    print(cnt_x[ans_index_x] + cnt_y[ans_index_y])

Submission status: Wrong Answer

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

width = [0] * W
height = [0] * H

obj = set()
for i in range(M):
    h, w = [int(x) - 1 for x in input().split()]

    width[w] += 1
    height[h] += 1
    obj.add((h, w))

for h, w in obj:
    if height[h] == max(height):
        if width[w] == max(height):
            print(max(height) + max(width) - 1)
            exit()

print(max(height) + max(width))

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split())
#h = np.empty(M,dtype=np.int)
#w = np.empty(M,dtype=np.int)
bomb = np.zeros((M,2),dtype=np.int32)
hh = np.zeros(H+1,dtype=np.int32)
ww = np.zeros(W+1,dtype=np.int32)

for i in range(M):
    h,w = map(int,input().split())
    bomb[i, :] = [h,w]
    hh[h] += 1
    ww[w] += 1

#print(bomb)
h_max_id = np.argmax(hh)
w_max_id = np.argmax(ww)
#print("hmax:{} wmax:{}".format(h_max_id, w_max_id))
b = 0

for i in range(M):
  if bomb[i][0] == h_max_id and bomb[i][1] == w_max_id:
    #print("bomb[{}] = {}".format(i, bomb[i]))
    b = 1
    
#print("hmax:{} wmax:{}".format(hh[h_max_id], ww[w_max_id]))
print(hh[h_max_id] + ww[w_max_id] - b)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
HH=[]
WW=[]
HW=set()
lh=[0]*(h+1)
lw=[0]*(w+1)
for _ in range(m):
    h1,w1=map(int,input().split())
    lh[h1]+=1
    lw[w1]+=1
    HW.add((h1,w1))
lhmax=max(lh)
lwmax=max(lw)
maxh=[]
maxw=[]
for i in range(1,h+1):
    if lh[i]==lhmax:
        maxh.append(i)
for i in range(1,w+1):
    if lw[i]==lwmax:
        maxw.append(i)

if len(maxh)*len(maxw)>w:
    print(lhmax+lwmax)
else:
    flag=True
    for i in maxh:
        for j in maxw:
            if (i,j) not in HW:
                flag=False
                break
    if flag==True:
        print(lhmax+lwmax-1)
    else:
        print(lhmax+lwmax)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
HW = []
for i in range(M):
	HW.append(list(map(int,input().split())))

#H方向の走査
Hmax = 0
Hmax_temp = 0
y_max = []
for y in range(1,H+1):
	for j in HW:
		if y == j[0]:
			Hmax_temp += 1
	if Hmax_temp >= Hmax:
		Hmax = Hmax_temp
		y_max.append(y)
	Hmax_temp = 0

#W方向の走査
Wmax = 0
Wmax_temp = 0
x_max = []
for x in range(1,W+1):
	for j in HW:
		if x == j[1]:
			Wmax_temp += 1
	if Wmax_temp >= Wmax:
		Wmax = Wmax_temp
		x_max.append(x)
	Wmax_temp = 0

#爆弾設置位置に対象が存在するか？
flag = False
for i in y_max:
	for  j in x_max:
		if [i,j] not in HW:
			flag = True
			break
	if flag:
		break

#答えのセット
if flag:
	ans = Wmax + Hmax
else:
	ans = Wmax + Hmax - 1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
hs = [0]*H
ws = [0]*W
s = [[0 for i in range(W)] for j in range(H)]
for i in range(M):
    h,w = map(int,input().split())
    hs[h-1] += 1
    ws[w-1] += 1
    s[h-1][w-1] = 1

mh = 0; mw = 0
for i in range(H):
    mh = max(mh,hs[i])
for i in range(W):
    mw = max(mw,ws[i])

Is = []; Js = []
for i in range(H):
    if mh ==  hs[i]:
        Is.append(i)
for i in range(W):
    if mw == ws[i]:
        Js.append(i)
ans = mh + mw

for i in range(H):
    for j in range(W):
        if s[i][j] == 1:
            continue
        print(ans)
        exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
hs = [0]*H
ws = [0]*W
s = set()
for i in range(M):
    h,w = map(int,input().split())
    hs[h-1] += 1
    ws[w-1] += 1
    s.add((h-1,w-1))

mh = 0; mw = 0
for i in range(H):
    mh = max(mh,hs[i])
for i in range(W):
    mw = max(mw,ws[i])

Is = []; Js = []
for i in range(H):
    if mh ==  hs[i]:
        Is.append(i)
for i in range(W):
    if mw == ws[i]:
        Js.append(i)
ans = mh + mw
flag = 0
for i in Is:
    for j in Js:
        if (i,j) in s:
            continue
        print(ans)
        flag = 1
if flag == 0:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
targets = [list(map(int, input().split())) for _ in range(M)]
x_counter = [0 for _ in range(W + 1)]
y_counter = [0 for _ in range(H + 1)]
y_index = []
x_index = []
dup = True

for target in targets:
    y_counter[target[0]] += 1
    x_counter[target[1]] += 1

y_max, x_max = max(y_counter), max(x_counter)

for i in range(H + 1):
    if y_counter[i] == y_max:
        y_index.append(i)

for j in range(W + 1):
    if x_counter[j] == x_max:
        x_index.append(j)

for k in y_index:
    for l in x_index:
        if [k, l] not in targets:
            dup == False

if dup:
    print(y_max + x_max - 1)
else:
    print(y_max + x_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    h,w,m=map(int,input().split())
    hw=[tuple(map(int,input().split())) for _ in range(m)]
    hs=Counter([i[0] for i in hw])
    ws=Counter([i[1] for i in hw])
    hh = hs.most_common()[0]
    ww = ws.most_common()[0]
    if (hh[0],ww[0]) in hw:
        print(hh[1]+ww[1]-1)
    else:
        print(hh[1]+ww[1])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
h,w,m = ( int(x) for x in input().split() )

h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
    hi,wi = ( int(x)-1 for x in input().split() )
    h_array[hi] += 1
    w_array[wi] += 1
    ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
    if hi == h_great:
        h_greats.append(i)
for i , wi in enumerate(w_array):
    if wi == w_great:
        w_greats.append(i)

ans = h_great + w_great - 1


for _h in h_greats:
    for _w in w_greats:
        if (_h,_w) in ps:
            continue
        print(ans)
        exit()

print(ans)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
tate = [0 for _ in range(H)]
yoko = [0 for _ in range(W)]
for i in range(M):
    a, b = map(int, input().split())
    tate[a-1] += 1
    yoko[b-1] += 1
print(max(tate) + max(yoko) - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split())
#h = np.empty(M,dtype=np.int)
#w = np.empty(M,dtype=np.int)
bomb = np.zeros((M,2),dtype=np.int32)
hh = np.zeros(H+1,dtype=np.int32)
ww = np.zeros(W+1,dtype=np.int32)

for i in range(M):
    h,w = map(int,input().split())
    bomb[i, :] = [h,w]
    hh[h] += 1
    ww[w] += 1

#print(bomb)
h_max_id = np.argmax(hh)
w_max_id = np.argmax(ww)

b = 0
for i in range(M):
    bomb[i] == [h_max_id, w_max_id]
    b = 1

print(hh[h_max_id] + ww[w_max_id] - b)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
bombs = set()
field = [[False] * W for _ in range(H)]

max_hw = max(H, W)
H_count = {i:0 for i in range(max_hw)}
W_count = H_count.copy()

for i in range(M):
    h, w = map(lambda x:int(x) - 1, input().split())
    bombs.add((h, w))
    field[h][w] = True
    H_count[h] += 1
    W_count[w] += 1


A = max(H_count.values())
B = max(W_count.values())
Ah = []
Bw = []

for i in range(max_hw):
    if H_count[i] == A:
        Ah.append(i)
    if W_count[i] == B:
        Bw.append(i)

ans = A + B - 1
for h in Ah:
    for w in Bw:
        if (h, w) not in bombs:
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    import sys
    input = sys.stdin.readline
    H,W,m=map(int,input().split())
    bomb=[]
    cnt1=[[0,i] for i in range(H)]
    cnt2=[[0,i] for i in range(W)]
    for i in range(m):
        h,w=map(int,input().split())
        bomb.append((h-1,w-1))
        cnt1[h-1][0]+=1
        cnt2[w-1][0]+=1
    cnt1.sort(reverse=True)
    cnt2.sort(reverse=True)
    m1=cnt1[0][0]
    l1=[]
    i=0
    while cnt1[i][0]==m1:
        l1.append(cnt1[i][1])
        i+=1
        if i>=H-1:
            break
    m2=cnt2[0][0]    
    l2=[]
    i=0
    while cnt2[i][0]==m2:
        l2.append(cnt2[i][1])
        i+=1
        if i>=W-1:
            break
    ans=m1+m2-1
    k=0
    for h,w in bomb:
        if (h in l1) and (w in l2):
            k+=1
    if len(l1)*len(l2)>k:
        ans+=1
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
H,W,m=map(int,input().split())
bomb=[]
cnt1=[[0,i] for i in range(H)]
cnt2=[[0,i] for i in range(W)]
for i in range(m):
    h,w=map(int,input().split())
    bomb.append((h-1,w-1))
    cnt1[h-1][0]+=1
    cnt2[w-1][0]+=1
cnt1.sort(reverse=True)
cnt2.sort(reverse=True)
m1=cnt1[0][0]
l1=[]
i=0
while cnt1[i][0]==m1:
    l1.append(cnt1[i][1])
    i+=1
    if i>=H-1:
        break
m2=cnt2[0][0]    
l2=[]
i=0
while cnt2[i][0]==m2:
    l2.append(cnt2[i][1])
    i+=1
    if i>=W-1:
        break
ans=m1+m2-1
k=0
for h,w in bomb:
    if (h in l1) and (w in l2):
        k+=1
if len(l1)*len(l2)>k:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int, input().split())
s = []
hcount = [0]*H
wcount = [0]*W
for m in range(M):
  h,w = map(int, input().split())
  h = h - 1
  w = w - 1
  hcount[h] = hcount[h] + 1
  wcount[w] = wcount[w] + 1
  s.append([h,w])
hmax = max(hcount)
wmax = max(wcount)
hmode = []
wmode = []
for h in range(H):
  if hcount[h] == hmax:
    hmode.append(h)
for w in range(W):
  if wcount[w] == wmax:
    wmode.append(w)
ans = hmax + wmax - 1
for h in hmode:
  for w in wmode:
    if ([h,w] in s):
      continue
    ans = ans + 1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import bisect
from operator import itemgetter

h,w,m = readints()

r = [0]*h
c = [0]*w

p = [readints() for i in range(m)]
p.sort(key=itemgetter(1))

d = [[] for i in range(h)]
for i in range(m):
    a,b = (x-1 for x in p[i])
    r[a] += 1
    c[b] += 1
    d[a].append(b)

mr = max(r)
mc = max(c)
R = [i for i,x in enumerate(r) if x==mr]
C = [i for i,x in enumerate(c) if x==mc]

flag = 1
if len(R)*len(C)>m:
    flag = 0
else:
    for x in R:
        for y in C:
            z = bisect.bisect_left(d[x],y)
            if z>=len(d[x]):
                continue
            else:
                if y != d[x][z]:
                    flag = 0
                    break

print(max(r)+max(c)-flag)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import bisect
from operator import itemgetter

h,w,m = readints()

r = [0]*h
c = [0]*w

p = [readints() for i in range(m)]
p.sort(key=itemgetter(1))

d = [[] for i in range(h)]
for i in range(m):
    a,b = (x-1 for x in p[i])
    r[a] += 1
    c[b] += 1
    d[a].append(b)

R = [i for i,x in enumerate(r) if x==max(r)]
C = [i for i,x in enumerate(c) if x==max(c)]

flag = 1
if len(R)*len(C)>m:
    flag = 0
else:
    for x in R:
        for y in C:
            z = bisect.bisect_left(d[x],y)
            if z>=len(d[x]):
                continue
            else:
                if y != d[x][z]:
                    flag = 0
                    break

print(max(r)+max(c)-flag)

Submission status: Wrong Answer

Solution code:
import numpy as np
import statistics
H,W,M = map(int, input().split())
s = []
hcount = [0]*H
wcount = [0]*W
for m in range(M):
  h,w = map(int, input().split())
  h = h - 1
  w = w - 1
  hcount[h] = hcount[h] + 1
  wcount[w] = wcount[w] + 1
  s.append([h,w])
hmax = max(hcount)
wmax = max(wcount)
hmode = []
wmode = []
for h in range(H):
  if hcount[h] == hmax:
    hmode.append(h)
for w in range(W):
  if wcount[w] == wmax:
    wmode.append(w)
ans = hmax + wmax - 1
for h in hmode:
  for w in wmode:
    if ([h,w] in s):
      continue
    ans = ans + 1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

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

def index_Multi(List, liter):
    # Listはリスト本体・literは検索したい文字
    index_L = []
    for val in range(0, len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L


def serch(count, H, W):
    h = []
    w = []
    num = []
    for i in range(count):
        h_n, w_n = map(int, input().split())
        h.append(h_n)
        w.append(w_n)
    for j in range(H):
        line_count = h.count(j + 1)
        h_index = index_Multi(h, j)
        for k in range(W):
            row_count = w.count(k + 1)
            w_index = index_Multi(w, k)
            sum_ans = line_count + row_count
            if h_index == w_index:
                sum_ans -= 1
            num.append(sum_ans)
    print(max(num))


serch(count, H, W)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
t=[[0,i] for i in range(w)]
y=[[0,i] for i in range(h)]
hw=[[False]* w for i in range(h)]
for i in range(m):
    h1,w1=map(int,input().split())
    h1,w1=h1-1,w1-1
    y[h1][0]+=1
    t[w1][0]+=1
    hw[h1][w1]=True
ans=0
t.sort(reverse=True)
y.sort(reverse=True)
for i in range(min(w,5)):
    for j in range(min(h,5)):
        tmp=t[i][0]+y[j][0]
        if hw[y[j][1]][t[i][1]]==True:
            tmp-=1
        if tmp>ans:
            ans=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
HW = []
for i in range(M):
	HW.append(list(map(int,input().split())))

#H方向の走査
Hmax = 0
Hmax_temp = 0
y_max = []
for y in range(1,H+1):
	for j in HW:
		if y == j[0]:
			Hmax_temp += 1
	if Hmax_temp >= Hmax:
		Hmax = Hmax_temp
		y_max.append(y)
	Hmax_temp = 0

#W方向の走査
Wmax = 0
Wmax_temp = 0
x_max = []
for x in range(1,W+1):
	for j in HW:
		if x == j[1]:
			Wmax_temp += 1
	if Wmax_temp >= Wmax:
		Wmax = Wmax_temp
		x_max.append(x)
	Wmax_temp = 0

#爆弾設置位置に対象が存在するか？
for i in y_max:
	for  j in x_max:
		if [i,j] not in HW:
			ans = Hmax + Wmax
			break
		else:
			ans = Hmax + Wmax - 1

print(ans)

Submission status: Wrong Answer

Solution code:
r,c,m=map(int,input().split())
cols=[0]*c
rows=[0]*r
rid=[]
cid=[]
ans=0
for i in range(m):
  a,b=map(int,input().split())
  rows[a-1]+=1
  cols[b-1]+=1
  rid.append(a-1)
  cid.append(b-1)
sqr=rows.index(max(rows))
sqc=cols.index(max(cols))
for i in range(m):
    if rid[i]==sqr:
        if cid[i]==sqc:
            ans-=1
            break
ans+=max(rows)+max(cols)
print(ans)

Submission status: Wrong Answer

Solution code:
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

rowcnt, colcnt = [0] * H, [0] * W
for h, w in hw:
    rowcnt[h - 1] += 1
    colcnt[w - 1] += 1

rowmax, colmax = max(rowcnt), max(colcnt)
print(rowmax + colmax - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m=map(int, input().split())
hw=[tuple(map(int,input().split())) for i in range(m)]
H=np.zeros(h)
W=np.zeros(w)
for i in range(m):
    hi,wi=hw[i]
    H[hi-1]+=1
    W[wi-1]+=1
hmax=[i for i, x in enumerate(H) if x == max(H)]
wmax=[i for i, x in enumerate(W) if x == max(W)]
checker=[]
for Hi in hmax:
  for Wi in wmax:
    checker.append((Hi+1,Wi+1))
if len(list(set(checker)&set(hw)))<len(checker) :
    print(int(max(H)+max(W)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

ddh = defaultdict(int)
ddw = defaultdict(int)
ddm = defaultdict(int)

h,w,m = map(int,input().split())
for _ in range(m):
    h,w = map(int,input().split())
    ddh[h]+=1
    ddw[w]+=1
    ddm[(h,w)]+=1

# print(ddh)
# print(ddw)
# print(ddm)

max_h_k = max(ddh,key=ddh.get)
max_w_k = max(ddw,key=ddw.get)

if ddm[(max_h_k,max_w_k)]==0:
    print(ddh[max_h_k]+ddw[max_w_k])
else:
    print(ddh[max_h_k]+ddw[max_w_k]-ddm[(max_h_k,max_w_k)])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

ddh = defaultdict(int)
ddw = defaultdict(int)
ddm = defaultdict(int)

h,w,m = map(int,input().split())
for _ in range(m):
    h,w = map(int,input().split())
    ddh[h]+=1
    ddw[w]+=1
    ddm[(h,w)]+=1

# print(ddh)
# print(ddw)
# print(ddm)

max_h_k = max(ddh,key=ddh.get)
max_w_k = max(ddw,key=ddw.get)

if ddm[(max_h_k,max_w_k)]==0:
    print(ddh[max_h_k]+ddw[max_w_k])
else:
    print(ddh[max_h_k]+ddw[max_w_k]-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

height, width, num = map(int, input().split())

bomb_rows = np.zeros(height)
bomb_cols = np.zeros(width)
bomb_pos = []
for index in range(num):
  x, y = map(int, input().split())
  bomb_rows[x - 1] += 1
  bomb_cols[y - 1] += 1
  bomb_pos.append([x - 1, y - 1])
  
max_row = 0
max_row_pos = []
max_col = 0
max_col_pos = []

for index in range(height):
  if bomb_rows[index] > max_row:
    max_row = bomb_rows[index]
    max_row_pos = [index]
  elif bomb_rows[index] == max_row:
    max_row_pos.append(index)
    
for index in range(width):
  if bomb_cols[index] > max_col:
    max_col = bomb_cols[index]
    max_col_pos = [index]
  elif bomb_cols[index] == max_col:
    max_col_pos.append(index)

if len(max_row_pos) * len(max_col_pos) > num:
  max_value = int(max_row + max_col)
else:
  max_value = int(max_row + max_col - 1)
  '''
  all_pos_num = len(max_row_pos) * len(max_col_pos)
  for item in bomb_pos:
    for pos_row in max_row_pos:
      if item[0] == pos_row:
        for pos_col in max_col_pos:
          if item[1] == pos_col:
            all_pos_num -= 1
            break
#    if item[0] in max_row_pos and item[1] in max_col_pos:
#      all_pos_num -= 1
    if all_pos_num == 0:
      break
  if all_pos_num == 0:
    max_value = int(max_row + max_col - 1)
  else:
    max_value = int(max_row + max_col)
  '''

print(max_value)

Submission status: Wrong Answer

Solution code:
import numpy as np

height, width, num = map(int, input().split())

bomb_rows = np.zeros(height)
bomb_cols = np.zeros(width)
bomb_pos = []
for index in range(num):
  x, y = map(int, input().split())
  bomb_rows[x - 1] += 1
  bomb_cols[y - 1] += 1
  bomb_pos.append([x - 1, y - 1])
  
max_row = 0
max_row_pos = []
max_col = 0
max_col_pos = []

for index in range(height):
  if bomb_rows[index] > max_row:
    max_row = bomb_rows[index]
    max_row_pos = [index]
  elif bomb_rows[index] == max_row:
    max_row_pos.append(index)
    
for index in range(width):
  if bomb_cols[index] > max_col:
    max_col = bomb_cols[index]
    max_col_pos = [index]
  elif bomb_cols[index] == max_col:
    max_col_pos.append(index)

max_value = int(max_row + max_col)
'''
if len(max_row_pos) * len(max_col_pos) > num:
  max_value = int(max_row + max_col)
else:
  all_pos_num = len(max_row_pos) * len(max_col_pos)
  for item in bomb_pos:
    if item[0] in max_row_pos and item[1] in max_col_pos:
      all_pos_num -= 1
    if all_pos_num == 0:
      break
  if all_pos_num == 0:
    max_value = int(max_row + max_col - 1)
  else:
    max_value = int(max_row + max_col)
'''

print(max_value)

Submission status: Wrong Answer

Solution code:
def main():
    H,W,M = map(int,input().split())
    s = []
    h_cnt = [0 for i in range(H)]
    w_cnt = [0 for i in range(W)]
    for i in range(M):
        h,w = map(int,input().split())
        s.append([h-1,w-1])
        h_cnt[h-1] += 1
        w_cnt[w-1] += 1
    h_m,w_m = max(h_cnt), max(w_cnt)
    h_mp,w_mp = [],[]
    for i in range(h):
        if h_cnt[i] == h_m:
            h_mp.append(i)
    for i in range(w):
        if w_cnt[i] == w_m:
            w_mp.append(i)
    f = 0
    for i in range(M):
        if h_cnt[s[i][0]] == h_m and w_cnt[s[i][1]] == w_m:
            f += 1
    if len(w_mp)*len(h_mp)-f<1:
        print(h_m+w_m-1)
    else:
        print(h_m+w_m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    H,W,M = map(int,input().split())
    s = [[0 for i in range(W)] for i in range(H)]
    h_cnt = [0 for i in range(H)]
    w_cnt = [0 for i in range(W)]
    for i in range(M):
        h,w = map(int,input().split())
        s[h-1][w-1] = 1
        h_cnt[h-1] += 1
        w_cnt[w-1] += 1
    h_m,w_m = max(h_cnt), max(w_cnt)
    h_mp,w_mp = [],[]
    for i in range(h):
        if h_cnt[i] == h_m:
            h_mp.append(i)
    for i in range(w):
        if w_cnt[i] == w_m:
            w_mp.append(i)
    for i in range(len(h_mp)):
        for j in range(len(w_mp)):
            if s[h_mp[i]][w_mp[j]] == 0:
                print(h_m+w_m)
                return
    print(h_m+w_m-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  lh=[]
  lw=[]
  d={}
  for _ in range(M):
    a,b=LI()
    a-=1
    b-=1
    lh.append(a)
    lw.append(b)
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(lh):
    if x==h_max:
      h_koho.append(x)
  for i,x in enumerate(lw):
    if x==w_max:
      w_koho.append(x)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1

# main()
print(main())