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: Runtime Error

Solution code:

import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

H, W, M = nn()
T = nm(M)

for i in range(M):
    T[i] = ldec(T[i])

dh = array2(H, 0, [])
dw = array2(W, 0, [])

for i in range(M):
    dh[T[i][0]].append(T[i])
    dw[T[i][1]].append(T[i])

def lenmax(A):
    m = 0
    for i in range(len(A)):
        if m < len(A[i]):
            m = len(A[i])

    ret = []
    for i in range(len(A)):
        if len(A[i]) == m:
            #print(m, A[i])
            ret.append(A[i])

    return m, ret

x, dhlist = lenmax(dh)
y, dwlist = lenmax(dw)
ans = x + y

def judge(a, L):
    for i in range(len(L)):
        for j in range(len(L[i])):
            if a == L[i][j]:
                return True
    return False

for i in range(len(dhlist)):
    for j in range(len(dwlist)):
        if [dhlist[i][0][0], dwlist[j][0][1]] not in T:
            print(ans)
            exit(0)

print(ans-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

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

rows, columns = [0]*H, [0]*W
for h, w in hw:
    rows[h-1] += 1
    columns[w-1] += 1
max_r, max_c = max(rows), max(columns)

argmax_r, argmax_c = [], []
for i in range(H):
    if max_r == rows[i]:
        argmax_r.append(i)

for i in range(W):
    if max_c == columns[i]:
        argmax_c.append(i)

for r in argmax_r:
    for c in argmax_c:
        idx = bisect.bisect_left(hw, [r+1, c+1])
        if hw[idx] != [r+1,c+1]:
            print(max_r + max_c)
            exit()

print(max_r + max_c - 1)

Submission status: Runtime Error

Solution code:
r,c,m=map(int,input().split())
cols=[0]*c
rows=[0]*r
for i in range(m):
  a,b=map(int,input().split())
  rows[a]+=1
  cols[b]+=1
print(max(rows)+max(cols))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import deque

H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))

ch -= 1
cw -= 1
dh -= 1
dw -= 1

S = [list((str(input()))) for i in range(H)]


def check(h, w):
    if h < 0 or h >= H:
        return False
    if w < 0 or w >= W:
        return False
    if S[h][w] == "#":
        return False
    return True


def main():

    map_ = [[10**10]*W for i in range(H)]
    # map_[ch][cw] = 0

    dq = deque([[ch, cw, 0]])

    while(len(dq) > 0):
        # print(dq)
        h, w, value = dq.popleft()
        map_value = map_[h][w]
        if map_value <= value:
            continue
        map_[h][w] = value

        for i in [-2, -1, 0, 1, 2]:
            for j in [-2, -1, 0, 1, 2]:
                if i == 0 and j == 0:
                    continue
                if abs(i)+abs(j) == 1:
                    if check(h+i, w+j):
                        # print(h+i, w+)
                        if map_[h+i][w+j] > value:
                            dq.appendleft([h+i, w+j, value])
                else:
                    if check(h+i, w+j):
                        if map_[h+i][w+j] > value+1:
                            dq.append([h+i, w+j, value+1])
    # for i in map_:
        # print(i)
    ans = map_[dh][dw]
    if ans == 10**10:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H,W,M=map(int,readline().split())
bomb=[[0 for j in range(2)] for i in range(M)]
h=[0]*M
w=[0]*M
for i in range(M):
    x,y=map(lambda x: int(x) - 1, readline().split())
    bomb[i]=x,y
    h[x]+=1
    w[y]+=1
maxh=max(h)
maxw=max(w)
R=[h for h, x in enumerate(h) if x == maxh] 
C = [w for w, y in enumerate(w) if y == maxw]
for r in R:
    for c in C:
        if (r, c) not in bomb:
            print(maxh + maxw)
            exit()
print(maxh + maxw - 1)

Submission status: Runtime Error

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

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = []
for col in range(W):
    colcnt.append(sum(row[col] for row in mat))

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

Submission status: Runtime Error

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

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = [sum(row[col] for row in mat) for col in range(W)]

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

Submission status: Runtime Error

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

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = [sum(row[col] for row in mat) for col in range(W)]

rowmax, colmax = max(rowcnt), max(colcnt)
for r, mat_h in zip(rowcnt, mat):
    for c, mat_hw in zip(colcnt, mat_h):
        if r == rowmax and c == colmax and mat_hw == 0:
            print(rowmax + colmax)
            exit()
