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())
hl=[0]*(h+1)
wl=[0]*(w+1)
bom=[]
for i in range(m):
  h,w=map(int,input().split())
  bom.append([h-1,w-1])
  hl[h-1]+=1
  wl[w-1]+=1
mh=max(hl)
mw=max(wl)
ans=mh+mw
mhl=set()
mwl=set()
for i in range(h):
  if mh==hl[i]:
    mhl.add(i)
for i in range(w):
  if mw==wl[i]:
    mwl.add(i)
count=len(mhl)*len(mwl)
for i in range(len(bom)):
  if bom[i][0] in mhl and bom[i][1] in mwl:
    count-=1
if count<=0:
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hl=[0]*(h+1)
wl=[0]*(w+1)
bom=[]
for i in range(m):
  h,w=map(int,input().split())
  bom.append([h-1,w-1])
  hl[h-1]+=1
  wl[w-1]+=1
mh=max(hl)
mw=max(wl)
ans=mh+mw
mhl=set()
mwl=set()
for i in range(m):
  if mh==bom[i][0]:
    mhl.add(i)
  if mw==bom[i][1]:
    mwl.add(i)
count=len(mhl)*len(mwl)

for i in range(len(bom)):
  if bom[i][0] in mwl and bom[i][1] in mhl:
    count-=1
if count<=0:
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hl=[0]*(h+1)
wl=[0]*(w+1)
bom=[]
for i in range(m):
  h,w=map(int,input().split())
  bom.append([h-1,w-1])
  hl[h-1]+=1
  wl[w-1]+=1
mh=max(hl)
mw=max(wl)
m_h_count=0
m_w_count=0
ans=mh+mw
mhl=set()
mwl=set()
for i in range(m):
  if mh==bom[i][0]:
    m_h_count+=1
    mhl.add(i)
  if mw==bom[i][1]:
    m_w_count+=1
    mwl.add(i)
count=m_h_count*m_w_count

for i in range(len(bom)):
  if bom[i][0] in mhl and bom[i][1] in mwl:
    count-=1
if count<=0:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
ans=0
mass=set()
for i in range(M):
    h,w=nm()
    mass.add(H*h+w)
    r[h]+=1
    c[w]+=1

inds1=list(range(10**6))
inds1.sort(reverse=True,key=lambda x: r[x])

inds2=list(range(10**6))
inds2.sort(reverse=True,key=lambda x: c[x])

r.sort(reverse=True)
c.sort(reverse=True)

rl=[inds1[0]]
cl=[inds2[0]]

r1=0
l1=0

while(1):
    if(r[inds1[r1+1]]==r[inds1[r1]]):
        r1+=1
        rl.append(inds1[r1])
    else:
        break

while(1):
    if(c[inds2[l1+1]]==c[inds2[l1]]):
        l1+=1
        cl.append(inds2[l1])
    else:
        break



flag=False
for i in rl:
    for j in cl:
        if(i*H+j not in mass):
            print(r[0]+c[0])
            sys.exit(0)


print(r[0]+c[0]-1)

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
ans=0
mass=set()
for i in range(M):
    h,w=nm()
    mass.add(H*h+w)
    r[h]+=1
    c[w]+=1

inds1=list(range(10**6))
inds1.sort(reverse=True,key=lambda x: r[x])

inds2=list(range(10**6))
inds2.sort(reverse=True,key=lambda x: c[x])

r.sort(reverse=True)
c.sort(reverse=True)

rl=[r[0]]
cl=[c[0]]

r1=0
l1=0

while(1):
    if(r[inds1[r1+1]]==r[inds1[r1]]):
        r1+=1
        rl.append(r[inds1[r1]])
    else:
        break

while(1):
    if(c[inds2[l1+1]]==c[inds2[l1]]):
        l1+=1
        cl.append(c[inds2[l1]])
    else:
        break



flag=False
for i in rl:
    for j in cl:
        if(i*H+j not in mass):
            print(r[0]+c[0])
            sys.exit(0)


