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
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
ssi =lambda: stdin.readline()
sii =lambda: int(stdin.readline())
sp  =lambda x: stdout.write(str(x))

mod=1000000007


#main code

h,w,m=mi()
arr=[[0 for i in range(w)] for j in range(h)]
dx=dd(int)
dy=dd(int)
for i in range(m):
    x,y=mi()
    dx[x]+=1
    dy[y]+=1
x=max(dx, key=dx.get)
y=max(dy,key=dy.get)
a=max(dx.values())
b=max(dy.values())
if a==b:
    print(a+b-1)
elif x==y:
    print(a+b-1)
else:
    print(a+b)

Submission status: Wrong Answer

Solution code:
import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = [copy.deepcopy(width)]*H
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object[h-1][w-1] = 1
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
p = len(cand_h)*len(cand_w)
if M > p:
   for i in range(len(cand_h)):
      for j in range(len(cand_w)):
         if object[cand_h[i]][cand_w[j]] == 0:
            ans += 1
else:
   ans += 1
print(ans)

Submission status: Wrong Answer

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

hlist=[0]*H
wlist=[0]*W
hwset=set()
for _ in range(M):
  h,w=map(int,input().split())
  hlist[h-1]+=1
  wlist[w-1]+=1
  hwset.add((h-1,w-1))
  
hlist2=[]
for i in range(H):
  if hlist[i]>0:
    hlist2.append((hlist[i],i))
hlist2.sort(reverse=True)
wlist2=[]
for i in range(W):
  if wlist[i]>0:
    wlist2.append((wlist[i],i))
wlist2.sort(reverse=True)

#print(hlist2,wlist2)
H2=len(hlist2)
W2=len(wlist2)

answer=0
for i in range(min(H2,3000)):
  hh,ii=hlist2[i]
  for j in range(min(W2,3000)):
    ww,jj=wlist2[j]
    if (ii,jj) in hwset:
      answer=max(answer,hh+ww-1)
    else:
      answer=max(answer,hh+ww)
      
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import defaultdict

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=np.zeros(H,dtype=int)
sum2=np.zeros(W,dtype=int)
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

ans=0
for idx1,val1 in sum1[:min(3,len(sum1))]:
  for idx2,val2 in sum2:
    tmp = val1+val2-hw[(idx1,idx2)]
    ans = max(ans,tmp)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    l = []
    mm = []
    for h in range(H):
        l.append([None for i in range(W)])
    for i in range(M):
        a, b = map(int, input().split())
        mm.append([a, b])
        l[a-1][b-1] = 1
    gyo_max = 0
    gyo_num = 0
    column_max = 0
    column_num = 0
    for i in range(H):
        if gyo_max < l[i].count(1):
            gyo_max = l[i].count(1)
            gyo_num = i
    ll = np.array(l).T
    for i in range(W):
        m = np.count_nonzero(ll[i] == 1)
        if column_max < m:
            column_max = m
            column_num = i
        if column_max == m and column_num == gyo_num:
            column_num = i
    if [gyo_num+1, column_num+1] in mm:
        print(gyo_max + column_max - 1)
    else:
        print(gyo_max + column_max)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

num_boms_row = [0] * H
max_boms_row = [None, 0]

num_boms_col = [0] * W
max_boms_col = [None, 0]

boms = set()

for _ in range(M):
    h, w = map(int, input().split())
    # 0-index
    h -= 1
    w -= 1

    boms.add((h, w))
    num_boms_row[h] += 1
    num_boms_col[w] += 1

    if max_boms_row[1] < num_boms_row[h]:
        max_boms_row = [h, num_boms_row[h]]

    if max_boms_col[1] < num_boms_col[w]:
        max_boms_col = [w, num_boms_col[w]]

# pprint(max_boms_row)
# pprint(max_boms_col)

ans = max_boms_row[1] + max_boms_col[1]
if (max_boms_row[0], max_boms_col[0]) in boms:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
a = list(map(int,input().split()))
h = a[0]
w = a[1]
m = a[2]
ch = 0

xy = [map(int, input().split()) for _ in range(m)]
x, y = [list(i) for i in zip(*xy)]
xc=collections.Counter(x)
yc=collections.Counter(y)
x_m = xc.most_common()[0]
y_m = yc.most_common()[0]

