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

ListH = [0 for i in range(H)]
ListW = [0 for i in range(W)]

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

ListH.sort(reverse=True)
ListW.sort(reverse=True)

print(ListH[0] + ListW[0])

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
row = [0]*H  # 行
column = [0]*W  # 列

target = set()
for _ in range(M):
    # h行, w列に爆破対象がある
    h, w = map(lambda x: int(x)-1, input().split())
    row[h] += 1
    column[w] += 1
    target.add((h, w))

max_row_value = max(row)
max_column_value = max(column)
max_row_idx = []
max_column_idx = []

for i in range(H):
    if row[i] == max_row_value:
        max_row_idx.append(i)
for j in range(W):
    if column[j] == max_column_value:
        max_column_idx.append(j)


for r in max_row_idx:
    for c in max_row_idx:
        if (r, c) not in target:
            print(max_row_value+max_column_value)
            exit()

print(max_row_value+max_column_value-1)

Submission status: Wrong Answer

Solution code:
import collections as cl

h, w, m = map(int, input().split())
x = list(list(map(int, input().split())) for i in range(m))

#print(h, w, m, x)

#行検索
a_lis = []
for i in range(m):
    a_lis.append(x[i][0])
#print(a_lis)
# a = max(a_lis)

#行の最大爆発個数,行数
a_cnt = cl.Counter(a_lis)
#print(a_cnt)
max_a = a_cnt.most_common()[0][1]
set_a = a_cnt.most_common()[0][0]
#print(max_a, set_a)


#列検索
b_lis = []
for i in range(m):
     b_lis.append(x[i][1])
#print(b_lis)

#列の最大爆発数
b_cnt = cl.Counter(b_lis)
#print(b_cnt)
max_b = b_cnt.most_common()[0][1]
set_b = b_cnt.most_common()[0][0]
#print(max_b, set_b)

#爆弾があるところにおいたら１を引く
frag = 0
for i in range(m):
    if x[i][0] == set_a and x[i][1] == set_b:
        frag += 1

if frag == 0:
    ans = max_a + max_b
elif frag == 1:
    ans = max_a + max_b - 1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


H,W,M = input().rstrip().split(' ')

H = int(H)
W = int(W)
M = int(M)

hcount = [0 for _ in range(H)]
wcount = [0 for _ in range(W)]

#L = [[0 for i in range(W)]for j in range(H)]
L = {}
for i in range(M):
    ij = input().rstrip().split(' ')
    i = int(ij[0])-1
    j = int(ij[1])-1
    #L[i][j] = 1
    L[(i,j)] = 1
    hcount[i] += 1
    wcount[j] += 1
 
hmax = max(hcount)
wmax = max(wcount)
count = hmax+wmax-1

hin = [i for i, x in enumerate(hcount) if x == hmax]
win = [i for i, x in enumerate(wcount) if x == wmax]

for i in hin:
    for j in win:
      if (i, j) not in L:
            count += 1
            break
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

h,w,m=map(int,input().split())
c=set()
dic_h=defaultdict(int)
dic_w=defaultdict(int)
for _ in range(m):
    h,w=map(int,input().split())
    c.add((h-1,w-1))
    dic_h[h-1]+=1
    dic_w[w-1]+=1
H,W=max(dic_h.values()),max(dic_w.values())
print(H+W)

Submission status: Wrong Answer

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

Hn = [0 for _ in range(H)]
Wn = [0 for _ in range(W)]
B_d = {}

for B in Bn:
    BH, BW = B
    Hn[BH-1] += 1
    Wn[BW-1] += 1
    key = "{0}:{1}".format(BH, BW)
    B_d[key] = True

H_max = max(Hn)
Hi_max = []
for i in range(H):
    if Hn[i] == H_max:
        Hi_max.append(i)

W_max = max(Wn)
Wi_max = []
for i in range(W):
    if Wn[i] == W_max:
        Wi_max.append(i)

if len(Hi_max) == 1:
    for i in Wi_max:
        key2 = "{0}:{1}".format(Hi_max[0]+1, i+1)
        if key2 not in B_d:
            ans = H_max + W_max
            break
    else:
        ans = H_max + W_max - 1