print(r[0]+c[0]-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque,Counter,defaultdict

H,W,M = map(int , input().split())
alls = defaultdict(set)
ths = deque()
tws = deque()

for _ in range(M):
  h,w = map(int,input().split())
  ths.append(h)
  tws.append(w)
  alls[h].add(w)


mh = Counter(ths).most_common()
mw = Counter(tws).most_common()

tghq = deque()
tgwq = []

tghq.append(mh[0])
tgwq.append(mw[0])

if len(mh)>1:
  i=1
  while mh[0][1] == mh[i][1]:
    tghq.append(mh[i])
    i+=1
    if i >= len(mh):
      break

if len(mw)>1:
  i=1
  while mw[0][1] == mw[i][1]:
    tgwq.append(mw[i])
    i+=1
    if i >= len(tgwq):
      break

sums = mw[0][1] + mh[0][1] - 1
breaker = True
while tghq and breaker:
  tgh,mxh = tghq.pop()
  for tw in tgwq:
    if tw[0] not in alls[tgh]:
      sums +=1
      breaker = False
      break

print(sums)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
a = []
b = []
for _ in range(m):
    i,j = map(int,input().split())
    a.append(i)
    b.append(j)
u = [(a[i],b[i]) for i in range(m)]
from collections import Counter
c = Counter(a)
d = Counter(b)
z = 0
if (c.most_common()[0][0],d.most_common()[0][0]) in u:
    z = 1
print(c.most_common()[0][1]+d.most_common()[0][1]-z)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque,Counter,defaultdict

H,W,M = map(int , input().split())
alls = defaultdict(set)
ths = deque()
tws = deque()
for _ in range(M):
  h,w = map(int,input().split())
  ths.append(h)
  tws.append(w)
  alls[h].add(w)
tgh,resulthnum = Counter(ths).most_common(1)[0]
tgw,resultwnum = Counter(tws).most_common(1)[0]
sums = resulthnum + resultwnum
print(sums)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque,Counter,defaultdict

H,W,M = map(int , input().split())
alls = defaultdict(set)
ths = deque()
tws = deque()
for _ in range(M):
  h,w = map(int,input().split())
  ths.append(h)
  tws.append(w)
  alls[h].add(w)
tgh,resulthnum = Counter(ths).most_common(1)[0]
tgw,resultwnum = Counter(tws).most_common(1)[0]
sums = resulthnum + resultwnum
print(sums-1 if tgw in alls[tgh] else sums)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
import numpy as np
from  collections import Counter
 
hw = np.zeros(
  (M, 2),np.uint8
)
for _ in range(M):
  h, w = map(int, input().split())
  hw[_][0] = h
  hw[_][1] = w
  
#print(hw, hw[:, 0])
c_h = Counter(hw[:, 0]).most_common()
c_w = Counter(hw[:, 1]).most_common()

 
max_ch = c_h[0][1]
max_ch_lst = []
for _c_h in c_h:
  if _c_h[1] == max_ch:
    max_ch_lst.append(_c_h[0])
  else:
    break
    
max_cw = c_w[0][1]
max_cw_lst = []
for _c_w in c_w:
  if _c_w[1] == max_cw:
    max_cw_lst.append(_c_w[0])
  else:
    break

#print(max_ch_lst, max_cw_lst, hw)

flg = 1
for h in max_ch_lst:
  for w in max_cw_lst:
    if [h, w] not in hw:
      flg = 0
      break

print(max_ch + max_cw - flg)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
  h[l[i][0]-1]=h[l[i][0]-1]+1
  w[l[i][1]-1]=w[l[i][1]-1]+1
maxh=max(h)
maxw=max(w)
max_h=[i for i,k in enumerate(h) if k==maxh]
max_w=[i for i,k in enumerate(w) if k==maxw]
flag=0
for i in max_h:
  for j in max_w:
    c=0
    for k in range(M):
      if i==l[k][0]-1 or j==l[k][1]-1:
        c=1
    if c==0:
      flag=1
      print(maxh+maxw)
      
    if flag==1:
      break
  if flag==1:
    break
if flag==0:
  print(maxh+maxw-1)

Submission status: Wrong Answer

Solution code:
h, w, m =map(int,input().split())
nh=[0]*h
nw=[0]*w
boms=set()
for _ in range(m):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))
maxh = max(nh)
maxw = max(nw)
 