xd = x_m[0]
yd = y_m[0]

if y_m[1] == 1:
  for i in range(m):
    if not x_m[0]==x[i]:
      yd=y[i]
      ch=1
      break

if x_m[1] == 1:
  for i in range(m):
    if not y_m[0]==y[i]:
      xd=x[i]
      ch =1
      break
if ch == 0:
  wa = x_m[1]+y_m[1]
else:
  wa = x.count(xd)+y.count(yd)

for i in  range(m):
  if x[i]==xd and y[i]==yd:
    wa=wa-1
    
print(wa)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

H, W, M = map(int, input().split())
horizon_set = defaultdict(set)
vertical_set = defaultdict(set)
horizon = defaultdict(int)
vertical = defaultdict(int)
bombs = []
for _ in range(M):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    horizon_set[y].add(x)
    vertical_set[x].add(y)
    horizon[y] += 1
    vertical[x] += 1
    bombs.append((x, y))

yn = sorted(horizon.items(), key=lambda yn: yn[::-1], reverse=True)
xn = sorted(vertical.items(), key=lambda xn: xn[::-1], reverse=True)
ans = 0
for i in range(min(len(yn), 100)):
    y, ny = yn[i]
    for j in range(min(len(xn), 100)):
        x, nx = xn[j]
        n = nx + ny
        if x in horizon_set[y]:
            n -= 1
        ans = max(ans, n)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter as C

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

hs, ws = [], []
hw = []

for i in range(m):
    hi, w = map(int, input().split())
    hs.append(hi)
    ws.append(w)
    hw.append([hi, w])


ch = C(hs).most_common()
cw = C(ws).most_common()
anss = []
pre_ans = -float('inf')

for num1, num2 in zip(ch, cw):
    row, cow = num1[0], num2[0]
    ans1 = hs.count(row)
    ans2 = ws.count(cow)
    ans = ans1 + ans2

    if [row, cow] in hw:
        ans -= 1

    if pre_ans > ans:
        ans = pre_ans
        break
    else:
        pre_ans = ans


print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
points = []
xs = {}
ys = {}
for i in range(m):
    x,y = map(int,input().split())
    points.append([x,y])
    if xs.get(str(x)):
        xs[str(x)] += 1
    else:
        xs[str(x)] = 1
    if ys.get(str(y)):
        ys[str(y)] += 1
    else:
        ys[str(y)] = 1
max_x = max(xs, key=xs.get)
max_y = max(ys, key=ys.get)
if [int(max_x), int(max_y)] in points:
    print(xs[max_x] + ys[max_y]-1)
else:
    print(xs[max_x] + ys[max_y])

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w,m=map(int,input().split())
hl=[0]*m
hc=[0]*h
wc=[0]*w
n=0
wl=[0]*m
for i in range(m):
    hl[i],wl[i]=list(map(int,input().split()))
w=Counter(wl)
h=Counter(hl)
ans=[0]*2
if (len(w)>1)and(len(h)>1):
    ct=2
else:
    ct=1
for i in range(ct):
    mh=h.most_common()[i][0]
    mw=w.most_common()[i][0]
    for j in range(m):
        if (hl[j]==mh)and(wl[j]==mw):
            n+=1
    ans[i]=h.most_common()[i][1]+w.most_common()[i][1]-n
print(max(ans))

Submission status: Wrong Answer

Solution code:
def E():
    h,w,m = list(map(int, input().split()))
    h_l = []
    w_l = []
    bomb = []
    for _ in range(m):
        h_t,w_t = list(map(int, input().split()))
        h_l.append(h_t)
        w_l.append(w_t)
        bomb.append(str(h_t)+":"+str(w_t))
    import collections
    c_h = collections.Counter(h_l)
    c_w = collections.Counter(w_l)
    ret = c_h.most_common()[0][1] + c_w.most_common()[0][1]
    if str(c_h.most_common()[0][0])+":"+str(c_w.most_common()[0][0]) in bomb:
        ret -= 1
    print(ret)
E()

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
H=[0 for i in range(h)]
W=[0 for i in range(w)]
s=set()
for i in range(m):
    a,b=map(int,input().split())
    H[a-1]+=1
    W[b-1]+=1
    s.add((a,b))