print(rowmax + colmax - 1)

Submission status: Runtime Error

Solution code:
W=np.zeros(w)
for i in range(m):
    hi,wi=hw[i]
    H[hi-1]+=1
    W[wi-1]+=1
hmax=[i for i, x in enumerate(H) if x == max(H)]
wmax=[i for i, x in enumerate(W) if x == max(W)]
ans=0
mh=max(H)
mw=max(W)
for hi in hmax:
    for wi in wmax:
        if not ([hi+1,wi+1] in hw):
            ans=mh+mw
            print(int(ans))
            exit()
ans=mh+mw-1
print(int(ans))

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
s = []
bb = [[0] * (w + 1) for _ in range(h + 1)]
r = [0] * (h + 1)
c = [0] * (w + 1)
for i in range(m):
    bh, bw = map(int, input().split())
    s.append([bh, bw])
    bb[bh][bw] = 1
    r[bh] += 1
    c[bw] += 1
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = sum(x in nr and y in nc for x, y in s)
print(R + C - (len(nr) * len(nc) == count))

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [[0,0] for _ in range(m)]
for i in range(m):
    h,w = map(int,input().split())
    h_ls[h-1] += 1
    w_ls[w-1] += 1
    bombers[i] = [h-1,w-1]

h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
    if h_ls[i] == h_max:
        h_max_args[next_ind] = i
        next_ind += 1

w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
    if w_ls[i] == w_max:
        w_max_args[next_ind] = i
        next_ind += 1

bombers = set(bombers)
for h in h_max_args:
    for w in w_max_args:
        if not [h,w] in bombers:
            print(w_max+h_max)
            sys.exit()

print(w_max+h_max-1)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools
 
# input
H, W, M = map(int, input().split()) # H * Mのマス目, M個のターゲット
A = np.zeros(H * W)
A = A.reshape(H, W)
for _ in range(M):
    i, j = map(int, input().split())
    A[i - 1][j - 1] = 1
 
# print(A, "\n")
 
# output
a = np.sum(A, axis=0)
b = np.sum(A, axis=1)
 
a_max, b_max = map(int, (a.max(), b.max()))
a_i_list = np.where(a == a_max)
b_i_list = np.where(b == b_max)
 
# print(a, b)
# print(a_i_list, b_i_list)
 
flg = False
for a_i, b_i in itertools.product(a_i_list[0], b_i_list[0]):
    if A[a_i][b_i] == 0:
        flg = True
        break
        
if flg:
    print(a_max + b_max)
else:
    print(a_max + b_max - 1)

Submission status: Runtime Error

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * (H * W)
w = [0] * (H * W)
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

ans = max(h) + max(w)
d =[h.index(max(h)), w.index(max(w))]
if d in item_list:
    ans -= 1


print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  h, w, m = map(int, input().strip().split())
  fieldh = numpy.zeros(h, dtype=numpy.int)
  fieldw = numpy.zeros(w, dtype=numpy.int)
  field = numpy.zeros((h, w), dtype=numpy.int)
  for _ in range(m):
    ih, iw = map(int, input().strip().split())
    fieldh[ih-1] += 1
    fieldw[iw-1] += 1
    field[ih-1, iw-1] = 1
    
  max_h = numpy.max(fieldh)
  max_w = numpy.max(fieldw)
  argsort_h = [ ih for ih in range(h) if fieldh[ih] == max_h ]
  argsort_w = [ iw for iw in range(w) if fieldw[iw] == max_w ]
  
  max_cnt = 0
  for ih in argsort_h:
    for iw in argsort_w:
      if field[ih, iw] == 0:
        max_cnt = max(max_cnt, fieldh[ih]+fieldw[iw])
        print(max_cnt)
        return 
      else:
        max_cnt = max(max_cnt, fieldh[ih]+fieldw[iw]-1)
  print(max_cnt)