list_i=[]
for i in range(h):
    if nh[i] == maxh:
        list_i.append(i)
list_j=[]
for j in range(w):
    if nw[j] == maxw:
        list_j.append(j)
for i in list_i:
    for j in list_j:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
bomb = []
h_bomb = []
w_bomb = []
for i in range(m):
    bomb.append(list(map(int, input().split())))
for k in range(h):
    h_bomb.append(0)
for l in range(w):
    w_bomb.append(0)
for j in range(m):
    h_bomb[bomb[j][0] - 1] += 1
    w_bomb[bomb[j][1] - 1] += 1
print(max(h_bomb) + max(w_bomb))

Submission status: Wrong Answer

Solution code:
import numpy as np

H,W,M = input().split()
A = []
S = 0
for i in range(int(M)):
    a_ = input().split()
    a = [int(i)-1 for i in a_]
    A.append(a)
A = np.array(A)
h_ = range(int(H))
w_ = range(int(W))

for i in h_:
    for j in w_:
        s = sum(A[: , 0]==i) + sum(A[: , 1]==j) 
        if [i,j] in A:
            s -=1
        if s > S:
            S =s
print(S)

Submission status: Wrong Answer

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

row = [0]*h
col = [0]*w
bombs = []
for i in range(m):
    x,y = map(int,input().strip().split(" "))
    bombs.append((x-1,y-1))
    row[x-1] += 1
    col[y-1] += 1

mr = 0
mri = 0
for i in range(h):
    if row[i]>mr:
        mr = row[i]
        mri = i

mc = 0
mci = 0
for i in range(w):
    if col[i]>mc:
        mc = col[i]
        mci = i

ans = mc+mr
if (mri,mci) in bombs:
    ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
#E
H,W,M=map(int,input().split())
H=[0 for i in range(3*10**5+1)]
W=[0 for i in range(3*10**5+1)]
P=[0 for i in range(M)]
for i in range(M):
    h,w=map(int,input().split())
    P[i]=[h,w]
    H[h]+=1
    W[w]+=1

MAX_h,MAX_w=[max(H),max(W)]
flag=False
for i in range(M):
    h,w=P[i]
    if H[h]==MAX_h and W[w]==MAX_w:
        flag=True
    
if flag:
    ans=MAX_h+MAX_w-1
else:
    ans=MAX_h+MAX_w
print(ans)

Submission status: Wrong Answer

Solution code:
#E
H,W,M=map(int,input().split())
H=[0 for i in range(3*10**5+1)]
W=[0 for i in range(3*10**5+1)]
P=[0 for i in range(M)]
for i in range(M):
    h,w=map(int,input().split())
    P[i]=[h,w]
    H[h]+=1
    W[w]+=1

MAX_h,MAX_w=[max(H),max(W)]
flag=False
for i in range(M):
    h,w=P[i]
    if h==MAX_h and w==MAX_w:
        flag=True
    
if flag:
    ans=MAX_h+MAX_w-1
else:
    ans=MAX_h+MAX_w
print(ans)

Submission status: Wrong Answer

Solution code:
#E
H,W,M=map(int,input().split())
H=[0 for i in range(3*10**5+1)]
W=[0 for i in range(3*10**5+1)]
P=[0 for i in range(M)]
for i in range(M):
    h,w=map(int,input().split())
    P[i]=[h,w]
    H[h]+=1
    W[w]+=1