elif len(Wi_max) == 1:
    for i in Hi_max:
        key2 = "{0}:{1}".format(i+1, Wi_max[0]+1)
        if key2 not in B_d:
            ans = H_max + W_max
            break
    else:
        ans = H_max + W_max - 1
else:
        ans = H_max + W_max
print(ans)

Submission status: Wrong Answer

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

Hn = [0 for _ in range(H)]
Wn = [0 for _ in range(W)]

for B in Bn:
    BH, BW = B
    Hn[BH-1] += 1
    Wn[BW-1] += 1

H_max = max(Hn)
Hi_max = []
for i in range(H):
    if Hn[i] == H_max:
        Hi_max.append(i)

W_max = max(Wn)
Wi_max = []
for i in range(W):
    if Wn[i] == W_max:
        Wi_max.append(i)

if len(Hi_max) == 1:
    for i in Wi_max:
        if [Hi_max[0]+1, i+1] not in Bn:
            ans = H_max + W_max
            break
    else:
        ans = H_max + W_max -1
elif len(Wi_max) == 1:
    for i in Hi_max:
        if [i+1, Wi_max[0]+1] not in Bn:
            ans = H_max + W_max
            break
    else:
        ans = H_max + W_max -1
else:
        ans = H_max + W_max

print(ans)

Submission status: Wrong Answer

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

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


hmax=max(hs)
wmax=max(ws)
Hs=[]
Ws=[]
for h in range(H):
    if hmax==hs[h]:
        Hs.append(hs[h])

for w in range(W):
    if wmax==ws[w]:
        Ws.append(ws[w])

for h in Hs:
    for w in Ws:
        if D[h,w]==0:
            print(h+w)
            exit()

print(hmax+wmax-1)

Submission status: Wrong Answer

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

hs=defaultdict(int)
ws=defaultdict(int)
D=defaultdict(int)
for i in range(M):
    h,w=map(int, input().split())
    hs[h-1]+=1
    ws[w-1]+=1
    D[(h-1,w-1)]+=1


hmax=max(hs.values())
wmax=max(ws.values())

for h in hs.values():
    for w in ws.values():
        if h==hmax and w==wmax and D[h,w]==0:
            print(h+w)
            exit()

print(hmax+wmax-1)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
R = {}
C = {}
RC = []
for i in range(M):
  h,w = map(int,input().split())
  RC.append([h,w])
  if h in R:
    R[h] += 1
  else:
    R[h] = 1
  if w in C:
    C[w] += 1
  else:
    C[w] = 1
MaxR = max(R.values())
rlist = [k for k, v in R.items() if v == MaxR]
MaxC = max(C.values())
clist = [k for k, v in C.items() if v == MaxC]
for i in rlist:
  for j in clist:
    if [i,j] not in RC:
      print(MaxR+MaxC)
      break
  else:
    print(MaxR+MaxC-1)
    break

Submission status: Wrong Answer

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

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


hmax=max(hs)
wmax=max(ws)

for h in hs:
    for w in ws:
        if h==hmax and w==wmax and D[h,w]==0:
            print(h+w)
            exit()