if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    # 座標だけはsetで格納
    bomb_pos = set()
    # 爆弾情報を行と列ごとで格納
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split())]
        bomb_col[r] += 1
        bomb_row[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(col) if v == bomb_col_max]
    col_index = [i for i, v in enumerate(row) if v == bomb_row_max]
    ans = max(col) + max(row)
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  h, w, m = map(int, input().strip().split())
  fieldh = numpy.zeros(h, dtype=numpy.int)
  fieldw = numpy.zeros(w, dtype=numpy.int)
  field = numpy.zeros((h, w), dtype=numpy.int)
  for _ in range(m):
    ih, iw = map(int, input().strip().split())
    fieldh[ih-1] += 1
    fieldw[iw-1] += 1
    field[ih-1, iw-1] = 1
  max_h = numpy.max(fieldh)
  max_w = numpy.max(fieldw)
  argsort_h = fieldh.argsort()[::-1]
  argsort_w = fieldw.argsort()[::-1]
  
  max_cnt = 0
  for ih in argsort_h:
    for iw in argsort_w:
      if field[ih, iw] == 0:
        max_cnt = max(max_cnt, fieldh[ih]+fieldw[iw])
        print(max_cnt)
        return 
      else:
        max_cnt = max(max_cnt, fieldh[ih]+fieldw[iw]-1)

if __name__=='__main__':
  main()

Submission status: Runtime Error

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

grid = [[0]*W for _ in range(H)]
grid_h = [0]*H
grid_w = [0]*W

for i in range(m):
    h,w = map(int,input().split())
    grid_h[h-1] += 1
    grid_w[w-1] += 1
    grid[h-1][w-1] = 1

h_max = max(grid_h)
w_max = max(grid_w)

id_h = set()
id_w = set()

for i in range(H):
    if grid_h[i] == h_max:
        id_h.add(i)
for i in range(W):
    if grid_w[i] == w_max:
        id_w.add(i)

ans = h_max + w_max - 1

for i in id_h:
    for j in id_w:
        if grid[i][j] == 0:
            ans = h_max + w_max
            break

print(ans)

Submission status: Runtime Error

Solution code:
R,C,N=map(int,input().split())
locations=[]
for a in range(N):
    locations+=[int(i) for i in input().split()]
rows=[locations[::2].count(i) for i in range(1,R)]
columns=[locations[1::2].count(i) for i in range(1,C)]
print(max(rows)+max(columns))

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
m =[[0]*W for _ in range (H)]
hlist = [0]*H
wlist = [0]*W
for i in range (M):
    h,w = map(lambda x: int(x)-1,input().split())
    m[h][w] = 1
    hlist[h]+=1
    wlist[w]+=1

hmax = 0
hind = []
for i in range(H):
    if hmax < hlist[i]:
        hmax = hlist[i]
        hind = [i]
    elif hmax == hlist[i]:
        hind.append(i)


wmax = 0
wind = []
for i in range(W):
    if wmax < wlist[i]:
        wmax = wlist[i]
        wind = [i]
    elif wmax == wlist[i]:
        wind.append(i)


flag = False
for h in hind:
    for w in wind:
        if m[h][w] == 0:
            print(hmax + wmax)
            flag = True
            break
    if flag:
        break

if not flag:
    print(hmax + wmax - 1)

Submission status: Runtime Error

Solution code:
def solve():
    H,W,M = map(int,input().split())
    h_counter = [0] * H
    w_counter = [0] * W

    opponents = []
    for _ in range(M):
        h, w = map(lambda x:int(x)-1, input().split())
        h_counter[h] += 1
        w_counter[w] += 1
        opponents.append((h,w))
    
    h_max = max(h_counter)
    w_max = max(w_counter)

    h_max_area_cnt = 0
    h_max_area_nums = set()
    for h in range(H):
        if h_counter[h] == h_max:
            h_max_area_nums.add(h)
            h_max_area_cnt += 1

    w_max_area_cnt = 0
    w_max_area_nums = set()
    for w in range(H):
        if w_counter[w] == w_max:
            w_max_area_nums.add(w)
            w_max_area_cnt += 1

    max_area_cnt = h_max_area_cnt * w_max_area_cnt

    opponent_in_max_area = 0
    for h,w in opponents:
        if h in h_max_area_nums and w in w_max_area_nums:
            opponent_in_max_area += 1

    if max_area_cnt > opponent_in_max_area:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
from random import randint
import numpy as np
from numba import njit


@njit('i4(i4,i4,i4,i4[:,:])',cache=True)
def f(h,w,m,ins):
    yp = np.zeros(h,dtype=np.int32)
    xp = np.zeros(w,dtype=np.int32)
    ans = 0
    s = set()
    for hi,wi in ins:
        s.add((hi-1,wi-1))
        yp[hi-1] += 1
        xp[wi-1] += 1
    ypm = yp[yp.argmax()]
    xpm = xp[xp.argmax()]
    yps = np.where(yp == ypm)[0]
    xps = np.where(xp == xpm)[0]
    ans = yp[yps[0]]+xp[xps[0]]
    for ypsi in yps:
        for xpsi in xps:
            if not ((ypsi,xpsi) in s):
                return ans
    return ans-1