MAX_h,MAX_w=[max(H),max(W)]
flag=False
for i in range(M):
    h,w=P[i]
    if h==MAX_h and w==MAX_w:
        flag=True
    
if flag:
    ans=MAX_h+MAX_w-1
else:
    ans=MAX_h+MAX_w-1
print(ans)

Submission status: Wrong Answer

Solution code:
#E
H,W,M=map(int,input().split())
H=[0 for i in range(3*10**5+1)]
W=[0 for i in range(3*10**5+1)]

for i in range(M):
    h,w=map(int,input().split())
    H[h]+=1
    W[w]+=1
    
ans=max(H)+max(W)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
x = []
max_a = 0
max_b = 0
a = []
b = []
for _ in range(m):
    x.append(input().split())

for i in range(h):
    cnt_a = 0
    for j in range(m):
        if str(i) == x[j][0]:
            cnt_a += 1
    if max_a < cnt_a:
        max_a = cnt_a
        a.clear()
        a.append(i)
    elif max_a == cnt_a:
        a.append(i)

for i in range(w):
    cnt_b = 0
    for j in range(m):
        if str(i) == x[j][1]:
            cnt_b += 1
    if max_b < cnt_b:
        max_b = cnt_b
        b.clear()
        b.append(i)
    elif max_b == cnt_b:
        b.append(i)
for i in a:
    for j in b:
        xx = [str(i), str(j)]
        if xx not in x:
            print(int(max_a) + int(max_b))
            exit()
else:
    print(int(max_a) + int(max_b) - 1)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
x = []
max_a = 0
max_b = 0
a = []
b = []
for _ in range(m):
    x.append(input().split())

for i in range(h):
    cnt_a = 0
    for j in range(m):
        if str(i) == x[j][0]:
            cnt_a += 1
    if max_a < cnt_a:
        max_a = cnt_a
        a.clear()
        a.append(i)
    elif max_a == cnt_a:
        a.append(i)

for i in range(w):
    cnt_b = 0
    for j in range(m):
        if str(i) == x[j][1]:
            cnt_b += 1
    if max_b < cnt_b:
        max_b = cnt_b
        b.clear()
        b.append(i)
    elif max_b == cnt_b:
        b.append(i)

for i in a:
    for j in b:
        xx = [a, b]
        if xx not in x:
            print(int(max_a) + int(max_b))
            exit()
else:
    print(int(max_a) + int(max_b) - 1)

Submission status: Wrong Answer

Solution code:
########### E
H, W, M = map(int, input().split())
bombs = []
for _ in range(M):
    bomb = list(map(lambda x:int(x)-1, input().split()))
    bombs.append(bomb)

H_list = [0]*H
W_list = [0]*W
sign = True
for h,w in bombs:
    H_list[h] += 1
    W_list[w] += 1
    
maxX = max(H_list)
maxY = max(W_list)

max_H = [i for i,k in enumerate(H_list) if k == maxX]
max_W = [i for i,k in enumerate(W_list) if k == maxY]

cross = []

for i in max_H:
    for k in max_W:
        if [i,k] not in bombs:
            sign = False
            print(maxX + maxY)
            break
    break

if sign:
    print(maxX + maxY -1)

Submission status: Wrong Answer

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

Hmax_temp = [0]*(H+1)
Wmax_temp = [0]*(W+1)
Hmax = 0
Wmax = 0
Bomb = dict()
for i in range(M):
	H_M,W_M = map(int,input().split())
	Hmax_temp[H_M] += 1
	Wmax_temp[W_M] += 1
	Bomb[(H_M,W_M)] = 1

Hmax = max(Hmax_temp)
Wmax = max(Wmax_temp)

#H方向の走査
y_max = []
for i in range(H+1):
	if Hmax == Hmax_temp[i]:
		y_max.append(i)
		
#W方向の走査
x_max = []
for j in range(W+1):
	if Wmax == Wmax_temp[j]:
		x_max.append(j)