print(hmax+wmax-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
s=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    s.add((hr-1)*w+wr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
if resu==m or resl==m :
  print(m)
  exit()
if len(cu)*len(cl)>=m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i*w+j in s:
                res=resl+resu-1
            else:
                res=resl+resu
            ans=max(res,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
s=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    s.add((hr-1)*w+wr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
if resu==m or resl==m:
  print(m)
  exit()
if len(cu)*len(cl)>=m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i*w+j in s:
                res=l[j]+u[i]-1
            else:
                res=l[j]+u[i]
            ans=max(res,ans)
print(ans)

Submission status: Wrong Answer

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

hBom = [0]*H
wBom = [0]*W

# 各行、各列の爆破対象をカウント
for h, w in boms:
    hBom[h-1] += 1
    wBom[w-1] += 1

# 爆破対象の最大数と最大になる行と列の番号を調べる
maxHBom = max(hBom)
maxWBom = max(wBom)
maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom]
maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom]

# 爆破対象が最大になる行と列の組み合わせについて、
# 爆弾を配置する場所が爆破対象であるかないかで場合分け
boms = set(boms)
for h in maxHBomIndex:
    for w in maxWBomIndex:
        if (h+1, w+1) not in boms:
            print(maxHBom + maxWBom)
            exit()
else:
    print(maxHBom + maxWBom - 1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
s=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    s.add((hr-1)*w+wr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
if len(cl)==1 or len(cu)==1:
  print(m)
  exit()
if len(cu)*len(cl)>=m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i*w+j in s:
                res=l[j]+u[i]-1
            else:
                res=l[j]+u[i]
            ans=max(res,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
s=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    s.add((hr-1)*w+wr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0

if len(cu)*len(cl)>=m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i*w+j in s:
                res=l[j]+u[i]-1
            else:
                res=l[j]+u[i]
            ans=max(res,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
sl=set()
su=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    sl.add(wr-1)
    su.add(hr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
if len(cu)*len(cl)>=m:
    ans=resl+resu-1
else:
    for i in cu:
        for j in cl:
            if i in su and j in sl:
                res=l[j]+u[i]-1
            else:
                res=l[i]+u[j]
            ans=max(res,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
sl=set()
su=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    sl.add(wr-1)
    su.add(hr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
if len(cu)*len(cl)>=m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i in su and j in sl:
                res=l[j]+u[i]-1
            else:
                res=l[i]+u[j]
            ans=max(res,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if (i,j) not in cnt:
      print(hcnt+wcnt)
      exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

H = [0] * h
W = [0] * w
for x,y in t:
    H[x-1] += 1
    W[y-1] += 1
H_max = max(H)
W_max = max(W)

H_index = [h for h,i in enumerate(H) if i == H_max]
W_index = [w for w,j in enumerate(W) if j == W_max]

ans = H_max + W_max

for r in H_index:
    for c in W_index:
        if (r, c) not in t:
            print(ans)
            exit()
print(ans - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W, M = list(map(int, input().split()))
h = [None]*M
w = [None]*M
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))

hc = Counter(h)
wc = Counter(w)

x, ctx = hc.most_common(1)[0]
y, cty = wc.most_common(1)[0]
# print(x,y)
for i in range(M):
    if h[i] == x and w[i] == y:
        print(ctx+cty-1)
        break
else:
    print(ctx+cty)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1

  

hcnt,wcnt=max(hlist),max(wlist)

hh,ww=[],[]
hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,w+1):
  if wlist[i]==wcnt:
    ww+=[i]

for i in hh:
  for j in ww:
    if i not in hhh:
      if j not in www:
        print(hcnt+wcnt)
        exit()
  
print(hcnt+wcnt-1)

Submission status: Wrong Answer

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

H_bom = [0 for i in range(H)]
W_bom = [0 for i in range(W)]
bom_map = [[0 for i in range(W)] for i in range(H)]

for i in range(M):
    M_temp = list(map(int, input().split()))
    H_bom[M_temp[0]-1] += 1
    W_bom[M_temp[1]-1] += 1
    bom_map[M_temp[0]-1][M_temp[1]-1] = 1

#print(bom_map)
H_bom_max = max(H_bom)
W_bom_max = max(W_bom)
H_bom_line = []
W_bom_line = []

for i in range(H):
    if H_bom[i] == H_bom_max:
        H_bom_line.append(i)
for i in range(W):
    if W_bom[i] == W_bom_max:
        W_bom_line.append(i)
#print(H_bom_max, H, H_bom_line, W_bom_max, W, W_bom_line)
bom_check_flag = 0

if len(H_bom_line) > W - W_bom_max and len(H_bom_line) != H:
    bom_check_flag = 1
if len(W_bom_line) > H - H_bom_max and len(W_bom_line) != W:
    bom_check_flag = 1
if bom_check_flag == 1:
    print(H_bom_max + W_bom_max -1)
else:
    print(H_bom_max + W_bom_max)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int, input().split())
hh=[]
ww=[]
b=set()
for _ in range(m):
    hi,wi=map(int, input().split())
    hh.append(hi)
    ww.append(wi)
    b.add((hi,wi))
from collections import Counter

hc=Counter(hh)
wc=Counter(ww)

hmx=0;hnow=-1
wmx=0;wnow=-1
hs=[];ws=[]
for hi in hc:
    if hc[hi]>hmx:
        hmx=hc[hi]
        hnow=hi
        hs=[hi]
    elif hc[hi]>hmx:
        hs.append(hi)
for wi in wc:
    if wc[wi]>wmx:
        wmx=wc[wi]
        wnow=wi
        ws=[wi]
    elif wc[wi]>wmx:
        ws.append(wi)

ans=hmx+wmx
flag=False
for hi in hs:
    for wi in ws:
        if (hi,wi) not in b:
            flag=True
            break
    if flag:break
if not flag:
    ans-=1

ans2=0

for hi,wi in b:
    ans2=max(ans2,hc[hi]+wc[wi]-1)
print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
dpcol = [0]*w
dprow = [0]*h
ypos = []
xpos = []
hw = [list(map(lambda x: int(x) - 1, input().split())) for i in range(m)]

for i, j in hw:
    dpcol[j] += 1
    dprow[i] += 1

maxcol = max(dpcol)
maxrow = max(dprow)

for i in range(w): #列の最大値
    if dpcol[i] == maxcol:
        xpos.append(i)

for i in range(h):
    if dprow[i] == maxrow:
        ypos.append(i)

ans = maxcol + maxrow - 1

for i in ypos:
    for j in xpos:
        if [i, j] not in hw:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int, input().split())
hh=[]
ww=[]
b=set()
for _ in range(m):
    hi,wi=map(int, input().split())
    hh.append(hi)
    ww.append(wi)
    b.add((hi,wi))
from collections import Counter

hc=Counter(hh)
wc=Counter(ww)

hmx=0;hnow=-1
wmx=0;wnow=-1

for hi in hc:
    if hc[hi]>hmx:
        hmx=hc[hi]
        hnow=hi
for wi in wc:
    if wc[wi]>wmx:
        wmx=wc[wi]
        wnow=wi
ans=hmx+wmx
if (hnow,wnow) in b:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

h, w, m = (int(each) for each in input().split())

bombs = []
for each in range(m):
    bombs.append(tuple(int(each) for each in input().split()))

hbombs = [each[0] for each in bombs]
wbombs = [each[1] for each in bombs]

# h方向で行番号と対象の数のタプル
hbombs_cnt = collections.Counter(hbombs).most_common()
wbombs_cnt = collections.Counter(wbombs).most_common()

hbombs_max = hbombs_cnt[0][1]
wbombs_max = wbombs_cnt[0][1]

# h方向で一番多い行番号と対象の数のタプル
hbombs_most_common = [each for each in hbombs_cnt if each[1] == hbombs_max]
wbombs_most_common = [each for each in wbombs_cnt if each[1] == wbombs_max]

# print(hbombs_most_common)
# print(wbombs_most_common)

result = hbombs_max + wbombs_max

pos = [0]

# 爆破位置に爆弾があるか
for _h in hbombs_most_common:
    for _w in wbombs_most_common:
        # print(_h[0], _w[0])
        if (_h[0], _w[0]) in bombs:
            pos.append(1)
# print(pos)
print(result- max(pos))

Submission status: Wrong Answer

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

h, w, m = inpm()
rl = []
cl = []
for i in range(0, w):
    cl.append(0)
for i in range(0, h):
    rl.append(0)
maxr = 0
maxc = 0
l = {}
ans = 0
ri = 0
ci = 0

for i in range(0, m):
    a , b = inpm()
    l[(a- 1, b- 1)] = 1

for t in l:
    a = t[0]
    b = t[1]
    rl[a] += 1
    cl[b] += 1
    if(maxr < rl[a]):
        maxr = rl[a]
        ri = a 
    if(maxc < cl[b]):
        maxc = cl[b]
        ci = b 
    if(l.get((ri, ci)) == 1):
        ans = max(ans, maxr + maxc - 1)
    else:
        ans = max(ans, maxr + maxc)
    
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
dpcol = [0]*w
dprow = [0]*h
ypos = []
xpos = []
hw = [list(map(lambda x: int(x) - 1, input().split())) for i in range(m)]

for i, j in hw:
    dpcol[j] += 1
    dprow[i] += 1

maxcol = max(dpcol)
maxrow = max(dprow)

for i in range(w): #列の最大値
    if dpcol[i] == maxcol:
        xpos.append(i)

for i in range(h):
    if dprow[i] == maxrow:
        ypos.append(i)

ans = maxcol + maxrow - 1

for i in ypos:
    for j in xpos:
        if [i, j] not in hw:
            ans += 1
            exit()
            
print(ans)

Submission status: Wrong Answer

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

H_bom = [0 for i in range(H)]
W_bom = [0 for i in range(W)]
bom_map = [[0 for i in range(W)] for i in range(H)]

for i in range(M):
    M_temp = list(map(int, input().split()))
    H_bom[M_temp[0]-1] += 1
    W_bom[M_temp[1]-1] += 1
    bom_map[M_temp[0]-1][M_temp[1]-1] = 1

#print(bom_map)
H_bom_max = max(H_bom)
W_bom_max = max(W_bom)
H_bom_line = []
W_bom_line = []

for i in range(H):
    if H_bom[i] == H_bom_max:
        H_bom_line.append(i)
for i in range(W):
    if W_bom[i] == W_bom_max:
        W_bom_line.append(i)
#print(H_bom_max, H_bom_line, W_bom_max, W_bom_line)
bom_check_flag = 0

for i in H_bom_line:
    for j in W_bom_line:
        if bom_map[i][j] == 0:
            print(H_bom_max + W_bom_max)
            bom_check_flag = 1
            break
if bom_check_flag == 0:
    print(H_bom_max + W_bom_max -1)

Submission status: Wrong Answer

Solution code:
import collections

h, w, m = (int(each) for each in input().split())

bombs = []
for each in range(m):
    bombs.append(tuple(int(each) for each in input().split()))

hbombs = [each[0] for each in bombs]
wbombs = [each[1] for each in bombs]

# h方向で行番号と対象の数のタプル
hbombs_cnt = collections.Counter(hbombs).most_common()
wbombs_cnt = collections.Counter(wbombs).most_common()

hbombs_max = hbombs_cnt[0][1]
wbombs_max = wbombs_cnt[0][1]

# h方向で一番多い行番号と対象の数のタプル
hbombs_most_common = [each for each in hbombs_cnt if each[1] == hbombs_max]
wbombs_most_common = [each for each in wbombs_cnt if each[1] == wbombs_max]

# print(hbombs_most_common)
# print(wbombs_most_common)

result = hbombs_max + wbombs_max

flg = False

for _h in hbombs_most_common:
    for _w in wbombs_most_common:
        if (_h[0], _w[0]) in bombs:
            flg = True

print(result- int(flg))

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()
for _ in range(m):
    c_h, c_w = map(int, input().split())
    h_cnt[c_h-1] +=1
    w_cnt[c_w-1]+=1
    bomb.add(((c_h-1),(c_w-1)))

ans = []
for i in bomb:
    if h_cnt[i[0]] == 1 and w_cnt[i[1]] ==1:
        ans.append(h_cnt[i[0]] + w_cnt[i[1]] -1)
    else:
        ans.append(h_cnt[i[0]] + w_cnt[i[1]])

print(max(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W, M = map(int, input().split())
h_list = []
w_list = []
bomber = []
for _ in range(M):
    h, w = map(int, input().split())
    h_list.append(h)
    w_list.append(w)
    bomber.append([h, w])
h_cnt = Counter(h_list)
w_cnt = Counter(w_list)
h_max = max(h_cnt.values())
w_max = max(w_cnt.values())
h_max_list = []
w_max_list = []
for h_key, h_value in h_cnt.items():
    if h_value == h_max:
        h_max_list.append(h_key)
for w_key, w_value in w_cnt.items():
    if w_value == w_max:
        w_max_list.append(w_key)
tmp = -1
for h_index in h_max_list:
    for w_index in w_max_list:
        if [h_index, w_index] in bomber:
            tmp = 0
            break
print(h_max + w_max + tmp)

Submission status: Wrong Answer

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

H_bom = [0 for i in range(H)]
W_bom = [0 for i in range(W)]
bom_map = [[0 for i in range(W)] for i in range(H)]

for i in range(M):
    M_temp = list(map(int, input().split()))
    H_bom[M_temp[0]-1] += 1
    W_bom[M_temp[1]-1] += 1
    bom_map[M_temp[0]-1][M_temp[1]-1] = 1

#print(H_bom, W_bom)
H_bom_max = max(H_bom)
W_bom_max = max(W_bom)
H_bom_line = []
W_bom_line = []

for i in range(H):
    if H_bom[i] == H_bom_max:
        H_bom_line.append(i)
for i in range(W):
    if W_bom[i] == W_bom_max:
        W_bom_line.append(i)

bom_check_flag = 0

for i in H_bom_line:
    for j in W_bom_line:
        if bom_map[i-1][j-1] == 1:
            print(H_bom_max + W_bom_max)
            bom_check_flag = 1
            break
if bom_check_flag == 0:
    print(H_bom_max + W_bom_max -1)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
 
HB = [0] * H
WB = [0] * W
 
place = []
 
for i in range(M):
    h, w = map(int, input().split())
    place.append((h, w,))
 
    HB[h - 1] += 1
    WB[w - 1] += 1
 
HBC = [i for i, x in enumerate(HB) if x == max(HB)]
WBC = [i for i, x in enumerate(WB) if x == max(WB)]
result = max(HB) + max(WB)

place_x = []
place_y = []
 
for x, y in place:
    if x in HBC:
        place_x.append(x)
    if y in WBC:
        place_y.append(y)


 
if len(HBC) == len(place_x) and len(WBC) == len(place_y):
    result -= 1
 
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w, m = map(int, input().split())

Submission status: Wrong Answer

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

M_map = [[0 for i in range(W)] for j in range(H)]

for i in range(M):
    M_temp = list(map(int, input().split()))
    M_map[M_temp[0]-1][M_temp[1]-1] = 1
#print(M_map)

max_R_line = []
max_C_line = []
R_sum_max = 0
R_check = 1
C_sum_max = 0

for i in range(W):
    C_sum = 0
    for j in range(H):
        C_sum += M_map[j][i]
        if R_check == 1:
            if R_sum_max <= sum(M_map[j]):
                if R_sum_max < sum(M_map[j]):
                    max_R_line.clear()
                    max_R_line.append(j)
                else:
                    max_R_line.append(j)
                R_sum_max = sum(M_map[j])
    R_check = 0
    if C_sum_max <= C_sum:
        if C_sum_max < C_sum:
            max_C_line.clear()
            max_C_line.append(i)
        else:
            max_C_line.append(i)
        C_sum_max = C_sum
#print(max_C_line, C_sum_max, max_R_line, R_sum_max)

for i in max_R_line:
    for j in max_C_line:
        if M_map[i][j] == 0:
            print(C_sum_max + R_sum_max)
            break
    if i == max(max_R_line) and j == max(max_C_line):
        print(C_sum_max + R_sum_max -1)

Submission status: Wrong Answer

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

h_idx = h.index(max(h))
ans = max(h)

for j in range(W):
  if (h_idx + 1, j) in Mem:
    tmp = max(h) + w[j] -1
  else:
    tmp = max(h) + w[j]
  ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import mode
H,W,M = map (int, input ().split ())
p = 0
X = []
Y = []
Z = []
for i in range (M):
  x,y = map (int ,input ().split ())
  X.append (x)
  Y.append (y)
  Z.append (x*10+y)
x = mode(X)
y = mode(Y)
p += X.count (x)
p += Y.count (y)
print (p-Z.count (x*10+y))