hma=max(H)
wma=max(W)
h_index=[x for x, v in enumerate(H) if v==hma]
w_index=[y for y, v in enumerate(W) if v==wma]
val=0
for p in h_index:
    for q in w_index:
        if (p+1,q+1) in s:
            val=-1
print(hma+wma+val)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
lis = [list(map(int, input().split())) for _ in range(m)]
bom_map = [[0]*w for _ in range(h)]

gyou = [0 for _ in range(w)]
retsu = [0 for _ in range(h)]

g_max = 0
r_max = 0
g_max_i = 0
r_max_i = 0

for i in range(m):
    retsu[lis[i][0]-1] += 1
    if retsu[lis[i][0]-1] > r_max:
        r_max = retsu[lis[i][0]-1]
        r_max_i = lis[i][0]
    gyou[lis[i][1]-1] += 1
    if gyou[lis[i][1]-1] > g_max:
        g_max = gyou[lis[i][1]-1]
        g_max_i = lis[i][1]
    bom_map[lis[i][0]-1][lis[i][1]-1] = 1
# print('a', r_max_i, g_max_i)
print(g_max + r_max - bom_map[r_max_i-1][g_max_i-1])

Submission status: Wrong Answer

Solution code:
import numpy as np


def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)

for m in ms:
    pd(f"{m=}")
    rows[m[0]] += 1
    cols[m[1]] += 1

row = np.argmax(rows)
col = np.argmax(cols)

pd(f"{row=} {col=}")
total = 0
for m in ms:
    if (m[0] == row) or (m[1] == col):
        total += 1
        pd(f"o:{m[0]=} {m[1]=}")
    else:
        pd(f"x:{m[0]=} {m[1]=}")
    

print(total)

Submission status: Wrong Answer

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

H,W,M = (int(x) for x in input().rstrip('\n').split())
ds = []
for _ in range(M):
  h,w = (int(x) for x in input().rstrip('\n').split())
  ds.append([h,w])
hs = [x[0] for x in ds]
ws = [x[1] for x in ds]
hs2 = Counter(hs)
ws2 = Counter(ws)
max_h=hs2.most_common()[0][1]
max_w=ws2.most_common()[0][1]
mh = [x for x in hs if hs.count(x)==max_h]
mw = [x for x in hs if ws.count(x)==max_w]
if any([x,y] not in ds for x in mh for y in mw):
  print(max_h+max_w)
else:
  print(max_h+max_w-1)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hx=[0]*m
wy=[0]*m
for ii in range(m):
  hx[ii],wy[ii]=map(int,input().split())

sh=set(hx)
sw=set(wy)

ch=[0]*len(sh)
cw=[0]*len(sw)
ih=[0]*len(sh)
iw=[0]*len(sw)
kk=0
for ii in sh:
  ih[kk]=ii
  for jj in range(m):
    if hx[jj]==ii:
      ch[kk]+=1
  kk+=1

kk=0
for ii in sw:
  iw[kk]=ii
  for jj in range(m):
    if wy[jj]==ii:
      cw[kk]+=1
  kk+=1
"""
print(ch)
print(cw)
"""
mh=max(ch)
mw=max(cw)
lh=[]
for ii in range(len(sh)):
  if ch[ii]==mh:
    lh.append(ih[ii])
#print(lh)
lw=[]

for ii in range(len(sw)):
  if cw[ii]==mw:
    lw.append(iw[ii])
#print(lw)
    

def func(hx,wy,lh,lw):
  """
  print(mh,mw)
  print(hx)
  print(wy)
  """
  for ii in range(m):
    if hx[ii] in lh and wy[ii] in lw :
      return(True)
  return(False)

r=mh+mw
#print(r)
if func(hx,wy,lh,lw):
  r-=1
print(r)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict

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

ctr_h = defaultdict(int)
ctr_w = defaultdict(int)

for h, w in X:
    ctr_h[h] += 1
    ctr_w[w] += 1

val_h = sorted(ctr_h.items(), key=lambda x: -x[1])
val_w = sorted(ctr_w.items(), key=lambda x: -x[1])

val_h = [v for v in val_h if v[1] > 1]
val_w = [v for v in val_w if v[1] > 1]