#爆弾設置位置に対象が存在するか？
flag = False
for i in y_max:
	for  j in x_max:
		if (i,j) in Bomb:
			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())
hallline = [0 for i in range(H)]
wallline = [0 for i in range(W)]
b = {}

for i in range(M):
    tmp = list(map(lambda x: int(x) - 1, input().split()))
    hallline[tmp[0]] += 1
    wallline[tmp[1]] += 1
    b[(tmp[0], tmp[1])] = True

t = max(hallline)
s = max(wallline)

a = (i for i in range(H) if hallline[i] == t)
c = (i for i in range(W) if wallline[i] == s)

for i in a:
    for j in c:
        if (i, j) not in b.keys():
            print(t + s)
            exit()
print(t + s - 1)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
hallline = [0 for i in range(H)]
wallline = [0 for i in range(W)]
b = {}

for i in range(M):
    tmp = list(map(lambda x: int(x) - 1, input().split()))
    hallline[tmp[0]] += 1
    wallline[tmp[1]] += 1
    b[(tmp[0], tmp[1])] = True

t = max(hallline)
s = max(wallline)

a = (i for i in range(H) if hallline[i] == t)
c = (i for i in range(W) if wallline[i] == s)

for i in a:
    for j in c:
        try:
            b[(i, j)]
        except:
            print(t + s)
            exit()
print(t + s - 1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

H, W, M = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(M)]

dh, dw = defaultdict(int), defaultdict(int)
used = set()

for h, w in l:
    dh[h] += 1
    dw[w] += 1
    used.add((h, w))

ih = sorted(dh.items(), key=lambda x:-x[1])
iw = sorted(dw.items(), key=lambda x:-x[1])

def get(x):
    h, counth = ih[x]
    w, countw = iw[x]
    ans = counth + countw
    if (h, w) in used:
        ans -= 1
    return ans

ans = get(0)
for h, w in l:
    ans = max(ans, dh[h]+dw[w]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp[i]=[s[i],t[i]]
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)
c=0
for i in range(len(maxs)):
  for j in range(len(maxt)):
    if (maxs[i]+1,maxt[j]+1) not in temp:
      print(ans)
      exit()
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)
c=0
for i in range(len(maxs)):
  if maxs[i]+1 in s:
    for j in range(len(maxt)):
      if maxt[j]+1 in t:
        c=c+1
if c==len(maxs)*len(maxt):
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)
c=0
for i in range(len(maxs)):
  if st[i]+1 in s:
    for j in range(len(maxt)):
      if tt[j]+1 in t:
        c=c+1
if c==len(maxs)*len(maxt):
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)
c=0
for i in range(len(maxs)):
  if st[i] in s:
    for j in range(len(maxt)):
      if tt[j] in t:
        c=c+1
if c==len(maxs)*len(maxt):
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)
print(st,tt,maxs,maxt)
c=0
for i in range(len(maxs)):
  if st[i] in s:
    for j in range(len(maxt)):
      if tt[j] in t:
        c=c+1
if c==len(maxs)*len(maxt):
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m  = list(map(int, input().strip().split()))
a=[0]*m
A=[0]*h
b=[0]*m
B=[0]*w
grid = []
for i in range(m):
    a[i],b[i]= list(map(int, input().strip().split()))
for i in range(m):
    A[a[i]-1]=a.count(a[i])
    B[b[i]-1]=b.count(b[i])
p=max(A)
q=max(B)

S=[]

T=[]
for i in range(m):
    if A[a[i]-1]==p:
        S.append(a[i])
for i in range(m):
    if B[b[i]-1]==q:
        T.append(b[i])
S=list(set(S))
T=list(set(T))
f=0
for i in range(m):
    if A[a[i]-1]==p :
        f=f+1
if len(S)*len(T)>f:
    ans=p+q
else:
    ans=p+q-1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m  = list(map(int, input().strip().split()))