if False:
    while True:
        h,w = randint(1,10**5*3),randint(10**5,10**5*3)
        m = randint(1,min(h*w,10**5*3))
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans = f(h,w,m,np.array(ins))
        print(ans)
else:
    h,w,m = map(int,input().split())
    ans = f(h,w,m,np.array([list(map(int,input().split())) for i in range(m)]))
    print(ans)

Submission status: Runtime Error

Solution code:
from random import randint
from numba.np.ufunc import parallel
import numpy as np
from numba import njit


@njit('i4(i4,i4,i4,i4[:,:])',cache=True)
def f(h,w,m,ins):
    yp = np.zeros(h,dtype=np.int32)
    xp = np.zeros(w,dtype=np.int32)
    ans = 0
    s = set()
    for hi,wi in ins:
        s.add((hi-1,wi-1))
        yp[hi-1] += 1
        xp[wi-1] += 1
    ypm = yp[yp.argmax()]
    xpm = xp[xp.argmax()]
    yps = np.where(yp == ypm)[0]
    xps = np.where(xp == xpm)[0]
    ans = yp[yps[0]]+xp[xps[0]]
    for ypsi in yps:
        for xpsi in xps:
            if not ((ypsi,xpsi) in s):
                return ans
    return ans-1


if False:
    while True:
        h,w = randint(10**5,10**5*3),randint(10**5,10**5*3)
        m = randint(h*w,10**5*3)
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans = f(h,w,m,np.array(ins,dtype=np.int32))
        print(ans)
else:
    h,w,m = map(int,input().split())
    ans = f(h,w,m,np.array([tuple(map(int,input().split())) for i in range(m)]))
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

bomb = np.zeros([height, weight], dtype=bool)
for index in range(num):
  x, y = map(int, input().split())
  bomb[x-1, y-1] = True

sum_each_col = bomb.sum(axis=0)
sum_each_row = bomb.sum(axis=1)

max_row = np.max(sum_each_row)
max_col = np.max(sum_each_col)
max_row_pos = np.argmax(sum_each_row)
max_col_pos = np.argmax(sum_each_col)

sum = int(max_row + max_col)
if (bomb[max_row_pos, max_col_pos]):
  print(sum - 1)
else:
  print(sum)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h = num_in_h.values()
max_w = num_in_w.values()
max_h_list = [kv for kv in num_in_h.items() if kv[1] == max_h]
max_w_list = [kv for kv in num_in_w.items() if kv[1] == max_w]
ans = max_h + max_w

#print([max_h[0], max_w[0]] in targets)
flag = False
for h in max_h_list:
    for w in max_w_list:
        if [h[0], w[0]] not in targets:
            flag = True
            break

print(ans if flag == True else ans-1)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
grid = [[0]*W for i in range(H)]

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

ans = 0
idx_counts = []
for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == 1:
            count += 1
    idx_counts.append(count)

for i in range(H):
    row_counts = grid[i].count(1)
    for j in range(W):
        tmp = row_counts + idx_counts[j]
        if grid[i][j] == 1:
            tmp -= 1
        ans = max(ans, tmp)

print(ans)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
grid = [[0]*W for i in range(H)]

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

ans = 0
for i in range(H):
    row_counts = grid[i].count(1)
    idx_counts = 0
    for j in range(W):
        if i == j:
            continue
        else:
            if grid[j][i] == 1:
                idx_counts += 1
    tmp = row_counts + idx_counts
    ans = max(ans, tmp)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M = input().split()
Array_box = np.zeros((int(H),int(W)))
max_bom = 0
for i in range(int(M)):
  X,Y = input().split()
  Array_box[int(X)-1][int(Y)-1] = 1

for i in range(int(H)):
  for j in range(int(W)):
    a = sum(Array_box[i,:])
    b = sum(Array_box[:,j])
    sum_ab = a+b
    if Array_box[i][j] == 1:
      sum_ab -= 1
    if max_bom < sum_ab:
      max_bom = sum_ab
print(int(max_bom))

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M = input().split()
Array_box = np.zeros((int(H),int(W)))
max_bom = 0
for i in range(int(M)):
  X,Y = input().split()
  Array_box[int(X)-1][int(Y)-1] = '1'