max_h = val_h[0][1] if val_h else 1
max_w = val_w[0][1] if val_w else 1
cand = set()
for h, c_h in val_h:
    for w, c_w in val_w:
        if c_h == max_h and c_w == max_w:
            cand.add((h, w))

res = max_h + max_w
flag = True
for h, w in X:
    flag &= (h, w) not in cand

if flag:
    print(res)
else:
    print(res - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W,M = list(map(int,input().split()))

if M == 1:
    print(1)
    exit()

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

ans = 2
flg = False
for count_H in counterH.most_common():
    for count_W in counterW.most_common():
        # print(count_H,count_W)
        if (count_H[0],count_W[0]) in targets:
            ans = max(ans,count_H[1]+count_W[1]-1)
            # print(count_H[1]+count_W[1]-1)
        else:
            ans = max(ans,count_H[1]+count_W[1])
            flg = True
            # print(count_H[1]+count_W[1])
        if flg:
            break
    if flg:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W, M = [int(x) for x in input().split()]
    HW = [[int(x) for x in input().split()] for _ in range(M)]

    x = set()

    hc = collections.Counter()
    wc = collections.Counter()

    for h, w in HW:
        hc[h] += 1
        wc[w] += 1
        x.add((h, w))

    ans = 0
    hcma = hc.most_common()[0][1]
    wcma = wc.most_common()[0][1]
    cnta = 0
    for a in hc.most_common():
        cnta += 1
        if cnta >= 1000:
            break
        if a[1] != hcma:
            break
        cnt = 0
        for b in wc.most_common():
            cnt += 1
            if cnt >= 1000:
                break
            if b[1] != wcma:
                break
            if (a[0], b[0]) in x:
                ans = max(ans, hcma + wcma - 1)
            else:
                ans = max(ans, hcma + wcma)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
inpl = lambda: list(map(int,input().split()))
H, W, M = inpl()
Shw = set()
Sh = []
Sw = []
for _ in range(M):
    h, w = inpl()
    h -= 1
    w -= 1
    Sh.append(h)
    Sw.append(w)
    Shw.add((h,w))

Gh = Counter(Sh).most_common()[0]
Gw = Counter(Sw).most_common()[0]

ans = Gh[1] + Gw[1] - int((Gh[0],Gw[0]) in Shw)
print(ans)

Submission status: Wrong Answer

Solution code:
hmw = input()
hmw_l = hmw.split()
h = int(hmw_l[0])
w = int(hmw_l[1])
m = int(hmw_l[2])
hw = []
h_l = []
w_l = []
hc =[]
wc =[]
for i in range(m):
  hwi=input()
  hw.append(hwi)
  hwi_l = hwi.split()
  h_l.append(int(hwi_l[0]))
  w_l.append(int(hwi_l[1]))
for x in range(1,h+1):
  hc.append(h_l.count(x))
for y in range(1,w+1):
  wc.append(w_l.count(y))
mhc = max(hc)
mwc = max(wc)
k = str(hc.index(mhc)+1) + " " + str(wc.index(mwc)+1)
if mhc+mwc == h +1:
  print(mhc+mwc)
elif mhc+mwc == w +1:
  print(mhc+mwc)
elif k in hw:
  print(mhc+mwc-1)
else:
  print(mhc+mwc)

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w,m = map(int,input().split())
lir = []
lic = []
ans = 0
for _ in range(m):
    x,y = map(int,input().split())
    lir.append(x)
    lic.append(y)
maxr = Counter(lir).most_common()[0][0]
for i in range(m):
    if lir[i] == maxr:
        ans+=1
        lir[i] = -1
        lic[i] = -1
maxc = Counter(lic).most_common()[0][0]
for i in range(m):
    if lic[i] == maxc:
        ans+=1
        lir[i] = -1
        lic[i] = -1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(list)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].append(col)

max_row = max(row_dict.items(), key=lambda x: x[1])
max_col = max(col_dict.items(), key=lambda x: x[1])
ans = max_row[1] + max_col[1]
if max_col[0] in row_col_dict[max_row[0]]:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = 1
if m >= 2:ans = 2
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

for turn in range(400):
    i,j = random.randint(0,h-1),random.randint(0,w-1)
    ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m  = list(map(int, input().strip().split()))