a=[0]*m
A=[0]*h
b=[0]*m
B=[0]*w
grid = []
for i in range(m):
    a[i],b[i]= list(map(int, input().strip().split()))
for i in range(m):
    A[a[i]-1]=a.count(a[i])
    B[b[i]-1]=b.count(b[i])
p=max(A)
q=max(B)

S=[]

T=[]
for i in range(m):
    if A[a[i]-1]==p:
        S.append(a[i])
for i in range(m):
    if B[b[i]-1]==q:
        T.append(b[i])
S=list(set(S))
T=list(set(T))
f=0
for i in range(m):
    if A[a[i]-1]==p :
        f=f+1
if len(S)*len(T)>f:
    ans=p+q
else:
    ans=p+q-1
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
ans=max(st)+max(tt)
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==max(st):
    maxs.append(st[i])
for i in range(w):
  if tt[i]==max(tt):
    maxt.append(tt[i])
for i in range(len(maxs)):
  for j in range(len(maxt)):
    if maxs[i]!=maxt[j]:
      print(ans)
      exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m  = list(map(int, input().strip().split()))
a=[0]*m
A=[0]*h
b=[0]*m
B=[0]*w
grid = []
for i in range(m):
    a[i],b[i]= list(map(int, input().strip().split()))
for i in range(m):
    A[a[i]-1]=a.count(a[i])
    B[b[i]-1]=b.count(b[i])
#print(A,B)
p=max(A)
q=max(B)
#print(p,q)
s=[]
S=[]
t=[]
T=[]
for i in range(m):
    if A[a[i]-1]==p:
        s.append(i)
        S.append(a[i])
    if B[b[i]-1]==q:
        t.append(i)
        T.append(b[i])
#S=list(set(S))
#T=list(set(T))
if abs(len(S)-len(T)) >abs(len(s)-len(t)):
    ans=p+q
else:
    ans=p+q-1
#print(S,T)
#print(s,t)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m  = list(map(int, input().strip().split()))
a=[0]*m
A=[0]*h
b=[0]*m
B=[0]*w
grid = []
for i in range(m):
    a[i],b[i]= list(map(int, input().strip().split()))
for i in range(m):
    A[a[i]-1]=a.count(a[i])
    B[b[i]-1]=b.count(b[i])

p=max(A)
q=max(B)
ans=p+q-1
f=0
for i in range(m):
    if A[a[i]-1]==p and B[b[i]-1]!=q:
        ans+=1
        break
    elif A[a[i]-1]!=p and B[b[i]-1]==q:
        ans+=1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m  = list(map(int, input().strip().split()))
a=[0]*m
A=[0]*h
b=[0]*m
B=[0]*w
grid = []
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
for i in range(m):
    a[i]=grid[i][0]
    A[a[i]-1]+=1
    b[i]=grid[i][1]
    B[b[i]-1]+=1
ans=max(A)+max(B)
x=np.argmax(A)
y=np.argmax(B)
for i in range(m):
    if a[i]==x+1 and b[i]==y+1:
        ans-=1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

h,w,m = map(int,input().split())
X = []
Y = []
for _ in range(m):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
#まず一番大いX座標を調べる
most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0] #x座標
most_common_x_count = most_common_x[0][1] #その線に存在する爆弾の個数
#爆破されない座標たちの共通するY座標を探す
otherwise = []
for i in range(m):
    if X[i] != most_common_x_index:#not most common
        otherwise.append(Y[i])
most_common_y = collections.Counter(otherwise).most_common()
if len(most_common_y)!= 0: #ある特定のyが存在した時
    ansx = most_common_y[0][1] + most_common_x_count
else:#もともと全部のy座標が揃っていた時
    ansx = most_common_x_count
#次にY座標を基準にして調べる
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0] #x座標
most_common_y_count = most_common_y[0][1] #その線に存在する爆弾の個数
otherwise = []
for i in range(m):
    if Y[i] != most_common_y_index:#not most common
        otherwise.append(Y[i])