for i in range(int(H)):
  for j in range(int(W)):
    a = sum(Array_box[i,:])
    b = sum(Array_box[:,j])
    sum_ab = a+b
    if Array_box[i][j] == 1:
      sum_ab -= 1
    if max_bom < sum_ab:
      max_bom = sum_ab
print(int(max_bom))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

H, W, M = map(int, input().split())
bom = np.zeros((H, W), dtype=int)
for _ in range(M):
    h, w = map(int, input().split())
    bom[h-1, w-1] = 1
tate, yoko = bom.sum(axis=0), bom.sum(axis=1)
tate_max, yoko_max = tate.max(), yoko.max()
tate_list, yoko_list = [], []
for i in range(W):
    if tate[i] == tate_max: tate_list.append(i)
for i in range(H):
    if yoko[i] == yoko_max: yoko_list.append(i)
for h in yoko_list:
    for w in tate_list:
        if not bom[h][w]:
            print(tate_max+yoko_max)
            sys.exit()
print(tate_max+yoko_max-1)

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split())
bombh=[]
bombw=[]
bomb=[[0]*W for _ in range(H)]
w=[0]*W
h=[0]*H
for i in range(M):
    hs,ws=map(int,input().split())
    w[ws-1]+=1
    h[hs-1]+=1
    bomb[hs-1][ws-1]=1
for i in range(H):
    bombh.append([h[i],i])
for i in range(W):
    bombw.append([w[i],i])
bombh.sort(reverse=True)
bombw.sort(reverse=True)
maxh=bombh[0][0]
maxw=bombw[0][0]
ans=maxh+maxw-1
for i in range(H):
    if maxh!=bombh[i][0]:
        break
    a=bombh[i][1]
    for j in range(W):
        if maxw!=bombw[j][0]:
            break
        b=bombw[j][1]
        if bomb[a][b]==0:
            ans+=1
            break
    if bomb[a][b]==0:
        break
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
import sys
h,w,m=map(int,input().split())
grid=[[0]*w for _ in range(h)]

for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    grid[x][y]=1
grid=np.array(grid)
h_sum=np.sum(grid,axis=0)
w_sum=np.sum(grid,axis=1)

h_index=np.where(h_sum==np.max(h_sum))
w_index=np.where(w_sum==np.max(w_sum))
answer=np.max(h_sum)+np.max(w_sum)
for i in h_index[0]:
    for j in w_index[0]:
        if grid[j][i]==0:
            print(answer)
            sys.exit()
print(answer-1)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
import sys
h,w,m=map(int,input().split())
grid=[[0]*w for _ in range(h)]

for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    grid[x][y]=1

grid=np.array(grid)
h_sum=np.sum(grid,axis=0)
w_sum=np.sum(grid,axis=1)

h_index=np.where(h_sum==np.max(h_sum))
w_index=np.where(w_sum==np.max(w_sum))
answer=np.max(h_sum)+np.max(w_sum)

for i in h_index[0]:
    for j in w_index[0]:
        if grid[i][j]==0:
            print(answer)
            sys.exit()
print(answer-1)

Submission status: Runtime Error

Solution code:
import numpy as np
R,C,M=input().split()
row=int(R)
col=int(C)
m=int(M)
main=[]
arr=np.zeros((row,col))
for i in range(m):
  A,B=input().split()
  a=int(A)-1
  b=int(B)-1
  arr[a][b]=1
c_sum=list(arr.sum(axis=0))
r_sum=list(arr.sum(axis=1))
x=r_sum.index(max(r_sum)) 
y=c_sum.index(max(c_sum)) 
print(int(c_sum[y]+r_sum[x]-arr[x][y]))

Submission status: Runtime Error

Solution code:
r, l, m = map(int, input().split())
rr, ll = [0] * r, [0] * l
tt = [[0] * l for i in range(r)]
for i in range(m):
    hi, wi = map(int, input().split())
    rr[hi-1] += 1
    ll[wi-1] += 1
    tt[hi-1][wi-1] = 1
i = rr.index(max(rr))
flag = max(ll)
ans = max(rr)
for j in range(l):
    if ll[j] == flag and tt[i][j] != 1:
        ans += flag
        print(ans)
        exit()

print(ans + flag - 1)

Submission status: Runtime Error

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

L = []