grid = []
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
H=[0]*h
W=[0]*w
for i in range(h):
    for j in range(m):
        if grid[j][0]==i+1:
            H[i]+=1
for i in range(h):
    for j in range(m):
        if grid[j][1]==i+1:
            W[i]+=1
kosuu= []
for i in range(h):
    for j in range(w):
        kosuu.append(H[i]+W[j]-1)

print(max(kosuu))

Submission status: Wrong Answer

Solution code:
h, w, m = map(int,input().split())
dic_h = dict()
dic_w = dict()
max_h = [0, 0]
max_w = [0, 0]
c = dict()
for _ in range(m):
    x, y = map(int,input().split())
    c[(x, y)] = 1
    
    if dic_h.get(x):
        dic_h[x] += 1
        if dic_h[x] > max_h[0]:max_h = [dic_h[x], x]
        elif dic_h[x] == max_h[0]:max_h.append(x)
    else:
        dic_h[x] = 1
        if max_h[0] == 0:max_h = [1, x]
    
    if dic_w.get(y):
        dic_w[y] += 1
        if dic_w[y] > max_w[0]:max_w = [dic_w[y], y]
        elif dic_w[y] == max_w[0]:max_w.append(y)
    else:
        dic_w[y] = 1
        if max_w[0] == 0:max_w = [1, y]
        
res = max_h[0] + max_w[0] - 1
#print(max_h, max_w)
for i in range(len(max_h) - 1):
    for j in range(len(max_w) - 1):
        temp = (max_h[i + 1], max_w[j + 1])
        if c.get(temp):continue
        res += 1
        print(res)
        exit()
print(res)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
# H, W, M = (3*10**5, 3*10**5, 3*10**5)

row = [0]*(H+1)
row_set = [set() for _ in range(H+1)]
column = [0]*(W+1)
column_set = [set() for _ in range(W+1)]
for m in range(M):
    h, w = map(int, input().split())
    # import random
    # h, w = (random.randrange(3*10**5), random.randrange(3*10**5))
    row[h] += 1
    row_set[h].add(w)
    column[w] += 1
    column_set[w].add(h)

maxR = max(row)
rowIndex = set([i for i, v in enumerate(row) if v == maxR])

flatten_max_rows = set()
for max_r_index in rowIndex:
    flatten_max_rows = flatten_max_rows | row_set[max_r_index]


maxC = max(column)
columnIndex = set([i for i, v in enumerate(column) if v == maxC])

for max_c in columnIndex:
    if max_c not in flatten_max_rows:
        print(max(row) + max(column))
        exit()


print(max(row) + max(column) - 1)

Submission status: Wrong Answer

Solution code:
import time
t = time.time()
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    for j in wkouho:
        if j not in c[i]:
            print(mh+mw)
            exit()
        if time.time()-t > 2.7:
            print(mh+mw-1)
            exit()
print(mh+mw-1)

Submission status: Wrong Answer

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

    row_dict = {}
    col_dict = {}
    maps = []

    try:
        while True:
            row, col = map(int, input().split())
            maps.append((row, col))

            if row_dict.get(row):
                row_dict[row] += 1
            else:
                row_dict[row] = 1

            if col_dict.get(col):
                col_dict[col] += 1
            else:
                col_dict[col] = 1
    except EOFError:
        total = row_dict[max(row_dict)]
        total += col_dict[max(col_dict)]

        if (max(row_dict), max(col_dict)) in maps:
            total -= 1

        print(total)


def main():
    probE()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


	
	

	

def main():
	h,w,m=mi()

	row=defaultdict(int)
	col=defaultdict(int)

	d=defaultdict(int)
	for _ in range(m):
		x,y=mi()
		d[(x,y)]=1
		row[x]+=1
		col[y]+=1


	r_max=max(row.values())
	c_max=max(col.values())
	r_val=0
	c_val=0
	
	for i in row:
		if row[i]==r_max:
			r_val=i
			break

	for j in col:
		if col[j]==c_max:
			c_val=j
			break



	#print(r_val,c_val)
	max_val=-1

	for i in range(1,w+1):
		if d[(r_val,i)]==1:
			if row[r_val]+col[i]-1>max_val:
				max_val=row[r_val]+col[i]-1
		elif row[r_val]+col[i]>max_val:
			max_val=row[r_val]+col[i]



	
	for i in range(1,h+1):
		if d[(i,c_val)]==1:
			if col[c_val]+row[i]-1>max_val:
				max_val=col[c_val]+row[i]-1
		elif col[c_val]+row[i]-1>max_val:
			
			max_val=col[c_val]+row[i]-1





		if col[c_val]+row[i]-1>max_val:
			max_val=col[c_val]+row[i]-1



	print(max_val)

	


	
	
	
		







	












	
	
	





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
# H, W, M = map(int, input().split())
H, W, M = (3*10**5, 3*10**5, 3*10**5)