most_common_x = collections.Counter(otherwise).most_common()
if len(most_common_x)!= 0 :
    ansy = most_common_x[0][1] + most_common_y_count
else:
    ansy = most_common_y_count
print(max(ansx,ansy))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import operator
h, w, m = map(int, input().split())
bomb = list()
for _ in range(m):
  bomb.append(tuple(map(int, input().split())))
row = list()
col = list()
for a, b in bomb:
  row.append(a)
  col.append(b) 
dictRow = sorted(dict(Counter(row)).items(), key = lambda x:x[1], reverse = True)
dictCol = sorted(dict(Counter(col)).items(), key = lambda x:x[1], reverse = True)
maxRow = dictRow[0][1]
maxCol = dictCol[0][1]
listofMaxRow = []
for a, b in dictRow:
  if(b == maxRow):
    listofMaxRow.append(a)
  else:
    break

listofMaxCol = []
for a, b in dictCol: 
  if(b == maxCol):
    listofMaxCol.append(a)
  else:
    break
result = maxRow + maxCol - 1
for i in listofMaxRow:
  for j in listofMaxCol:
    if((i, j) not in bomb):
      result += 1
      break
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import operator
h, w, m = map(int, input().split())
bomb = list()
for _ in range(m):
  bomb.append(tuple(map(int, input().split())))
row = list()
col = list()
for a, b in bomb:
  row.append(a)
  col.append(b) 
dictRow = sorted(dict(Counter(row)).items(), key = lambda x:x[1], reverse = True)
dictCol = sorted(dict(Counter(col)).items(), key = lambda x:x[1], reverse = True)
maxRow = dictRow[0][1]
maxCol = dictCol[0][1]
listofMaxRow = []
for a, b in dictRow:
  if(b == maxRow):
    listofMaxRow.append(a)
  else:
    break

listofMaxCol = []
for a, b in dictCol: 
  if(b == maxCol):
    listofMaxRow.append(a)
  else:
    break
result = maxRow + maxCol - 1
for i in listofMaxRow:
  for j in listofMaxCol:
    if( tuple(i, j) not in bomb):
      result += 1
      break
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    h,w,m=map(int,input().split())
    target=set()
    for i in range(m):
        th,tw=map(int,input().split())
        target.add((th-1,tw-1))
    lines=[0]*w
    rows=[0]*h
    for th,tw in target:
        lines[tw]+=1
        rows[th]+=1
    max_lines=max(lines)
    max_rows=max(rows)
    max_wi=[i for i,wi in enumerate(lines) if wi==max_lines]
    max_hi=[i for i,hi in enumerate(rows) if hi==max_rows]
    # print(max_rows,max_hi,max_lines,max_wi)
    ans=max_lines+max_rows-1
    for wi in max_wi:
        for hi in max_hi:
            if not (hi,wi) in target:
                ans+=1
                break
    return ans

if __name__=='__main__':
    ans=main()
    print(ans)

Submission status: Wrong Answer

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

H_list = [0]*H
W_list = [0]*W

bom_list = list()

for i in range(M):
    h,w = map(int,input().split())
    bom_list.append([h,w])
    H_list[h-1] += 1
    W_list[w-1] += 1

max_H = max(H_list)
max_W = max(W_list)

print(max_H+max_W)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
L=[]
bh=[0]*(H+1)
bw=[0]*(W+1)
mh,mw=[0,[]],[0,[]]
for _ in range(M):
    h,w=map(int,input().split())
    L.append((h,w))
    bh[h]+=1
    bw[w]+=1
    if bh[h]>mh[0]:
        mh=[bh[h],[h]]
    elif bh[h]==mh[0]:
        mh[1].append(h)
    if bw[w]>mw[0]:
        mw=[bw[w],[w]]
    elif bw[w]==mw[0]:
        mw[1].append(w)