for _ in range(M):
    h, w = map(int,input().split())
    R[h-1] += 1
    C[w-1] += 1
    L.append([h-1, w-1])

r = max(R)
c = max(C)

print(r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
hn = [0]*W
wn = [0]*W
flag = set()
for i in range(M):
  h, w = map(int, input().split())
  hn[h-1] += 1
  wn[w-1] += 1
  flag.add((h,w))
  
#hrank = sorted(hn, key=lambda t:-t[1])
#wrank = sorted(wn, key=lambda t:-t[1])

hmax = max(hn)
wmax = max(wn)

hmaxlist =[]
for h in hn:
  if h == hmax:
    hmaxlist.append(h)
  
wmaxlist =[]
for w in wn:
  if w == wmax:
    wmaxlist.append(w)
  
flag2 = set()
for i in hmaxlist:
  for j in wmaxlist:
    flag2.add((i,j))

if len(flag2 - flag) == 0:
  print(hmax+wmax -1)
else:
  print(hmax+wmax)

Submission status: Runtime Error

Solution code:
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
for i in range(M):
    h, w = S[i]
    R[h] += 1
    C[w] += 1

r = max(R)
c = max(C)

for h in [i for i in range(H) if R[i] == r]:
    for w in [i for i in range(W) if C[i] == c]:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)

Submission status: Runtime Error

Solution code:
x, y, m = map(int,input().split())
mat = []
r = [0]*x
c = [0]*y
smx = 0
smy = 0
for _ in range(m):
    p, q = map(int,input().split())
    p -= 1
    q -= 1
    mat.append((p,q))
    r[p] += 1
    c[q] += 1
    smx = max(smx,r[p])
    smy = max(smy,c[q])
xs = []
ys = []
for i in range(x):
    if smx == r[i]: xs.append(i)
for i in range(y):
    if smy == c[i]: ys.append(i)

ans = smx + smy - 1

for h in xs:
    for w in ys:
        if (h, w) in mat: continue
        print(ans + 1)
        end()
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
bombX = [0]*w
bombY = [0]*h
for i,j in bomb:
    bombX[i] += 1
    bombY[j] += 1
maxX = max(bombX)
maxY = max(bombY)
maxX_index = list(i for i in range(h) if bombX[i] == maxX)
maxY_index = list(i for i in range(w) if bombY[i] == maxY)
for i in maxX_index:
    for j in maxY_index:
        if (i,j) not in bomb:
            print(maxX+maxY)
            exit()
print(maxX+maxY-1)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
bombx = np.count_nonzero(Map,axis=1)
bomby = np.count_nonzero(Map,axis=0)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = list(i for i in range(h) if bombx[i] == maxx)
maxy_index = list(i for i in range(w) if bomby[i] == maxy)
flag = 0
for i in maxx_index:
    for j in maxy_index:
        if (i,j) not in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
bombx = np.count_nonzero(Map,axis=1)
bomby = np.count_nonzero(Map,axis=0)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = list(i for i in range(h) if bombx[i] == maxx)
maxy_index = list(i for i in range(w) if bomby[i] == maxy)
flag = 0
for i in maxx_index:
    for j in maxy_index:
        if Map[i][j] == 0:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
bombx = np.count_nonzero(Map,axis=1)
bomby = np.count_nonzero(Map,axis=0)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = np.where(bombx == maxx)
maxy_index = np.where(bomby == maxy)
flag = 0
for i in maxx_index[0]:
    for j in maxy_index[0]:
        if Map[i][j] == 0:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
bombx = np.count_nonzero(Map,axis=1)
bomby = np.count_nonzero(Map,axis=0)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = np.where(bombx == maxx)
maxy_index = np.where(bomby == maxy)
flag = 0
for i in maxx_index[0]:
    for j in maxy_index[0]:
        if Map[i][j] == 0:
            flag = 1
if flag == 0:
    print(maxx+maxy-1)
else:
    print(maxx+maxy)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
print(Map)    
bombx = np.count_nonzero(Map,axis=1)
bomby = np.count_nonzero(Map,axis=0)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = np.where(bombx == maxx)
maxy_index = np.where(bomby == maxy)
print(maxx_index[0],maxy_index[0])
flag = 0
for i in maxx_index[0]:
    for j in maxy_index[0]:
        if Map[i][j] == 0:
            flag = 1
if flag == 0:
    print(maxx+maxy-1)
else:
    print(maxx+maxy)