row = [0]*(H+1)
row_set = [set() for _ in range(H+1)]
column = [0]*(W+1)
column_set = [set() for _ in range(W+1)]
for m in range(M):
    # h, w = map(int, input().split())
    import random
    h, w = (random.randrange(3*10**5), random.randrange(3*10**5))
    row[h] += 1
    row_set[h].add(w)
    column[w] += 1
    column_set[w].add(h)

maxR = max(row)
rowIndex = set([i for i, v in enumerate(row) if v == maxR])

flatten_max_rows = set()
for max_r_index in rowIndex:
    flatten_max_rows = flatten_max_rows | row_set[max_r_index]


maxC = max(column)
columnIndex = set([i for i, v in enumerate(column) if v == maxC])

for max_c in columnIndex:
    if max_c not in flatten_max_rows:
        print(max(row) + max(column))
        exit()


print(max(row) + max(column) - 1)

Submission status: Wrong Answer

Solution code:
from itertools import product
H,W,M = map(int,input().split())
h_list = [0] * M
w_list = [0] * M
for m in range(M):
    h_list[m],w_list[m] = map(int,input().split())
hh_list = [0] * H
ww_list = [0] * W
for m in range(M):
    hh_list[h_list[m]-1] += 1
for m in range(M):
    ww_list[w_list[m]-1] += 1
h_max = max(hh_list)
w_max = max(ww_list)

h_ans = []
w_ans = []

for hh in range(H):
    if hh_list[hh] == h_max:
        h_ans.append(hh)
for ww in range(W):
    if ww_list[ww] == w_max:
        w_ans.append(ww)
h_ans_len = len(h_ans)
w_ans_len = len(w_ans)
hw_point = h_ans_len * w_ans_len
if h_ans_len == 1:
    if hw_point > h_max:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)
elif w_ans_len == 1:
    if hw_point > w_max:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)
else:
    if hw_point > h_max + w_max:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)

Submission status: Wrong Answer

Solution code:
from sys import exit, stdin

# import copy
from collections import deque, Counter

# import numpy as np
input = stdin.readline

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

col = Counter()
row = Counter()
D = Counter()
for i in range(M):
    h, w = map(int, input().split())
    row.update([h])
    col.update([w])
    D.update([str(h) + str(w)])

rmax = row.most_common(1)
cmax = col.most_common(1)
idx = str(rmax[0][0]) + str(cmax[0][0])
p = D[idx]

ans = rmax[0][1] + cmax[0][1] - p

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w,m = map(int,input().split())
lir = []
lic = []
ans = 0
for _ in range(m):
    x,y = map(int,input().split())
    lir.append(x)
    lic.append(y)
maxr = Counter(lir).most_common()[0][0]
for i in range(m):
    if lir[i] == maxr:
        ans+=1
        lir[i] = -1
        lic[i] = -1
maxc = Counter(lic).most_common()[0][0]
for i in range(m):
    if lic[i] == maxr:
        ans+=1
        lir[i] = -1
        lic[i] = -1
print(ans)

Submission status: Wrong Answer

Solution code:
H, W, M = list(map(int,input().split()))
Bom = []

import numpy as np

listH = np.zeros(H+1)
listW  =np.zeros(W+1) 

for _ in range(M):
    hi, wi = list(map(int,input().split()))
    listH[hi] += 1
    listW[wi] += 1
    Bom.append([hi,wi])

maxH = np.argmax(listH)
maxW = np.argmax(listW)