ans=mh[0]+mw[0]-1
for h in mh[1]:
    for w in mw[1]:
        if (h,w) not in L:
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve(H, W, M, h, w):
    f = [0] * (H+1)
    g = [0] * (W+1)
    for r, c in zip(h, w):
        f[r] += 1
        g[c] += 1
    r = np.argmax(f)
    c = np.argmax(g)
    return f[r] + g[c] - int((r, c) in set(zip(h, w)))

H, W, M = map(int, input().split())
h, w = zip(*[map(int, input().split()) for i in range(M)])
print(solve(H, W, M, h, w))

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve(H, W, M, h, w):
    f = [0] * H
    g = [0] * W
    for r, c in zip(h, w):
        f[r-1] += 1
        g[c-1] += 1
    r = np.argmax(f)
    c = np.argmax(g)
    print(f[r], g[c])
    return f[r] + g[c] - int((r+1, c+1) in set(zip(h, w)))

H, W, M = map(int, input().split())
h, w = zip(*[map(int, input().split()) for i in range(M)])
print(solve(H, W, M, h, w))

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
L=[]
bh=[0]*(H+1)
bw=[0]*(W+1)
mh,mw=[0,[]],[0,[]]
for _ in range(M):
    h,w=map(int,input().split())
    L.append((h,w))
    bh[h]+=1
    bw[w]+=1
    if bh[h]>mh[0]:
        mh=[bh[h],[h]]
        nh=1
    elif bh[h]==mh[0]:
        mh[1].append(h)
        nh+=1
    if bw[w]>mw[0]:
        mw=[bw[w],[w]]
        nw=1
    elif bw[w]==mw[0]:
        mw[1].append(w)
        nw+=1
ans=mh[0]+mw[0]-1
for h in mh[1]:
    for w in mw[1]:
        if (h,w) not in L:
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
bh=[0]*(H+1)
bw=[0]*(W+1)
mh,mw=[0,[]],[0,[]]
for _ in range(M):
    h,w=map(int,input().split())
    bh[h]+=1
    bw[w]+=1
    if bh[h]>mh[0]:
        mh=[bh[h],{w}]
    if bh[h]==mh[0]:
        mh[1].add(w)
    if bw[w]>mw[0]:
        mw=[bw[w],{w}]
    if bw[w]==mw[0]:
        mw[1].add(w)
ans=mh[0]+mw[0]
if mh[1] ^ mw[1]:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
bh=[0]*(H+1)
bw=[0]*(W+1)
ml,mh,mw=[],(0,0),(0,0)
for _ in range(M):
    h,w=map(int,input().split())
    bh[h]+=1
    bw[w]+=1
    ml.append((h,w))
    if bh[h]>mh[0]:
        mh=(bh[h],h)
    if bw[w]>mw[0]:
        mw=(bw[w],w)
ans=mh[0]+mw[0]
if (mh[1],mw[1]) in ml:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
bh=[0]*(H+1)
bw=[0]*(W+1)
g=[[False]*(W+1) for _ in range(H+1)]
mh,mw=(0,0),(0,0)
for _ in range(M):
    h,w=map(int,input().split())
    bh[h]+=1
    bw[w]+=1
    g[h][w]=True
    if bh[h]>mh[0]:
        mh=(bh[h],h)
    if bw[w]>mw[0]:
        mw=(bw[w],w)
ans=mh[0]+mw[0]
if g[mh[1]][mw[1]]:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


H, W, M = MI()

R = np.zeros(H + 1)
C = np.zeros(W + 1)
bombs = []
for _ in range(M):
    h, w = MI()
    bombs.append((h, w))
    R[h] += 1
    C[w] += 1

R_max = [R == max(R)]
C_max = [C == max(C)]

ans = max(R) + max(C)
cnt = 0
for h, w in bombs:
    if R[h] and C[w]:
        cnt += 1

if cnt == np.count_nonzero(R_max) * np.count_nonzero(C_max):
    print(int(ans))
else:
    print(int(ans - 1))