res = 0
for obj in Bom:
    if obj[0]==maxH or obj[1]==maxW:
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
import sys
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = [width]*H
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object[h-1][w-1] = 1
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
p = len(cand_h)*len(cand_w)
if M > p:
   for i in range(len(cand_h)):
      for j in range(len(cand_w)):
         if object[cand_h[i]][cand_w[j]] == 0:
            ans += 1
else:
   ans += 1

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
height=[0]*H
width=[0]*W
#bomb=[0]*M
bset=set()
#for k in range(M):
    #bomb[k]=[0]*2
for j in range(M):
    h,w=map(int,input().split())
    bset.add((h-1,w-1))
    #bomb[j][0]=h-1
    #bomb[j][1]=w-1
    height[h-1]+=1
    width[w-1]+=1
#print(bomb)
#print(height)
#print(width)
hmax=max(height)
wmax=max(width)
flag=0
hindex=0
windex=0
for i in range(H):
    if height[i]==hmax:
        hindex+=1
for h in range(W):
    if width[h]==wmax:
        windex+=1
kouho=hindex*windex
equalbomb=0
for p in bset:
    if height[p[0]]==hmax and width[p[1]]==wmax:
        equalbomb+=1

if kouho==equalbomb:
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split(' '))
grid = [[0 for j in range(w+1)] for i in range(h+1)]

h_max = 0
w_max = 0
h_max_grid = 0
w_max_grid = 0

for i in range(m):
    hi, wi = map(int, input().split(' '))
    grid[hi][wi] = 1
    grid[hi][0] += 1
    grid[0][wi] += 1

    if h_max < grid[hi][0]:
        h_max = grid[hi][0]
        h_max_grid = hi

    if w_max < grid[0][wi]:
        w_max = grid[0][wi]
        w_max_grid = wi

print(h_max + w_max - grid[h_max_grid][w_max_grid])

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
c={}
e={}
for i in range(k):
    a,b=map(int,input().split())
    t=str(a)+'x'
    s=str(b)+'y'
    e[t+s]=1
    if t in c:
        c[t]+=1
    else:
        c[t]=1
    if s in c:
        c[s]+=1
    else:
        c[s]=1
d=sorted(c.items(),key=lambda x:x[1],reverse=True)
p,r=d[0]
w=p
p=list(p)
m=r

if p[1]=='x':
    for i in range(len(d)):
        u,v=d[i]
        u=list(u)
        if u[1]=='y':
            m+=v
            w+=''.join(u)
            break
else:
    for i in range(len(d)):
        u, v = d[i]
        u = list(u)
        if u[1] == 'x':
            m += v
            w+=''.join(u)
            break
if w in e:
    print(m-1)
else:
    print(m)

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())

h_counter = collections.Counter(h)
w_counter = collections.Counter(w)
h_common = h_counter.most_common()[0][0]
w_common = w_counter.most_common()[0][0]

ans=0
for i in range(M):
    if h[i] == h_common or w[i] == w_common:
        ans = ans +1
if ans == 1:
    if M >= 2:
        ans = 2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

H, W, M = [int(n) for n in input().split()]
h = []
w = []
for m in range(M):
    tmp = [int(n) for n in input().split()]
    h.append(tmp[0])
    w.append(tmp[1])

h_counter = Counter(h)
w_counter = Counter(w)

hh = h_counter.most_common()[0][0]
ww = w_counter.most_common()[0][0]

c = 0
for m in range(M):
    if h[m] == hh and w[m] == ww:
        c = 1
        break

ans = h_counter.most_common()[0][1] + w_counter.most_common()[0][1] - c
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
Hlist= {}
Wlist ={}
HWlist = []
for i in range(M):
    h,w = map(int,input().split())
    if h not in Hlist:
        Hlist[h] = 1
    else:
        Hlist[h] += 1
    if w not in Wlist:
        Wlist[w] = 1
    else:
        Wlist[w] += 1
    HWlist.append([h,w])
h = max([(v,k) for k,v in Hlist.items()])[1]
w2 = max([(v,k) for k,v in Wlist.items()])
w = w2[1]
wmax = w2[0]
Dua = []
for k,v in Wlist.items():
    if v == wmax:
        Dua.append(k)
Answer = Hlist[h] + Wlist[w]
for _ in range(len(Dua)):
    if [h,Dua[_]] not in HWlist:
        break
    elif _ == len(Dua)-1:
        Answer -= 1
print(Answer)