input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys h, w, m = list(map(int, input().split())) row = [0]*h col = [0]*w bomb = set() for x in sys.stdin.readlines(): H, W = list(map(int, x.split())) bomb.add((H-1, W-1)) row[H-1] += 1 col[W-1] += 1 maxrow = max(row) maxcol = max(col) ans = maxcol + maxrow - 1 p, q = [], [] for i in range(h): if row[i] == maxrow: p.append(i) for i in range(w): if col[i] == maxcol: q.append(i) for i in p: for j in q: if (i, j) not in bomb: print((ans + 1)) exit() print(ans)
import sys def main(): h, w, m = list(map(int, input().split())) row = [0]*h col = [0]*w bomb = set() for x in sys.stdin.readlines(): H, W = list(map(int, x.split())) bomb.add((H-1, W-1)) row[H-1] += 1 col[W-1] += 1 maxrow = max(row) maxcol = max(col) ans = maxcol + maxrow - 1 p, q = [], [] for i in range(h): if row[i] == maxrow: p.append(i) for i in range(w): if col[i] == maxcol: q.append(i) for i in p: for j in q: if (i, j) not in bomb: print((ans + 1)) exit() print(ans) if __name__ == "__main__": main()
p02580
h,w,m = list(map(int,input().split())) bombw = [0]*w bombh = [0]*h bomb = [[0 for j in range(w)] for i in range(h)] # print(bomb) for i in range(m): hi,wi = list(map(int,input().split())) bombw[wi-1] += 1 bombh[hi-1] += 1 bomb[hi-1][wi-1] = 1 # print(bomb) maw = max(bombw) mah = max(bombh) # print(maw,mah) inmaw = [i for i, x in enumerate(bombw) if x == maw] inmah = [i for i, x in enumerate(bombh) if x == mah] # print(inmaw,inmah) ans = maw + mah # print(bomb) # print(ans) for i in inmah: for j in inmaw: if bomb[i][j] == 0: print(ans) exit() print((ans-1))
h,w,m = list(map(int,input().split())) bombw = [0]*w bombh = [0]*h bomb = [] # print(bomb) for i in range(m): hi,wi = list(map(int,input().split())) bombw[wi-1] += 1 bombh[hi-1] += 1 bomb.append([str(hi-1)+"-"+str(wi-1)]) # print(bomb) maw = max(bombw) mah = max(bombh) # print(maw,mah) inmaw = [i for i, x in enumerate(bombw) if x == maw] inmah = [i for i, x in enumerate(bombh) if x == mah] # print(inmaw,inmah) ans = maw + mah # print(bomb) # print(ans) for i in inmah: for j in inmaw: if [str(i)+"-"+str(j)] not in bomb: print(ans) exit() print((ans-1))
p02580
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(eval(input())) def MAP() : return list(map(int,input().split())) def MAP1() : return [int(x)-1 for x in input().split()] def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) def solve(): h, w, m = MAP() s = [LIST1() for i in range(m)] regy = [0]*h regx = [0]*w c = [[0]*w for i in range(h)] for x in s: regy[x[0]] += 1 regx[x[1]] += 1 c[x[0]][x[1]] = 1 maxy = 0 indy = [] for i in range(h): if maxy < regy[i]: indy = [i] maxy = regy[i] elif maxy == regy[i]: indy.append(i) maxx = 0 indx = [] for i in range(w): if maxx < regx[i]: indx = [i] maxx = regx[i] elif maxx == regx[i]: indx.append(i) ans = maxy + maxx tmp = 1 if len(indy)*len(indx) > m: tmp = 0 else: for y in indy: for x in indx: if c[y][x] == 0: tmp = 0 print((ans - tmp)) if __name__ == '__main__': solve()
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(eval(input())) def MAP() : return list(map(int,input().split())) def MAP1() : return [int(x)-1 for x in input().split()] def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) def solve(): h, w, m = MAP() s = [LIST1() for i in range(m)] ay = [0]*h ax = [0]*w for x in s: ay[x[0]] += 1 ax[x[1]] += 1 my = max(ay) mx = max(ax) by = bx = 0 for y in ay: if y == my: by += 1 for x in ax: if x == mx: bx += 1 ans = my + mx tmp = 0 for x in s: if ay[x[0]]+ax[x[1]]==ans: tmp += 1 if tmp == by*bx: ans -= 1 print(ans) if __name__ == '__main__': solve()
p02580
H, W, M, *HW = list(map(int, open(0).read().split())) R = HW[::2] C = HW[1::2] A = [0] * (H + 1) B = [0] * (W + 1) for h, w in zip(*[iter(HW)] * 2): A[h] += 1 B[w] += 1 S = set(zip(*[iter(HW)] * 2)) ans = 0 for r in R: for c in C: ans = max(ans, A[r] + B[c] - ((r, c) in S)) print(ans)
H, W, M, *HW = list(map(int, open(0).read().split())) HW = list(zip(*[iter(HW)] * 2)) A = [0] * (H + 1) B = [0] * (W + 1) for h, w in HW: A[h] += 1 B[w] += 1 a = max(A) b = max(B) cnt = A.count(a) * B.count(b) - len([0 for h, w in HW if A[h] == a and B[w] == b]) print((a + b - (cnt == 0)))
p02580
import sys H, W, M = list(map(int, sys.stdin.readline().split())) hlst = {} wlst = {} hwlst = [] for i in range(M): h, w = sys.stdin.readline().split() if h in hlst: hlst[h] += 1 else: hlst[h] = 1 if w in wlst: wlst[w] += 1 else: wlst[w] = 1 hwlst.append([h, w]) h = max(hlst.values()) w = max(wlst.values()) hmax = [i for i in hlst if hlst[i] == h] wmax = [i for i in wlst if wlst[i] == w] num = len(hmax)*len(wmax) ans = h + w -1 for i in hwlst: if hlst[i[0]] == h and wlst[i[1]] == w: num -= 1 if num == 0: print(ans) else: print((ans+1))
import sys H, W, M = list(map(int, sys.stdin.readline().split())) hlst = {} wlst = {} hwlst = [] for i in range(M): h, w = list(map(int, sys.stdin.readline().split())) if h in hlst: hlst[h] += 1 else: hlst[h] = 1 if w in wlst: wlst[w] += 1 else: wlst[w] = 1 hwlst.append([h, w]) h = max(hlst.values()) w = max(wlst.values()) hmax = [i for i in hlst if hlst[i] == h] wmax = [i for i in wlst if wlst[i] == w] num = len(hmax)*len(wmax) for i in hwlst: if hlst[i[0]] == h and wlst[i[1]] == w: num -= 1 if num: print((h+w)) else: print((h+w-1))
p02580
H,W,M=list(map(int,input().strip().split())) h=[0 for _ in range(H)] w=[0 for _ in range(W)] dp=[[0 for _ in range(W)] for _ in range(H)] for m in range(M): i,j=list(map(int,input().strip().split())) dp[i-1][j-1]=1 h[i-1]+=1 w[j-1]+=1 h_max=0 hmax_l=[] for i in range(H): if h_max==h[i]: hmax_l.append(i+1) elif h_max<h[i]: h_max=h[i] hmax_l=[] hmax_l.append(i+1) w_max=0 wmax_l=[] for i in range(W): if w_max==w[i]: wmax_l.append(i+1) elif w_max<w[i]: w_max=w[i] wmax_l=[] wmax_l.append(i+1) d=True for i in range(len(hmax_l)): for j in range(len(wmax_l)): if dp[hmax_l[i]-1][wmax_l[j]-1]==0: d=False break ans=max(h)+max(w) if d==False else max(h)+max(w)-1 print(ans)
H,W,M=list(map(int,input().strip().split())) h=[0 for _ in range(H)] w=[0 for _ in range(W)] dp=[] for m in range(M): i,j=list(map(int,input().strip().split())) dp.append((i,j)) h[i-1]+=1 w[j-1]+=1 h_max=0 hmax_l=[] for i in range(H): if h_max==h[i]: hmax_l.append(i+1) elif h_max<h[i]: h_max=h[i] hmax_l=[] hmax_l.append(i+1) w_max=0 wmax_l=[] for i in range(W): if w_max==w[i]: wmax_l.append(i+1) elif w_max<w[i]: w_max=w[i] wmax_l=[] wmax_l.append(i+1) cnt=0 for m in range(M): if h[dp[m][0]-1]+w[dp[m][1]-1]==h_max+w_max: cnt+=1 ans=h_max+w_max if cnt<len(hmax_l)*len(wmax_l) else h_max+w_max-1 print(ans)
p02580
h,w,m = list(map(int,input().split())) H = [0]*(h+1) W = [0]*(w+1) s = set([]) for i in range(m): a,b = list(map(int,input().split())) s.add((a,b)) H[a] += 1 W[b] += 1 x = [0]*(h+1) y = [0]*(w+1) for i in range(h+1): x[i] = [i,H[i]] for i in range(w+1): y[i] = [i,W[i]] x.sort(key= lambda val : val[1],reverse=True) y.sort(key= lambda val : val[1],reverse=True) ma = x[0][1] mb = y[0][1] i,j = 0,0 sw = 0 while 1: if j > w: break if x[i][1] == ma: if (x[i][0],y[j][0]) in s: pass else: if x[i][1]+y[j][1] == ma+mb: sw = 1 break i += 1 else: i = 0 j += 1 print((ma+mb+sw-1))
import time t0 = time.time() h,w,m = list(map(int,input().split())) H = [0]*(h+1) W = [0]*(w+1) s = set([]) for i in range(m): a,b = list(map(int,input().split())) s.add((a,b)) H[a] += 1 W[b] += 1 x = [0]*(h+1) y = [0]*(w+1) for i in range(h+1): x[i] = [i,H[i]] for i in range(w+1): y[i] = [i,W[i]] x.sort(key= lambda val : val[1],reverse=True) y.sort(key= lambda val : val[1],reverse=True) ma = x[0][1] mb = y[0][1] i,j = 0,0 sw = 0 while 1: if j > w: break if x[i][1] == ma: if (x[i][0],y[j][0]) in s: pass else: if x[i][1]+y[j][1] == ma+mb: sw = 1 break i += 1 else: i = 0 j += 1 if time.time() - t0 > 2.5: break print((ma+mb+sw-1))
p02580
import collections H, W, M = list(map(int, input().split())) H_count = collections.defaultdict(int) W_count = collections.defaultdict(int) points = set() for m in range(M): h, w = list(map(int, input().split())) H_count[h] += 1 W_count[w] += 1 points.add((h, w)) H_count_sort = sorted(list(H_count.items()), key=lambda x: x[1]) W_count_sort = sorted(list(W_count.items()), key=lambda x: x[1]) max_count = 0 for h_count in reversed(H_count_sort): for w_count in reversed(W_count_sort): count = h_count[1] + w_count[1] if (h_count[0], w_count[0]) in points: count -= 1 if max_count > count: break max_count = max(max_count, count) print(max_count)
H, W, M = list(map(int, input().split())) cnt_h = [0] * (H + 1) cnt_w = [0] * (W + 1) points = set() for m in range(M): h, w = list(map(int, input().split())) cnt_h[h] += 1 cnt_w[w] += 1 points.add((h, w)) H_max = max(cnt_h) W_max = max(cnt_w) H_max_num = [i for i, cnt in enumerate(cnt_h) if cnt == H_max] W_max_num = [i for i, cnt in enumerate(cnt_w) if cnt == W_max] flag = 0 for h_num in H_max_num: for w_num in W_max_num: if (h_num, w_num) not in points: print((H_max + W_max)) exit() print((H_max + W_max -1))
p02580
def main(): def solve(strings_max, rows_max, mapa): summa = maxs + maxr - 1 if summa == h + w - 1 or summa == m: return summa for h_item in strings_max: for w_item in rows_max: if w_item not in mapa.get(h_item, []): return summa + 1 return summa h, w, m = list(map(int, input().split())) mapa = {} strings = [0]*h rows = [0]*w for _ in range(m): h1, w1 = list(map(int, input().split())) if not mapa.get(h1-1, 0): mapa[h1-1] = [] mapa[h1-1].append(w1-1) strings[h1-1] += 1 rows[w1-1] += 1 maxs = max(strings) maxr = max(rows) strings_max = [] rows_max = [] for i in range(h): if strings[i] == maxs: strings_max.append(i) for i in range(w): if rows[i] == maxr: rows_max.append(i) ans = solve(strings_max, rows_max, mapa) print(ans) main()
def main(): h, w, m = list(map(int, input().split())) mapa = {} strings = [0]*h rows = [0]*w for _ in range(m): h1, w1 = list(map(int, input().split())) if not mapa.get(h1-1, 0): mapa[h1-1] = [] mapa[h1-1].append(w1-1) strings[h1-1] += 1 rows[w1-1] += 1 max_s = max(strings) max_r = max(rows) strings_max = [] rows_max = [] for i in range(h): if strings[i] == max_s: strings_max.append(i) for i in range(w): if rows[i] == max_r: rows_max.append(i) forbidden_positions = set(mapa[strings_max[0]]) for item in strings_max[1:]: forbidden_positions.intersection_update(set(mapa[item])) answer_set = set(rows_max).difference(forbidden_positions) if answer_set: print((max_s + max_r)) else: print((max_s + max_r - 1)) main()
p02580
from collections import deque H, W, M = list(map(int, input().split())) grid = [[0 for _ in range(W)] for _ in range(H)] counth = deque([0 for k in range(H)]) countw = deque([0 for k in range(W)]) for k in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 grid[h][w] = 1 counth[h] += 1 countw[w] += 1 maxh = max(counth) maxw = max(countw) index_h = deque([]) index_w = deque([]) k = 0 while k < H: h = counth.popleft() if h == maxh: index_h.append(k) k += 1 k = 0 while k < W: w = countw.popleft() if w == maxw: index_w.append(k) k += 1 ans = maxh + maxw - 1 lenh = len(index_h) lenw = len(index_w) if lenh*lenw > M: ans += 1 else: for i in range(lenh): h = index_h.pop() for j in range(lenw): w = index_w[j] if grid[h][w] == 0: ans += 1 break else: continue break print(ans)
from collections import deque H, W, M = list(map(int, input().split())) bomb = [] counth = deque([0 for k in range(H)]) countw = deque([0 for k in range(W)]) for k in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 bomb.append([h, w]) counth[h] += 1 countw[w] += 1 maxh = max(counth) maxw = max(countw) index_h = deque([]) index_w = [] k = 0 while k < H: h = counth.popleft() if h == maxh: index_h.append(k) k += 1 k = 0 while k < W: w = countw.popleft() if w == maxw: index_w.append(k) k += 1 ans = maxh + maxw - 1 lenh = len(index_h) lenw = len(index_w) if lenh*lenw > M: ans += 1 else: for i in range(lenh): h = index_h.pop() for j in range(lenw): w = index_w[j] if [h, w] not in bomb: ans += 1 break else: continue break print(ans)
p02580
from collections import deque H, W, M = list(map(int, input().split())) bomb = [] counth = deque([0 for k in range(H)]) countw = deque([0 for k in range(W)]) for k in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 bomb.append(h+ w*H) counth[h] += 1 countw[w] += 1 def binary_search(list, item): low = 0 high = len(list) - 1 while low <= high: mid = (low + high) //2 guess = list[mid] if guess == item: #return mid return True if guess > item: high = mid -1 else: low = mid + 1 return False maxh = max(counth) maxw = max(countw) index_h = deque([]) index_w = [] k = 0 while k < H: h = counth.popleft() if h == maxh: index_h.append(k) k += 1 k = 0 while k < W: w = countw.popleft() if w == maxw: index_w.append(k) k += 1 ans = maxh + maxw - 1 lenh = len(index_h) lenw = len(index_w) if lenh*lenw > M: ans += 1 else: bomb.sort() kouho = [] for i in range(lenh): h = index_h.pop() for j in range(lenw): w = index_w[j] kouho.append(h+ H*w) for K in kouho: if binary_search(bomb, K): continue else: ans += 1 break print(ans)
from collections import deque H, W, M = list(map(int, input().split())) bomb = [] counth = [0 for k in range(H)] countw = [0 for k in range(W)] for k in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 bomb.append(h+ w*H) counth[h] += 1 countw[w] += 1 counth = deque(counth) countw = deque(countw) def binary_search(list, item): low = 0 high = len(list) - 1 while low <= high: mid = (low + high) //2 guess = list[mid] if guess == item: #return mid return True if guess > item: high = mid -1 else: low = mid + 1 #return None return False maxh = max(counth) maxw = max(countw) index_h = deque([]) index_w = [] for k in range(H): h = counth.popleft() if h == maxh: index_h.append(k) for k in range(W): w = countw.popleft() if w == maxw: index_w.append(k) ans = maxh + maxw - 1 lenh = len(index_h) lenw = len(index_w) if lenh*lenw > M: ans += 1 else: bomb.sort() kouho = [] for i in range(lenh): h = index_h.pop() for j in range(lenw): w = index_w[j] kouho.append(h+ H*w) for K in kouho: if binary_search(bomb, K): continue else: ans += 1 break print(ans)
p02580
H, W, M = list(map(int, input().split())) hw = [] cnt_h, cnt_w = [0] * H, [0] * W for i in range(M): x, y = list(map(int, input().split())) hw.append((x - 1, y - 1)) cnt_h[x - 1] += 1 cnt_w[y - 1] += 1 max_h, max_w = max(cnt_h), max(cnt_w) h_list = [h for h in range(H) if cnt_h[h] == max_h] w_list = [w for w in range(W) if cnt_w[w] == max_w] from itertools import product for h, w in product(h_list, w_list): if (h, w) not in set(hw): print((max_h + max_w)) break else: print((max_h + max_w - 1))
H, W, M = list(map(int, input().split())) hw = set() cnt_h, cnt_w = [0] * H, [0] * W for i in range(M): x, y = list(map(int, input().split())) hw.add((x - 1, y - 1)) cnt_h[x - 1] += 1 cnt_w[y - 1] += 1 max_h, max_w = max(cnt_h), max(cnt_w) h_list = [h for h in range(H) if cnt_h[h] == max_h] w_list = [w for w in range(W) if cnt_w[w] == max_w] res = max_h + max_w - 1 for h in h_list: for w in w_list: if (h, w) not in hw: print((res + 1)) exit() print(res)
p02580
def my_index_multi(l, x): return [k for k, _x in enumerate(l) if _x == x] h,w,m = list(map(int,input().split())) l_h = [0]*(h+1) l_w = [0]*(w+1) a = min(h*w,3*10**5) l_hw = [[0 for _ in range(a)] for __ in range(h+1)] for x in range(m): h,w = list(map(int,input().split())) l_h[h] += 1 l_w[w] += 1 l_hw[h][x] += w m_h = max(l_h) m_w = max(l_w) ans = m_h + m_w l_h_2 = my_index_multi(l_h,m_h) l_w_2 = my_index_multi(l_w,m_w) for i in l_h_2: flag = False for j in l_w_2: if j not in l_hw[i]: flag = True break if flag: break else: ans -= 1 print(ans)
def my_index_multi(l, x): return [k for k, _x in enumerate(l) if _x == x] h,w,m = list(map(int,input().split())) l_h = [0]*(h+1) l_w = [0]*(w+1) l_hw = [[] for _ in range(h+1)] for _ in range(m): h,w = list(map(int,input().split())) l_h[h] += 1 l_w[w] += 1 l_hw[h].append(w) m_h = max(l_h) m_w = max(l_w) ans = m_h + m_w l_h_2 = my_index_multi(l_h,m_h) l_w_2 = my_index_multi(l_w,m_w) flag = False for i in l_h_2: for j in l_w_2: if j not in l_hw[i]: flag = True break if flag: break else: ans -= 1 print(ans)
p02580
import itertools def my_index_multi(l, x): return [k for k, _x in enumerate(l) if _x == x] h,w,m = list(map(int,input().split())) l_h = [0]*(h+1) l_w = [0]*(w+1) l_hw = [[] for _ in range(h+1)] for _ in range(m): h,w = list(map(int,input().split())) l_h[h] += 1 l_w[w] += 1 l_hw[h].append(w) m_h = max(l_h) m_w = max(l_w) ans = m_h + m_w l_h_2 = my_index_multi(l_h,m_h) l_w_2 = my_index_multi(l_w,m_w) for i,j in itertools.product(l_h_2,l_w_2): if j not in l_hw[i]: break else: ans -= 1 print(ans)
import sys import itertools input = sys.stdin.readline def my_index_multi(l, x): return [k for k, _x in enumerate(l) if _x == x] h,w,m = list(map(int,input().split())) l_h = [0]*(h+1) l_w = [0]*(w+1) l_b = set() for _ in range(m): h,w = list(map(int,input().split())) l_h[h] += 1 l_w[w] += 1 l_b.add((h,w)) m_h = max(l_h) m_w = max(l_w) l_h_2 = [] for i, x in enumerate(l_h): if x == m_h: l_h_2.append(i) l_w_2 = [] for i, x in enumerate(l_w): if x == m_w: l_w_2.append(i) ans = m_h + m_w for i,j in itertools.product(l_h_2,l_w_2): if (i,j) not in l_b: break else: ans -= 1 print(ans)
p02580
h,w,m=list(map(int,input().split())) s=[0]*m t=[0]*m temp=[0]*m for i in range(m): sm,tm=list(map(int,input().split())) s[i]=sm t[i]=tm temp[i]=[s[i],t[i]] st=[0]*h tt=[0]*w for i in range(m): st[s[i]-1]=st[s[i]-1]+1 tt[t[i]-1]=tt[t[i]-1]+1 smax=max(st) tmax=max(tt) ans=smax+tmax maxs=[] maxt=[] for i in range(h): if st[i]==smax: maxs.append(i) for i in range(w): if tt[i]==tmax: maxt.append(i) if len(maxs)*len(maxt)>m: print(ans) else: for i in range(len(maxs)): for j in range(len(maxt)): if [maxs[i]+1,maxt[j]+1] not in temp: print(ans) exit() else: print((ans-1))
h,w,m=list(map(int,input().split())) s=[0]*m t=[0]*m temp=set() for i in range(m): sm,tm=list(map(int,input().split())) s[i]=sm t[i]=tm temp.add((s[i],t[i])) st=[0]*h tt=[0]*w for i in range(m): st[s[i]-1]=st[s[i]-1]+1 tt[t[i]-1]=tt[t[i]-1]+1 smax=max(st) tmax=max(tt) ans=smax+tmax maxs=[] maxt=[] for i in range(h): if st[i]==smax: maxs.append(i) for i in range(w): if tt[i]==tmax: maxt.append(i) if len(maxs)*len(maxt)>m: print(ans) else: for i in range(len(maxs)): for j in range(len(maxt)): if (maxs[i]+1,maxt[j]+1) not in temp: print(ans) exit() else: print((ans-1))
p02580
h,w,m=list(map(int, input().split())) r = [0]*max(h,w) c = [0]*max(h,w) l=[] for i in range(m): x,y=list(map(int, input().split())) r[x-1]+=1 c[y-1]+=1 l.append([x,y]) cm = max(c) rm = max(r) ci = [i for i, x in enumerate(c) if x == cm] ri = [i for i, x in enumerate(r) if x == rm] ans = cm + rm cnt = 0 #print(l,ci,ri) for i in range(m): if l[i][0]-1 in ri and l[i][1]-1 in ci: cnt += 1 if cnt == len(ci)*len(ri): print((int(ans)-1)) else: print((int(ans)))
h,w,m=list(map(int, input().split())) r = [0]*max(h,w) c = [0]*max(h,w) l=[] for i in range(m): x,y=list(map(int, input().split())) r[x-1]+=1 c[y-1]+=1 l.append([x,y]) cm = max(c) rm = max(r) ci = [i for i, x in enumerate(c) if x == cm] ri = [i for i, x in enumerate(r) if x == rm] ans = cm + rm cnt = 0 #print(l,ci,ri) for i in range(m): if r[l[i][0]-1] == rm and c[l[i][1]-1] ==cm: cnt += 1 if cnt == len(ci)*len(ri): print((int(ans)-1)) else: print((int(ans)))
p02580
def comp(v,w): if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]): return 1 elif v==w: return 0 else: return -1 def mergesort(list0): n=len(list0) if n<=1: return list0 else: a=mergesort(list0[0:n//2]) b=mergesort(list0[n//2:n]) return merge(a,b) def merge(list1,list2): a=0 b=0 s=[] for c in range(len(list1)+len(list2)): if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])==1): s.append(list1[a]) a=a+1 else: s.append(list2[b]) b=b+1 return s def bis_exist(lis,dev): a=0 b=len(lis)-1 if lis[b]==dev: return 1 while a<b: c=(a+b)//2 if lis[c]==dev: return 1 if comp(lis[c],dev)==1: a=c+1 if comp(lis[c],dev)==-1: b=c return 0 h,w,m=list(map(int,input().split())) g=[] e1=[[0,t] for t in range(h)] e2=[[0,t] for t in range(w)] for c in range(m): a,b=list(map(int,input().split())) g.append([a-1,b-1]) e1[a-1][0]+=1 e2[b-1][0]+=1 f1=mergesort(e1) f2=mergesort(e2) k=mergesort(g) p=f1[-1][0] q=f2[-1][0] x=[] y=[] for c in range(h-1,-1,-1): if p>f1[c][0]: break x.append(f1[c][1]) for c in range(w-1,-1,-1): if q>f2[c][0]: break y.append(f2[c][1]) r=1 if len(x)*len(y)>m: r=0 else: for i in x: for j in y: if bis_exist(k,[i,j])==0: r=0 break else: continue break print((p+q-r))
h,w,m=list(map(int,input().split())) g=[] e1=[0]*h e2=[0]*w for c in range(m): a,b=list(map(int,input().split())) g.append([a-1,b-1]) e1[a-1]+=1 e2[b-1]+=1 p1=max(e1) p2=max(e2) x=[1 if e1[c]==p1 else 0 for c in range(h)] y=[1 if e2[c]==p2 else 0 for c in range(w)] r=sum(x)*sum(y) for i in g: if x[i[0]]==1 and y[i[1]]==1: r-=1 if r==0: print((p1+p2-1)) else: print((p1+p2))
p02580
H, W, M = list(map(int, input().split())) hrz = [0]*H vrt = [0]*W targets = set() for _ in range(M): h, w = list([int(x) - 1 for x in input().split()]) targets.add((h, w)) hrz[h] += 1 vrt[w] += 1 hrz_max = max(hrz) vrt_max = max(vrt) for h in [i for i in range(H) if hrz[i] == hrz_max]: for w in [i for i in range(W) if vrt[i] == vrt_max]: if not (h, w) in targets: print((hrz_max+vrt_max)) exit() print((hrz_max+vrt_max-1))
H, W, M = list(map(int, input().split())) hrz = [0]*H vrt = [0]*W targets = set() for _ in range(M): h, w = list([int(x) - 1 for x in input().split()]) targets.add((h, w)) hrz[h] += 1 vrt[w] += 1 hrz_max = max(hrz) vrt_max = max(vrt) hrz_max_lines = [i for i in range(H) if hrz[i] == hrz_max] vrt_max_lines = [i for i in range(W) if vrt[i] == vrt_max] for h in hrz_max_lines: for w in vrt_max_lines: if not (h, w) in targets: print((hrz_max+vrt_max)) exit() print((hrz_max+vrt_max-1))
p02580
import sys input = sys.stdin.readline l = [] sh,sw,m = list(map(int,input().split())) H = [0]*sh W = [0]*sw for i in range(m): h,w = list(map(int,input().split())) l.append((h-1,w-1)) H[h-1] += 1 W[w-1] += 1 maxh = max(H) maxw = max(W) # print(H,W) # print(maxh,maxw) hlist = [] wlist = [] for i in range(sh): if H[i] == maxh: hlist.append(i) for j in range(sw): if W[j] == maxw: wlist.append(j) # print(hlist,wlist) maxi = maxh+maxw-1 for i in hlist: for j in wlist: if (i,j) not in l: maxi += 1 print(maxi) exit() print(maxi)
import sys input = sys.stdin.readline l = set() sh,sw,m = list(map(int,input().split())) H = [0]*sh W = [0]*sw for i in range(m): h,w = list(map(int,input().split())) l.add((h-1,w-1)) H[h-1] += 1 W[w-1] += 1 maxh = max(H) maxw = max(W) # print(H,W) # print(maxh,maxw) hlist = [] wlist = [] for i in range(sh): if H[i] == maxh: hlist.append(i) for j in range(sw): if W[j] == maxw: wlist.append(j) # print(hlist,wlist) if len(hlist)*len(wlist) > m: print((maxh+maxw)) exit() ans = maxh+maxw-1 for i in hlist: for j in wlist: if (i,j) not in l: print((ans+1)) exit() print(ans)
p02580
from collections import Counter def solver(): H, W, M = list(map(int, input().split())) retu = Counter() gyo = Counter() ipt = [[] for _ in range(H)] for _ in range(M): a, b = list(map(int, input().split())) retu[a-1] += 1 gyo[b-1] += 1 ipt[a-1].append(b-1) rm = retu.most_common() rmm = rm[0][1] gm = gyo.most_common() gmm = gm[0][1] for r in rm: if r[1] < rmm: break for g in gm: if g[1] < gmm: break if g[0] not in ipt[r[0]]: return rmm+gmm return rmm+gmm-1 print((solver()))
from collections import Counter def solver(): H, W, M = list(map(int, input().split())) retu = Counter() gyo = Counter() ipt = [set() for _ in range(H)] for _ in range(M): a, b = list(map(int, input().split())) retu[a-1] += 1 gyo[b-1] += 1 ipt[a-1].add(b-1) rm = retu.most_common() rmm = rm[0][1] gm = gyo.most_common() gmm = gm[0][1] for r in rm: if r[1] < rmm: break for g in gm: if g[1] < gmm: break if g[0] not in ipt[r[0]]: return rmm+gmm return rmm+gmm-1 print((solver()))
p02580
h, w, m = list(map(int, input().split())) bom_list = [] h_list = [0] * h w_list = [0] * w for i in range(m): a, b = list(map(int, input().split())) bom_list.append([a - 1, b - 1]) h_list[a - 1] += 1 w_list[b - 1] += 1 max_h = max(h_list) max_h_list = [i for i, x in enumerate(h_list) if x == max_h] max_w = max(w_list) max_w_list = [i for i, x in enumerate(w_list) if x == max_w] ans = max_h + max_w count = 0 for i in range(len(max_h_list)): for j in range(len(max_w_list)): if [max_h_list[i], max_w_list[j]] in bom_list: count += 1 if len(max_h_list) * len(max_w_list) == count: ans -= 1 print(ans)
h, w, m = list(map(int, input().split())) bom_list = [] h_list = [0] * h w_list = [0] * w for i in range(m): a, b = list(map(int, input().split())) bom_list.append([a - 1, b - 1]) h_list[a - 1] += 1 w_list[b - 1] += 1 max_h = max(h_list) max_w = max(w_list) ans = max_h + max_w count = 0 for bom in bom_list: if h_list[bom[0]] == max_h and w_list[bom[1]] == max_w: count += 1 if h_list.count(max_h) * w_list.count(max_w) == count: ans -= 1 print(ans)
p02580
import sys input = sys.stdin.buffer.readline H, W, M = list(map(int, input().split())) bomb_h = [0] * H bomb_w = [0] * W grid = [[False] * W for _ in range(H)] max_h = 0 max_w = 0 h_indices = [] w_indices = [] for i in range(M): h, w = list(map(int, input().split())) bomb_h[h-1] += 1 bomb_w[w-1] += 1 if bomb_h[h-1] == max_h: h_indices.append(h-1) elif bomb_h[h-1] > max_h: h_indices = [h-1] max_h = bomb_h[h-1] if bomb_w[w-1] == max_w: w_indices.append(w-1) elif bomb_w[w-1] > max_w: w_indices = [w-1] max_w = bomb_w[w-1] grid[h-1][w-1] = True ans = max_w + max_h - 1 for h in h_indices: for w in w_indices: if not grid[h][w]: ans += 1 print(ans) exit() if ans == -1: ans = 0 print(ans)
import sys input = sys.stdin.buffer.readline H, W, M = list(map(int, input().split())) bomb_h = [0] * H bomb_w = [0] * W bomb = set() for i in range(M): h, w = list(map(int, input().split())) bomb_h[h-1] += 1 bomb_w[w-1] += 1 bomb.add((h-1, w-1)) max_h = max(bomb_h) max_w = max(bomb_w) h_indices = [] for i in range(H): if bomb_h[i] == max_h: h_indices.append(i) w_indices = [] for i in range(W): if bomb_w[i] == max_w: w_indices.append(i) ans = max_w + max_h - 1 for h in h_indices: for w in w_indices: if (h, w) not in bomb: ans += 1 print(ans) exit() if ans == -1: ans = 0 print(ans)
p02580
H,W,M=list(map(int,input().split())) HSum=[0 for _ in range(H)] WSum=[0 for _ in range(W)] bombs = set() for _ in range(M): hi,wi = [int(x)-1 for x in input().split()] HSum[hi] += 1 WSum[wi] += 1 bombs.add( (hi,wi) ) # print(HSum) # print(WSum) curMax = 0 ## 計算量多すぎ。。 # for h in range(H): # for w in range(W): # tmp = HSum[h] + WSum[w] # if curMax <= tmp: # if (h,w) in bombs: # tmp -= 1 # curMax = max( curMax, tmp ) hMax = max(HSum) wMax = max(WSum) tmpMax = hMax + wMax ans = 0 # hSumMaxOnly = [h for h, x in enumerate(HSum) if x == hMax] # wSumMaxOnly = [w for w, y in enumerate(WSum) if y == wMax] for h in [h for h, x in enumerate(HSum) if x == hMax]: if ans == tmpMax: break for w in [w for w, y in enumerate(WSum) if y == wMax]: if (h,w) in bombs: ans = tmpMax - 1 else: ans = tmpMax break print(ans)
H,W,M=list(map(int,input().split())) HSum=[0 for _ in range(H)] WSum=[0 for _ in range(W)] bombs = set() for _ in range(M): hi,wi = [int(x)-1 for x in input().split()] HSum[hi] += 1 WSum[wi] += 1 bombs.add( (hi,wi) ) # print(HSum) # print(WSum) curMax = 0 ## 計算量多すぎ。。 # for h in range(H): # for w in range(W): # tmp = HSum[h] + WSum[w] # if curMax <= tmp: # if (h,w) in bombs: # tmp -= 1 # curMax = max( curMax, tmp ) hMax = max(HSum) wMax = max(WSum) tmpMax = hMax + wMax ans = 0 hSumMaxOnly = [h for h, x in enumerate(HSum) if x == hMax] wSumMaxOnly = [w for w, y in enumerate(WSum) if y == wMax] for h in hSumMaxOnly: if ans == tmpMax: break for w in wSumMaxOnly: if (h,w) in bombs: ans = tmpMax - 1 else: ans = tmpMax break print(ans)
p02580
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(eval(input())) def F(): return float(eval(input())) def SS(): return eval(input()) def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): H, W, M = LI() hw = [LI() for _ in range(M)] hw_set = set([(h, w) for h, w in hw]) cnt_h = collections.Counter([h for h, w in hw]) cnt_w = collections.Counter([w for h, w in hw]) # i行目にはどの列にあります # print(cnt_h) # print(cnt_w) max_h = max(cnt_h.values()) max_w = max(cnt_w.values()) max_h_k = [k for k, v in list(cnt_h.items()) if v == max_h] max_w_k = [k for k, v in list(cnt_w.items()) if v == max_w] is_on_target = True for i, j in itertools.product(max_h_k, max_w_k): if (i, j) not in hw_set: is_on_target = False if is_on_target: ans = max(cnt_h.values()) + max(cnt_w.values()) - 1 else: ans = max(cnt_h.values()) + max(cnt_w.values()) print(ans) if __name__ == '__main__': resolve()
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(eval(input())) def F(): return float(eval(input())) def SS(): return eval(input()) def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): H, W, M = LI() hw = [LI() for _ in range(M)] hw_set = set([(h, w) for h, w in hw]) cnt_h = collections.Counter([h for h, w in hw]) cnt_w = collections.Counter([w for h, w in hw]) # i行目にはどの列にあります # print(cnt_h) # print(cnt_w) max_h = max(cnt_h.values()) max_w = max(cnt_w.values()) max_h_k = [k for k, v in list(cnt_h.items()) if v == max_h] max_w_k = [k for k, v in list(cnt_w.items()) if v == max_w] is_on_target = True for i, j in itertools.product(max_h_k, max_w_k): if (i, j) not in hw_set: is_on_target = False break if is_on_target: ans = max_h + max_w - 1 else: ans = max_h + max_w print(ans) if __name__ == '__main__': resolve()
p02580
h, w, m = list(map(int, input().split())) h_cnt = [0] * h w_cnt = [0] * w bomb_list = [] for i in range(m): h_, w_ = list(map(int, input().split())) h_ -= 1 w_ -= 1 h_cnt[h_] += 1 w_cnt[w_] += 1 bomb_list.append((h_, w_)) max_h = max(h_cnt) max_h_idx = [] for i in range(h): if h_cnt[i] == max_h: max_h_idx.append(i) max_w = max(w_cnt) max_w_idx = [] for i in range(w): if w_cnt[i] == max_w: max_w_idx.append(i) minus = -1 for i in max_h_idx: for j in max_w_idx: if (i, j) not in bomb_list: print((max_h + max_w)) exit() print((max_h + max_w - 1))
h, w, m = list(map(int, input().split())) h_cnt = [0] * h w_cnt = [0] * w bomb_set = set() for i in range(m): h_, w_ = list(map(int, input().split())) h_ -= 1 w_ -= 1 h_cnt[h_] += 1 w_cnt[w_] += 1 bomb_set.add((h_, w_)) max_h = max(h_cnt) max_h_idx = [] for i in range(h): if h_cnt[i] == max_h: max_h_idx.append(i) max_w = max(w_cnt) max_w_idx = [] for i in range(w): if w_cnt[i] == max_w: max_w_idx.append(i) minus = -1 for i in max_h_idx: for j in max_w_idx: if (i, j) not in bomb_set: print((max_h + max_w)) exit() print((max_h + max_w - 1))
p02580
from sys import exit H, W, M = list(map(int, input().split())) b = [[False] * W for _ in range(H)] r = [0] * H c = [0] * W for _ in range(M): h, w = list(map(int, input().split())) b[h-1][w-1] = True r[h-1] += 1 c[w-1] += 1 list_r, list_c = [], [] max_r, max_c = max(r), max(c) for i in range(H): if r[i] == max_r: list_r.append(i) for i in range(W): if c[i] == max_c: list_c.append(i) for v1 in list_r: for v2 in list_c: if not b[v1][v2]: print((max_r + max_c)) exit() print((max_r + max_c - 1))
from sys import exit H, W, M = list(map(int, input().split())) r = [0] * H c = [0] * W l = [] for _ in range(M): h, w = list(map(int, input().split())) l.append([h-1, w-1]) r[h-1] += 1 c[w-1] += 1 set_r = set() set_c = set() max_r, max_c = max(r), max(c) for i in range(H): if r[i] == max_r: set_r.add(i) for i in range(W): if c[i] == max_c: set_c.add(i) cnt = 0 for x, y in l: if x in set_r and y in set_c: cnt += 1 if cnt == len(set_r) * len(set_c): print((max_r + max_c - 1)) else: print((max_r + max_c))
p02580
""" Satwik_Tiwari ;) . 21st AUGUST , 2020 - FRIDAY """ #=============================================================================================== #importing some useful libraries. from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import * from copy import * from collections import deque from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl #If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect #If the element is already present in the list, # the right most position where element has to be inserted is returned #============================================================================================== #fast I/O region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts mod = 1000000007 def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return list(map(int, inp().split())) def strsep(): return list(map(str, inp().split())) # def graph(vertex): return [[] for i in range(0,vertex+1)] def zerolist(n): return [0]*n def nextline(): out("\n") #as stdout.write always print sring. def testcase(t): for p in range(t): solve() def printlist(a) : for p in range(0,len(a)): out(str(a[p]) + ' ') def google(p): print('Case #'+str(p)+': ',end='') def lcm(a,b): return (a*b)//gcd(a,b) def power(x, y, p) : res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True #=============================================================================================== # code here ;)) @iterative def dfs(v,visited,st,new): new.append(st) visited[st] = 1 for i in v[st]: if(visited[i] == 0): ok = yield dfs(v,visited,i,new) yield True def solve(): n,m,p = sep() grid = [[0 for i in range(m)] for j in range(n)] for i in range(p): a,b = sep() a-=1 b-=1 grid[a][b] +=1 rowsum = [0]*n colsum = [0]*m for i in range(n): sum = 0 for j in range(m): sum+=grid[i][j] rowsum[i] = sum for j in range(m): sum = 0 for i in range(n): sum+=grid[i][j] colsum[j] = sum new = [[0 for i in range(m)]for j in range(n)] for i in range(n): for j in range(m): new[i][j] = rowsum[i]+colsum[j]-grid[i][j] mx = 0 for i in range(n): for j in range(m): mx = max(mx,new[i][j]) print(mx) testcase(1) # testcase(int(inp()))
""" Satwik_Tiwari ;) . 21st AUGUST , 2020 - FRIDAY """ #=============================================================================================== #importing some useful libraries. from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import * from copy import * from collections import deque from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl #If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect #If the element is already present in the list, # the right most position where element has to be inserted is returned #============================================================================================== #fast I/O region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts mod = 1000000007 def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return list(map(int, inp().split())) def strsep(): return list(map(str, inp().split())) # def graph(vertex): return [[] for i in range(0,vertex+1)] def zerolist(n): return [0]*n def nextline(): out("\n") #as stdout.write always print sring. def testcase(t): for p in range(t): solve() def printlist(a) : for p in range(0,len(a)): out(str(a[p]) + ' ') def google(p): print('Case #'+str(p)+': ',end='') def lcm(a,b): return (a*b)//gcd(a,b) def power(x, y, p) : res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True #=============================================================================================== # code here ;)) @iterative def dfs(v,visited,st,new): new.append(st) visited[st] = 1 for i in v[st]: if(visited[i] == 0): ok = yield dfs(v,visited,i,new) yield True def solve(): n,m,p = sep() row = [0]*n col = [0]*m have = {} for i in range(p): a,b = sep() a-=1 b-=1 have[str(a)+' '+str(b)] = 1 row[a] +=1 col[b] +=1 rmx = max(row) cmx = max(col) total = row.count(rmx)*col.count(cmx) ans = 0 for i in have: ind = i.index(' ') a = int(i[:ind]) b = int(i[ind+1:]) if(row[a]==rmx and col[b] == cmx): ans +=1 if(total==ans): print(rmx+cmx-1) else: print(rmx+cmx) testcase(1) # testcase(int(inp()))
p02580
import copy import sys H, W, M= list(map(int,input().split())) height = [0]*H width = [0]*W object = [] for s in sys.stdin.readlines(): h, w = list(map(int, s.split())) height[h-1] += 1 width[w-1] += 1 object.append([h-1, w-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 c = 0 p = len(cand_h)*len(cand_w) if M >= p: for i in range(len(object)): if object[i][0] in cand_h and object[i][1] in cand_w: c += 1 print((ans - (c == p)))
import copy import sys H, W, M= list(map(int,input().split())) height = [0]*H width = [0]*W object = [] for s in sys.stdin.readlines(): h, w = list(map(int, s.split())) height[h-1] += 1 width[w-1] += 1 object.append([h-1, w-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 c = 0 p = len(cand_h)*len(cand_w) cand_h = set(cand_h) cand_w = set(cand_w) if M >= p: for i in range(len(object)): if object[i][0] in cand_h and object[i][1] in cand_w: c += 1 print((ans - (c == p)))
p02580
H, W, M = [int(n) for n in input().split()] H_freq = [0] * H W_freq = [0] * W coordinates = {} for m in range(M): h, w = [int(n)-1 for n in input().split()] H_freq[h] += 1 W_freq[w] += 1 if h in list(coordinates.keys()): coordinates[h].append(w) else: coordinates[h] = [w] max_h = max(H_freq) max_w = max(W_freq) most_freqent_h = [i for i, h in enumerate(H_freq) if h == max_h] most_freqent_w = [i for i, w in enumerate(W_freq) if w == max_w] ans = 0 for h in most_freqent_h: for w in most_freqent_w: if w in coordinates[h]: ans = max_h + max_w - 1 else: ans = max_h + max_w print(ans) exit() print(ans)
H, W, M = [int(n) for n in input().split()] H_freq = [0] * H W_freq = [0] * W table = [] for m in range(M): h, w = [int(n)-1 for n in input().split()] H_freq[h] += 1 W_freq[w] += 1 table.append((h, w)) max_h = max(H_freq) max_w = max(W_freq) most_freqent_h = [i for i, h in enumerate(H_freq) if h == max_h] most_freqent_w = [i for i, w in enumerate(W_freq) if w == max_w] count = 0 for (h, w) in table: if H_freq[h] == max_h and W_freq[w] == max_w: count += 1 if count < len(most_freqent_h) * len(most_freqent_w): print((max_h + max_w)) else: print((max_h + max_w - 1))
p02580
h, w, m = list(map(int, input().split())) target = set() rows = [0] * h cols = [0] * w for i in range(m): y, x = [int(x) - 1 for x in input().split()] rows[y] += 1 cols[x] += 1 target.add((y, x)) rows_sorted = [(a, i) for i, a in enumerate(rows)] rows_sorted.sort(reverse=True) cols_sorted = [(a, i) for i, a in enumerate(cols)] cols_sorted.sort(reverse=True) max_r = rows_sorted[0][0] max_c = cols_sorted[0][0] i = 0 max_val = max(max_r, max_c) while i < h and rows_sorted[i][0] == max_r: j = 0 while j < w and cols_sorted[j][0] == max_c: val = rows_sorted[i][0] + cols_sorted[j][0] if (rows_sorted[i][1], cols_sorted[j][1]) in target: val -= 1 else: max_val = val break max_val = max(max_val, val) j += 1 i += 1 print(max_val)
h, w, m = list(map(int, input().split())) target_pos = set() target_n_row = [0] * h target_n_col = [0] * w for i in range(m): y, x = [int(x) - 1 for x in input().split()] target_n_row[y] += 1 target_n_col[x] += 1 target_pos.add((y, x)) sorted_row = [(a, i) for i, a in enumerate(target_n_row)] sorted_row.sort(reverse=True) sorted_col = [(a, i) for i, a in enumerate(target_n_col)] sorted_col.sort(reverse=True) max_r = sorted_row[0][0] max_c = sorted_col[0][0] i = 0 max_val = max_r + max_c - 1 while i < h and sorted_row[i][0] == max_r: j = 0 while j < w and sorted_col[j][0] == max_c: if not (sorted_row[i][1], sorted_col[j][1]) in target_pos: max_val = sorted_row[i][0] + sorted_col[j][0] break j += 1 i += 1 print(max_val)
p02580
h, w, m = list(map(int, input().split())) mp = set() hp = [0] * h wp = [0] * w for i in range(m): a, b = list(map(int, input().split())) mp.add((a,b)) l = [a, b] hp[l[0]-1] += 1 wp[l[1]-1] += 1 hpdex = [i for i, x in enumerate(hp) if x == max(hp)] wpdex = [i for i, x in enumerate(wp) if x == max(wp)] for i in hpdex: for j in wpdex: if (i+1, j+1) not in mp: print((max(hp) + max(wp))) exit() print((max(hp) + max(wp) - 1))
h, w, m = list(map(int, input().split())) mp = set() hp = [0] * h wp = [0] * w for i in range(m): a, b = list(map(int, input().split())) mp.add((a, b)) l = [a, b] hp[l[0]-1] += 1 wp[l[1]-1] += 1 maxhp = max(hp) maxwp = max(wp) hpdex = [i for i, x in enumerate(hp) if x == maxhp] wpdex = [i for i, x in enumerate(wp) if x == maxwp] for i in hpdex: for j in wpdex: if (i+1, j+1) not in mp: print((max(hp) + max(wp))) exit() print((max(hp) + max(wp) - 1))
p02580
h, w, m = list(map(int, input().split())) a_list = [] b_list = [] h_list = [0 for _ in range(h)] w_list = [0 for _ in range(w)] for i in range(m): a, b = list(map(int, input().split())) a_list.append([a,b]) h_list[a - 1] += 1 w_list[b - 1] += 1 w_flag = [0 for _ in range(w)] for i in range(w): if w_list[i] == max(w_list): w_flag[i] = 1 h_flag = [0 for _ in range(h)] for i in range(h): if h_list[i] == max(h_list): h_flag[i] = 1 flag = 0 for i in range(m): if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1: flag += 1 s = sum(h_flag) * sum(w_flag) print((max(h_list) + max(w_list) - 1 if flag == s else max(h_list) + max(w_list)))
h, w, m = list(map(int, input().split())) a_list = [] b_list = [] h_list = [0 for _ in range(h)] w_list = [0 for _ in range(w)] for i in range(m): a, b = list(map(int, input().split())) a_list.append([a,b]) h_list[a - 1] += 1 w_list[b - 1] += 1 h_max = max(h_list) w_max = max(w_list) w_flag = [0 for _ in range(w)] for i in range(w): if w_list[i] == w_max: w_flag[i] = 1 h_flag = [0 for _ in range(h)] for i in range(h): if h_list[i] == h_max: h_flag[i] = 1 flag = 0 for i in range(m): if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1: flag += 1 s = sum(h_flag) * sum(w_flag) print((h_max + w_max - 1 if flag == s else h_max + w_max))
p02580
from collections import Counter def solve(): H, W, M = list(map(int, input().split())) dh, dw = Counter(), Counter() used = set() for _ in range(M): h, w = list(map(int, input().split())) dh[h] += 1 dw[w] += 1 used.add((h, w)) ih = dh.most_common() iw = dw.most_common() h, counth = ih[0] w, countw = iw[0] ans = counth + countw - ((h, w) in used) for h, counth in ih: for w, countw in iw: b = counth + countw - ((h, w) in used) if b<ans: break ans = b print(ans) solve()
from collections import Counter def solve(): H, W, M = list(map(int, input().split())) dh, dw = Counter(), Counter() used = set() for _ in range(M): h, w = list(map(int, input().split())) dh[h] += 1 dw[w] += 1 used.add((h, w)) ih = dh.most_common() iw = dw.most_common() h, counth = ih[0] w, countw = iw[0] s = counth + countw ans = counth + countw - ((h, w) in used) for h, counth in ih: for w, countw in iw: if counth+countw < s or ans == s: break b = counth + countw - ((h, w) in used) ans = max(ans, b) print(ans) solve()
p02580
H, W, M = [int(i) for i in input().split()] cnt_dict_h = {} cnt_dict_w = {} bomb_list = [] for i in range(M): h, w = [int(i)-1 for i in input().split()] bomb_list.append((h,w)) cnt_dict_h.setdefault(h, 0) cnt_dict_h[h] += 1 cnt_dict_w.setdefault(w, 0) cnt_dict_w[w] += 1 max_h_key_list = [kv[0] for kv in list(cnt_dict_h.items()) if kv[1] == max(cnt_dict_h.values())] max_w_key_list = [kv[0] for kv in list(cnt_dict_w.items()) if kv[1] == max(cnt_dict_w.values())] max_h = max(cnt_dict_h.values()) max_w = max(cnt_dict_w.values()) bomb_num = max_h + max_w - 1 flag = False for h in max_h_key_list: for w in max_w_key_list: if (h, w) not in bomb_list: bomb_num = max_h + max_w break else : continue break print(bomb_num)
H, W, M = [int(i) for i in input().split()] sum_h = [0] * W sum_w = [0] * H bomb_list = set() for _ in range(M): h, w = [int(i) for i in input().split()] h -= 1 w -= 1 bomb_list.add((h,w)) sum_h[w] += 1 sum_w[h] += 1 max_sum_h = max(sum_h) max_sum_w = max(sum_w) output = max_sum_h + max_sum_w - 1 max_bombs_h = [h for h in range(H) if sum_w[h] == max_sum_w] max_bombs_w = [w for w in range(W) if sum_h[w] == max_sum_h] for h in max_bombs_h: for w in max_bombs_w: if (h, w) not in bomb_list: output = max_sum_h + max_sum_w break else: continue break print(output)
p02580
import sys input = sys.stdin.readline H,W,M=list(map(int,input().split())) B=set([tuple(map(int,input().split())) for i in range(M)]) HH=[0]*(H+1) WW=[0]*(W+1) for x,y in B: HH[x]+=1 WW[y]+=1 MAXH=max(HH) MAXW=max(WW) ANS=MAXH+MAXW-1 for i in range(1,H+1): if HH[i]!=MAXH: continue for j in range(1,W+1): if WW[j]!=MAXW: continue if (i,j) in B: continue else: print((ANS+1)) sys.exit() print(ANS)
import sys input = sys.stdin.readline H,W,M=list(map(int,input().split())) B=set([tuple(map(int,input().split())) for i in range(M)]) HH=[0]*(H+1) WW=[0]*(W+1) for x,y in B: HH[x]+=1 WW[y]+=1 MAXH=max(HH) MAXW=max(WW) ANS=MAXH+MAXW-1 HLIST=[] WLIST=[] for i in range(1,H+1): if HH[i]==MAXH: HLIST.append(i) for j in range(1,W+1): if WW[j]==MAXW: WLIST.append(j) for i in HLIST: for j in WLIST: if (i,j) in B: continue else: print((ANS+1)) sys.exit() print(ANS)
p02580
import sys,math,collections,itertools input = sys.stdin.readline H,W,M=list(map(int,input().split())) bom = [] #ボムの場所 bomH =[0]*(H+1) bomW=[0]*(W+1) for _ in range(M): h,w=list(map(int,input().split())) bom.append((h,w)) bomH[h]+=1 bomW[w]+=1 #縦の爆弾と横の爆弾は独立。爆弾を置く場所に爆弾があると-1 max_bomH = max(bomH) max_bomW = max(bomW) index_max_H = [] index_max_W = [] for ih in range(H+1): if bomH[ih] == max_bomH: index_max_H.append(ih) for iw in range(W+1): if bomW[iw] == max_bomW: index_max_W.append(iw) point = itertools.product(index_max_H,index_max_W)#置き場所候補 sPoint = set(point) sBom = set(bom) #爆弾が置き場所候補から爆弾場所を消す,すべてなくなれば、-1,どこか残れば0 for sb in sBom: sPoint.discard(sb) print((max_bomH+max_bomW - (len(sPoint)==0) ))
import sys,math,collections,itertools input = sys.stdin.readline H,W,M=list(map(int,input().split())) bom = [] #ボムの場所 bomH =[0]*(H+1) bomW=[0]*(W+1) for _ in range(M): h,w=list(map(int,input().split())) bom.append((h,w)) bomH[h]+=1 bomW[w]+=1 #縦の爆弾と横の爆弾は独立。爆弾を置く場所に爆弾があると-1 max_bomH = max(bomH) max_bomW = max(bomW) cnt = 0#爆弾が置かれた場所のbomH,bomWがともにMaxの場所の数 for h,w in bom: if bomH[h]==max_bomH and bomW[w] == max_bomW: cnt += 1 print((max_bomH +max_bomW -(cnt == bomH.count(max_bomH) * bomW.count(max_bomW))))
p02580
H, W, M = list(map(int, input().split())) cntH = {} cntW = {} bomb = set() for i in range(M): h, w = list(map(int, input().split())) bomb.add((h-1,w-1)) cntH[h-1] = cntH.get(h-1, 0) + 1 cntW[w-1] = cntW.get(w-1, 0) + 1 max_H_list = [kv[0] for kv in list(cntH.items()) if kv[1] == max(cntH.values())] max_W_list = [kv[0] for kv in list(cntW.items()) if kv[1] == max(cntW.values())] ans = max(cntH.values()) + max(cntW.values()) flag = False for i in max_H_list: for j in max_W_list: if (i, j) not in bomb: flag = True break else: continue break if not flag: ans -= 1 print(ans)
H, W, M = list(map(int, input().split())) cntH = {} cntW = {} bomb = set() for i in range(M): h, w = list(map(int, input().split())) bomb.add((h-1, w-1)) cntH[h-1] = cntH.get(h-1, 0) + 1 cntW[w-1] = cntW.get(w-1, 0) + 1 maxH, maxW = max(cntH.values()), max(cntW.values()) max_H_list = [kv[0] for kv in list(cntH.items()) if kv[1] == maxH] max_W_list = [kv[0] for kv in list(cntW.items()) if kv[1] == maxW] ans = maxH + maxW - 1 flag = False for i in max_H_list: for j in max_W_list: if (i, j) not in bomb: flag = True break else: continue break if flag: ans += 1 print(ans)
p02580
h, w, m = list(map(int, input().split())) count_row = [0 for _ in range(h)] count_col = [0 for _ in range(w)] X = [[0 for i in range(w)] for _ in range(h)] max_col = 0 max_row = 0 max_row_index = [] max_col_index = [] for i in range(m): mh, mw = list(map(int, input().split())) X[mh-1][mw-1] = 1 count_row[mh-1] += 1 count_col[mw-1] += 1 if count_row[mh-1] > max_row: max_row = count_row[mh-1] max_row_index = [mh-1] elif count_row[mh-1] == max_row: max_row_index.append(mh-1) if count_col[mw-1] > max_col: max_col = count_col[mw-1] max_col_index = [mw-1] elif count_col[mw-1] == max_col: max_col_index.append(mw-1) # max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)] # max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)] # ans = max(count_row) + max(count_col) -1 ans = max_col + max_row -1 if len(max_col_index)*len(max_row_index) > m: ans += 1 else: flag = False for i in max_row_index: for j in max_col_index: if X[i][j] == 0: ans += 1 flag = True break if flag: break print(ans)
h, w, m = list(map(int, input().split())) count_row = [0 for _ in range(h)] count_col = [0 for _ in range(w)] # X = [[0 for i in range(w)] for _ in range(h)] max_col = 0 max_row = 0 max_row_index = [] max_col_index = [] M = set() for i in range(m): mh, mw = list(map(int, input().split())) # X[mh-1][mw-1] = 1 M.add((mh-1, mw-1)) count_row[mh-1] += 1 count_col[mw-1] += 1 if count_row[mh-1] > max_row: max_row = count_row[mh-1] max_row_index = [mh-1] elif count_row[mh-1] == max_row: max_row_index.append(mh-1) if count_col[mw-1] > max_col: max_col = count_col[mw-1] max_col_index = [mw-1] elif count_col[mw-1] == max_col: max_col_index.append(mw-1) # max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)] # max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)] # ans = max(count_row) + max(count_col) -1 ans = max_col + max_row -1 if len(max_col_index)*len(max_row_index) > m: ans += 1 else: flag = False for i in max_row_index: for j in max_col_index: if (i, j) not in M: ans += 1 flag = True break if flag: break print(ans)
p02580
h, w, m = list(map(int, input().split())) count_row = [0 for _ in range(h)] count_col = [0 for _ in range(w)] # X = [[0 for i in range(w)] for _ in range(h)] M = set() for i in range(m): mh, mw = list(map(int, input().split())) # X[mh-1][mw-1] = 1 M.add((mh-1, mw-1)) # M[i] = [mh, mw] count_row[mh-1] += 1 count_col[mw-1] += 1 max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)] max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)] ans = max(count_row) + max(count_col) -1 if len(max_col_index)*len(max_row_index) > m: ans += 1 else: flag = False for i in max_row_index: for j in max_col_index: if (i, j) not in M: ans += 1 flag = True break if flag: break print(ans)
h, w, m = list(map(int, input().split())) count_row = [0 for _ in range(h)] count_col = [0 for _ in range(w)] max_col = 0 max_row = 0 max_row_index = [] max_col_index = [] M = set() for i in range(m): mh, mw = list(map(int, input().split())) M.add((mh-1, mw-1)) count_row[mh-1] += 1 count_col[mw-1] += 1 if count_row[mh-1] > max_row: max_row = count_row[mh-1] max_row_index = [mh-1] elif count_row[mh-1] == max_row: max_row_index.append(mh-1) if count_col[mw-1] > max_col: max_col = count_col[mw-1] max_col_index = [mw-1] elif count_col[mw-1] == max_col: max_col_index.append(mw-1) # max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)] # max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)] # ans = max(count_row) + max(count_col) -1 ans = max_col + max_row -1 if len(max_col_index)*len(max_row_index) > m: ans += 1 else: flag = False for i in max_row_index: for j in max_col_index: if (i, j) not in M: ans += 1 flag = True break if flag: break print(ans)
p02580
import sys H, W, M = list(map(int, input().split())) X = [set() for _ in range(H)] Y = [set() for _ in range(W)] for s in sys.stdin.readlines(): h, w = [int(x) - 1 for x in s.split()] X[h].add(w) Y[w].add(h) cntX = [] cntY = [] for x in X: cntX.append((len(x), x)) for w, y in enumerate(Y): cntY.append((len(y), w)) cntX.sort(reverse=True) cntY.sort(reverse=True) maxX = cntX[0][0] maxY = cntY[0][0] ans = 0 for cnt, x in cntX: if cnt < maxX: break for tmp, w in cntY: if tmp < maxY: break tmp += cnt - (w in x) if ans < tmp: ans = tmp if cnt == maxX + maxY: break print(ans)
import sys H, W, M = list(map(int, input().split())) bomb = [tuple([int(x) - 1 for x in s.split()]) for s in sys.stdin.readlines()] X = [0] * H Y = [0] * W for h, w in bomb: X[h] += 1 Y[w] += 1 maxX = max(X) maxY = max(Y) R = [] C = [] for h, x in enumerate(X): if x == maxX: R.append(h) for w, y in enumerate(Y): if y == maxY: C.append(w) if len(R) * len(C) > M: ans = maxX + maxY else: done = set() for r in R: for c in C: done.add((r, c)) for b in bomb: if b in done: done.remove(b) if len(done) > 0: ans = maxX + maxY else: ans = maxX + maxY - 1 print(ans)
p02580
from sys import exit, stdin # import copy from collections import deque, Counter # import numpy as np input = stdin.readline H, W, M = list(map(int, input().split())) col = Counter() row = Counter() D = Counter() for i in range(M): h, w = list(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 rtmp = row.most_common(1)[0][1] ctmp = col.most_common(1)[0][1] rmax = [] cmax = [] for r in row.most_common(): if r[1] < rtmp: break rmax.append(r) for c in col.most_common(): if c[1] < ctmp: break cmax.append(c) ridx = str(rmax[0][0]) for d in cmax: if D[ridx + str(d[0])] == 0: ans = rmax[0][1] + d[1] break else: ans = rmax[0][1] + d[1] - 1 cidx = str(cmax[0][0]) for d in rmax: if D[str(d[0]) + cidx] == 0: ans2 = cmax[0][1] + d[1] break else: ans2 = cmax[0][1] + d[1] - 1 print((max(ans, ans2)))
from sys import exit, stdin # import copy from collections import deque, Counter # import numpy as np input = stdin.readline H, W, M = list(map(int, input().split())) col = Counter() row = Counter() D = Counter() for i in range(M): h, w = input().split() row.update([h]) col.update([w]) D.update([h + w]) rtop = row.most_common(1)[0] ctop = col.most_common(1)[0] for c in col.most_common(): if c[1] < ctop[1]: break else: if D[rtop[0] + c[0]] == 0: ans = rtop[1] + c[1] break else: ans = rtop[1] + c[1] - 1 for r in row.most_common(): if r[1] < rtop[1]: break else: if D[r[0] + ctop[0]] == 0: ans2 = r[1] + ctop[1] break else: ans2 = r[1] + c[1] - 1 print((max(ans, ans2)))
p02580
H,W,m = list(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 = list(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() print((mh+mw-1))
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [[-1,10**6] for i in range(H+1)] for i in range(m): a,b = list(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 range(H+1): c[i].sort() # print(hkouho) # print(wkouho) for i in hkouho: for j in wkouho: # print(c[i],i,j,bisect_left(c[i],j)) if c[i][bisect_left(c[i],j)] != j: print((mh+mw)) exit() print((mh+mw-1))
p02580
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [[-1,10**6] for i in range(H+1)] for i in range(m): a,b = list(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 range(H+1): c[i].sort() # print(hkouho) # print(wkouho) for i in hkouho: for j in wkouho: # print(c[i],i,j,bisect_left(c[i],j)) if c[i][bisect_left(c[i],j)] != j: print((mh+mw)) exit() print((mh+mw-1))
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [[-1,10**6] for i in range(H+1)] for i in range(m): a,b = list(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: c[i].sort() for j in wkouho: if c[i][bisect_left(c[i],j)] != j: print((mh+mw)) exit() print((mh+mw-1))
p02580
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [[-1,10**6] for i in range(H+1)] for i in range(m): a,b = list(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: c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh+mw)) exit() print((mh+mw-1))
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [{-1,10**6} for i in range(H+1)] for i in range(m): a,b = list(map(int,input().split())) h[a] += 1 w[b] += 1 c[a].add(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: # c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh+mw)) exit() print((mh+mw-1))
p02580
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [{-1,10**6} for i in range(H+1)] for i in range(m): a,b = list(map(int,input().split())) h[a] += 1 w[b] += 1 c[a].add(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: # c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh+mw)) exit() print((mh+mw-1))
# from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [{-1,10**6} for i in range(H+1)] for i in range(m): a,b = list(map(int,input().split())) h[a] += 1 w[b] += 1 c[a].add(b) mh = max(h) mw = max(w) # hkouho = [] # wkouho = [] hkouho= [i for i in range(H+1) if h[i] == mh] wkouho= [i for i in range(W+1) if w[i] == mw] # 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: # c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh+mw)) exit() print((mh+mw-1))
p02580
H, W, M = list(map(int, input().split())) bomb = [0] * M H_list = [0] * H W_list = [0] * W for i in range(M): h, w = list(map(int, input().split())) bomb[i] = [h - 1, w - 1] H_list[h - 1] += 1 W_list[w - 1] += 1 #print(HW, H_list, W_list) H_max = max(H_list) W_max = max(W_list) H_index = [] W_index = [] for i in range(H): if H_list[i] == H_max: H_index.append(i) for i in range(W): if W_list[i] == W_max: W_index.append(i) x = 1 for i in H_index: for j in W_index: if [i, j] not in bomb: x = 0 print((H_max + W_max - x))
H, W, M = list(map(int, input().split())) bomb = [0] * M H_list = [0] * H W_list = [0] * W for i in range(M): h, w = list(map(int, input().split())) bomb[i] = [h - 1, w - 1] H_list[h - 1] += 1 W_list[w - 1] += 1 #print(HW, H_list, W_list) H_max = max(H_list) W_max = max(W_list) H_count = H_list.count(H_max) W_count = W_list.count(W_max) HW_max = H_max + W_max count = 0 for i, j in bomb: if H_list[i] + W_list[j] == HW_max: count += 1 if count == H_count * W_count: x = 1 else: x = 0 print((HW_max - x))
p02580
def solve(): H, W, M = list(map(int, input().split())) N = 3 * 10 ** 5 cnth = [0] * N cntw = [0] * N dic = dict() for i in range(M): h, w = [int(x) - 1 for x in input().split()] cnth[h] += 1 cntw[w] += 1 dic[(h, w)] = 1 mh = max(cnth) mw = max(cntw) Y = [] X = [] for i in range(H): if cnth[i] == mh: Y.append(i) for i in range(W): if cntw[i] == mw: X.append(i) for y in Y: for x in X: if not (y, x) in dic: return mh + mw return mh + mw - 1 print((solve()))
def solve(): H, W, M = list(map(int, input().split())) N = 3 * 10 ** 5 cnth = [0] * N cntw = [0] * N st = set() for i in range(M): h, w = [int(x) - 1 for x in input().split()] cnth[h] += 1 cntw[w] += 1 st.add((h, w)) mh = max(cnth) mw = max(cntw) Y = [] X = [] for i in range(H): if cnth[i] == mh: Y.append(i) for i in range(W): if cntw[i] == mw: X.append(i) for y in Y: for x in X: if not (y, x) in st: return mh + mw return mh + mw - 1 print((solve()))
p02580
H, W, M = list(map(int, input().split())) hw = [] sum_h = [0] * W sum_w = [0] * H for _ in range(M): h, w = list(map(int, input().split())) hw.append([h, w]) h -= 1 w -= 1 sum_h[w] += 1 sum_w[h] += 1 max_h = max(sum_h) max_w = max(sum_w) new_H = [h for h in range(H) if sum_w[h] == max_w] new_W = [w for w in range(W) if sum_h[w] == max_h] max_num = max_h + max_w - 1 for i in new_H: for j in new_W: if [i + 1, j + 1] not in hw: print((max_h + max_w)) exit() else: continue break print(max_num)
H, W, M = list(map(int, input().split())) hw = set() sum_h = [0] * W sum_w = [0] * H for _ in range(M): h, w = list(map(int, input().split())) hw.add((h, w)) h -= 1 w -= 1 sum_h[w] += 1 sum_w[h] += 1 max_h = max(sum_h) max_w = max(sum_w) new_H = [h for h in range(H) if sum_w[h] == max_w] new_W = [w for w in range(W) if sum_h[w] == max_h] max_num = max_h + max_w - 1 for i in new_H: for j in new_W: if (i + 1, j + 1) not in hw: print((max_h + max_w)) exit() else: continue break print(max_num)
p02580
H, W, M = list(map(int, input().split())) bombs = [] rows = [[]for _ in range(H)] cols = [[]for _ in range(W)] for _ in range(M): h, w = [int(x)-1 for x in input().split()] bombs.append((h, w)) rows[h].append(w) cols[w].append(h) max_row = 0 row_idx = set() for i, row in enumerate(rows): if max_row < len(row): max_row = len(row) row_idx = {i} continue elif max_row == len(row): row_idx.add(i) max_col = 0 col_idx = set() for i, col in enumerate(cols): if max_col < len(col): max_col = len(col) col_idx = {i} continue elif max_col == len(col): col_idx.add(i) ans = max_row+max_col points = len(row_idx)*len(col_idx) if M < points: print(ans) else: for i, j in bombs: if i in row_idx and j in col_idx: points -= 1 if points == 0: print((ans-1)) else: print(ans)
import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) bombs = [] rows = [[]for _ in range(H)] cols = [[]for _ in range(W)] for _ in range(M): h, w = [int(x)-1 for x in input().split()] bombs.append((h, w)) rows[h].append(w) cols[w].append(h) max_row = 0 row_idx = set() for i, row in enumerate(rows): if max_row < len(row): max_row = len(row) row_idx = {i} continue elif max_row == len(row): row_idx.add(i) max_col = 0 col_idx = set() for i, col in enumerate(cols): if max_col < len(col): max_col = len(col) col_idx = {i} continue elif max_col == len(col): col_idx.add(i) ans = max_row+max_col points = len(row_idx)*len(col_idx) if M < points: print(ans) else: for i, j in bombs: if i in row_idx and j in col_idx: points -= 1 if points == 0: print((ans-1)) else: print(ans)
p02580
H,W,M=list(map(int,input().split())) h=[0]*M w=[0]*M for i in range(M): h[i],w[i]=list(map(int,input().split())) t=[0]*H y=[0]*W for i in range(H): a = 0 for j in range(M): if h[j] == i+1: a = a+1 t[i] = a for i in range(W): a = 0 for j in range(M): if w[j] == i+1: a = a+1 y[i] = a maxt = max(t) maxy = max(y) lt=[] ly=[] for i in range(len(t)): if t[i] == maxt: lt.append(i+1) for i in range(len(y)): if y[i] == maxy: ly.append(i+1) b = 0 for i in range(M): if h[i] in lt and w[i] in ly: b = b + 1 if b == len(lt)*len(ly): print((maxt+maxy-1)) else: print((maxt+maxy))
H,W,M=list(map(int,input().split())) bomb=[] h=[0]*H w=[0]*W for i in range(M): hi,wi=list(map(int,input().split())) h[hi-1] += 1 w[wi-1] += 1 bomb.append([hi,wi]) maxh = max(h) maxw = max(w) ans = maxh + maxw lh=[] lw=[] for i in range(len(h)): if h[i] == maxh: lh.append(i+1) for i in range(len(w)): if w[i] == maxw: lw.append(i+1) a = 0 for i in range(M): if ans == h[bomb[i][0]-1]+w[bomb[i][1]-1]: a += 1 if a == len(lh)*len(lw): print((ans-1)) else: print(ans)
p02580
H,W,M = list(map(int,input().split())) T = [0] * M H_cnt = {} W_cnt = {} HW = {} for i in range(M): h,w = list(map(int,input().split())) if not h in H_cnt: H_cnt[h] = 0 if not w in W_cnt: W_cnt[w] = 0 H_cnt[h] += 1 W_cnt[w] += 1 HW[(h,w)] = 1 HL = [[h,cnt] for h,cnt in list(H_cnt.items())] WL = [[w,cnt] for w,cnt in list(W_cnt.items())] HL.sort(key=lambda x: x[1],reverse=True) WL.sort(key=lambda x: x[1],reverse=True) HS = [] max_cnt = 0 for h,cnt in HL: if max_cnt<=cnt: HS.append([h,cnt]) max_cnt = max(max_cnt,cnt) continue break WS = [] max_cnt = 0 for w,cnt in WL: if max_cnt<=cnt: WS.append([w,cnt]) max_cnt = max(max_cnt,cnt) continue break cnt = 0 ans = 0 # ここの判定を高速にする #cross_cnt = 0 #for hw in HW.keys(): # h,w = hw # if h in HS and w in WS: # cross_cnt+=1 for h,hcnt in HS: for w,wcnt in WS: if (h,w) in HW: cnt = hcnt+wcnt-1 ans = max(ans,cnt) continue cnt = hcnt+wcnt ans = max(ans,cnt) print(ans)
H,W,M = list(map(int,input().split())) T = [0] * M H_cnt = {} W_cnt = {} HW = {} for i in range(M): h,w = list(map(int,input().split())) if not h in H_cnt: H_cnt[h] = 0 if not w in W_cnt: W_cnt[w] = 0 H_cnt[h] += 1 W_cnt[w] += 1 HW[(h,w)] = 1 HL = [[h,cnt] for h,cnt in list(H_cnt.items())] WL = [[w,cnt] for w,cnt in list(W_cnt.items())] HL.sort(key=lambda x: x[1],reverse=True) WL.sort(key=lambda x: x[1],reverse=True) HS = {} max_cnth = 0 for h,cnt in HL: if max_cnth<=cnt: HS[h] = cnt max_cnth = max(max_cnth,cnt) continue break WS = {} max_cntw = 0 for w,cnt in WL: if max_cntw<=cnt: WS[w] = cnt max_cntw = max(max_cntw,cnt) continue break cnt = 0 ans = 0 # ここの判定を高速にする cross_cnt = 0 for hw in list(HW.keys()): h,w = hw if h in HS and w in WS: cross_cnt+=1 if len(WS) * len(HS)==cross_cnt: print((max_cnth+max_cntw-1)) exit() print((max_cnth+max_cntw)) #for h,hcnt in HS: # for w,wcnt in WS: # if (h,w) in HW: # cnt = hcnt+wcnt-1 # ans = max(ans,cnt) # continue # cnt = hcnt+wcnt # ans = max(ans,cnt)
p02580
from collections import defaultdict h, w, m = list(map(int, input().split())) HW = [list(map(int, input().split())) for _ in range(m)] H = [i for i, _ in HW] W = [i for _, i in HW] hd = defaultdict(int) wd = defaultdict(int) for i, j in HW: hd[i] += 1 wd[j] += 1 hd = list(hd.items()) wd = list(wd.items()) hd.sort(key=lambda x: -x[1]) wd.sort(key=lambda x: -x[1]) kouhoh = [] kouhow = [] for i, j in hd: if j < hd[0][1]: break else: kouhoh.append(i) for i, j in wd: if j < wd[0][1]: break else: kouhow.append(i) for i in kouhoh: for j in kouhow: if [i, j] not in HW: ans = hd[0][1] + wd[0][1] print(ans) exit() ans = hd[0][1] + wd[0][1] - 1 print(ans)
from collections import defaultdict h, w, m = list(map(int, input().split())) HW = [list(map(int, input().split())) for _ in range(m)] dicHW = defaultdict(set) for h, w in HW: dicHW[h].add(w) hd = defaultdict(int) wd = defaultdict(int) for i, j in HW: hd[i] += 1 wd[j] += 1 hd = list(hd.items()) wd = list(wd.items()) hd.sort(key=lambda x: -x[1]) wd.sort(key=lambda x: -x[1]) kouhoh = [] kouhow = [] for i, j in hd: if j < hd[0][1]: break else: kouhoh.append(i) for i, j in wd: if j < wd[0][1]: break else: kouhow.append(i) for i in kouhoh: for j in kouhow: if j not in dicHW[i]: ans = hd[0][1] + wd[0][1] print(ans) exit() ans = hd[0][1] + wd[0][1] - 1 print(ans)
p02580
import queue h,w,m = ( int(x) for x in input().split() ) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = ( int(x)-1 for x in input().split() ) h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i in range( h ): if h_array[i] == h_great: h_greats.append(i) for i in range( w ): if w_array[i] == w_great: w_greats.append(i) ans = h_great + w_great - 1 escaper = False for i in range( len(h_greats) ): hi = h_greats[i] for j in range( len(w_greats) ): wi = w_greats[j] if (hi,wi) not in ps: ans += 1 escaper = True break if escaper: break print(ans)
h,w,m = ( int(x) for x in input().split() ) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = ( int(x)-1 for x in input().split() ) h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print((ans-1))
p02580
h,w,m = ( int(x) for x in input().split() ) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = ( int(x)-1 for x in input().split() ) h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print((ans-1))
import sys input = sys.stdin.readline h,w,m = list(map(int,input().split())) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = [int(x) - 1 for x in input().split()] h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print((ans-1))
p02580
import sys input = sys.stdin.readline h,w,m = list(map(int,input().split())) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = [int(x) - 1 for x in input().split()] h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print((ans-1))
import sys input = sys.stdin.readline def main(): h,w,m = list(map(int,input().split())) h_array = [ 0 for _ in range(h) ] w_array = [ 0 for _ in range(w) ] ps = set() for i in range(m): hi,wi = [int(x) - 1 for x in input().split()] h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i , hi in enumerate(h_array): if hi == h_great: h_greats.append(i) for i , wi in enumerate(w_array): if wi == w_great: w_greats.append(i) ans = h_great + w_great for _h in h_greats: for _w in w_greats: if (_h,_w) in ps: continue print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
p02580
h,w,m=list(map(int,input().split())) a=[[] for i in range(m)] g=[0 for i in range(h)] r=[0 for i in range(w)] for i in range(m): x,y=list(map(int,input().split())) a[i].append(x) a[i].append(y) g[x-1]+=1 r[y-1]+=1 G=[] R=[] d=max(g) e=max(r) for i in range(h): if g[i]==d: G.append(i+1) for i in range(w): if r[i]==e: R.append(i+1) f=0 for i in range(m): q=0 p=0 x=a[i][0] y=a[i][1] k=len(G)-1 l=0 j=(k+l)//2 while k-l>1: j=(k+l)//2 if G[j]>=x: k=j else: l=j if G[l]==x or G[k]==x: p=1 k = len(R) - 1 l = 0 j = (k + l) // 2 while k - l > 1: j = (k + l) // 2 if R[j] >=y: k = j else: l = j if R[l] == y or R[k] == y: q = 1 if p==q==1: f+=1 v=1 if f!=len(G)*len(R): v=0 ans=max(g)+max(r) print((ans if v==0 else ans-1))
h,w,m=list(map(int,input().split())) a=[[] for i in range(m)] g=[0 for i in range(h)] r=[0 for i in range(w)] for i in range(m): x,y=list(map(int,input().split())) a[i].append(x) a[i].append(y) g[x-1]+=1 r[y-1]+=1 G=[0 for i in range(h)] R=[0 for i in range(w)] d=max(g) e=max(r) for i in range(h): if g[i]==d: G[i]=1 for i in range(w): if r[i]==e: R[i]=1 f=0 for i in range(m): p=0 q=0 x=a[i][0] y=a[i][1] if G[x-1]==1: p=1 if R[y-1]==1: q=1 if p==q==1: f+=1 v=1 if f!=G.count(1)*R.count(1): v=0 ans=max(g)+max(r) print((ans if v==0 else ans-1))
p02580
# -*- coding: utf-8 -*- H, W, M = list(map(int, input().split())) h_list = [0 for _ in range(H + 1)] w_list = [0 for _ in range(W + 1)] m_list = [[0 for _ in range(W + 1)] for _ in range(H + 1)] for i in range(M): h, w = list(map(int, input().split())) h_list[h] += 1 w_list[w] += 1 m_list[h][w] = 1 max_h_list = [] max_h = -1 for i in range(H + 1): if max_h == h_list[i]: max_h_list.append(i) elif max_h < h_list[i]: max_h = h_list[i] max_h_list = [i] max_w_list = [] max_w = -1 for i in range(W + 1): if max_w == w_list[i]: max_w_list.append(i) elif max_w < w_list[i]: max_w = w_list[i] max_w_list = [i] adjust_dupl = 1 for i in range(len(max_h_list)): for j in range(len(max_w_list)): if m_list[max_h_list[i]][max_w_list[j]] == 0: adjust_dupl = 0 break if adjust_dupl == 0: break print((max_h + max_w - adjust_dupl))
# -*- coding: utf-8 -*- H, W, M = list(map(int, input().split())) h_list = [0 for _ in range(H + 1)] w_list = [0 for _ in range(W + 1)] m_dic = {} for i in range(M): h, w = list(map(int, input().split())) h_list[h] += 1 w_list[w] += 1 m_dic["{}_{}".format(h, w)] = 1 max_h_list = [] max_h = -1 for i in range(H + 1): if max_h == h_list[i]: max_h_list.append(i) elif max_h < h_list[i]: max_h = h_list[i] max_h_list = [i] max_w_list = [] max_w = -1 for i in range(W + 1): if max_w == w_list[i]: max_w_list.append(i) elif max_w < w_list[i]: max_w = w_list[i] max_w_list = [i] adjust_dupl = 1 for i in range(len(max_h_list)): for j in range(len(max_w_list)): if "{}_{}".format(max_h_list[i], max_w_list[j]) not in m_dic: adjust_dupl = 0 break if adjust_dupl == 0: break print((max_h + max_w - adjust_dupl))
p02580
import itertools h, w, m = list(map(int,input().split(' '))) x = [0] * 300001 y = [0] * 300001 z = [] mx, my = 0, 0 for i in range(m): a, b = list(map(int,input().split(' '))) x[a] += 1 y[b] += 1 mx = max(mx, x[a]) my = max(my, y[b]) z.append((a, b)) x1 = [i for i in range(300001) if x[i] == mx] y1 = [i for i in range(300001) if y[i] == my] z1 = list(itertools.product(x1, y1)) if all(i in z for i in z1): print((mx + my - 1)) else: print((mx + my))
import itertools h, w, m = list(map(int,input().split(' '))) x = [0] * 300001 y = [0] * 300001 z = [] mx, my = 0, 0 for i in range(m): a, b = list(map(int,input().split(' '))) x[a] += 1 y[b] += 1 mx = max(mx, x[a]) my = max(my, y[b]) z.append((a, b)) x1 = x.count(mx) y1 = y.count(my) z1 = x1 * y1 for i, j in z: if x[i] == mx and y[j] == my: z1 -= 1 if z1: print((mx + my)) else: print((mx + my - 1))
p02580
import sys from collections import Counter def input(): return sys.stdin.readline().rstrip() def main(): H,W,m=list(map(int, input().split())) Hline=[] wline=[] blist=[] for k in range(m): h,w=list(map(int, input().split())) Hline.append(h) wline.append(w) blist.append([h,w]) hc=Counter(Hline).most_common() wc=Counter(wline).most_common() ans=hc[0][1]+wc[0][1] hl=[] wl=[] for hcc in hc: if hcc[1]!= hc[0][1]: break hl.append(hcc[0]) for wcc in wc: if wcc[1]!= wc[0][1]: break wl.append(wcc[0]) for hll in hl: for wll in wl: if [hll,wll] not in blist: print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
import sys from collections import Counter def input(): return sys.stdin.readline().rstrip() def main(): H,W,m=list(map(int, input().split())) Hline=[] wline=[] blist=dict() for k in range(m): h,w=list(map(int, input().split())) Hline.append(h) wline.append(w) blist[h*(W+2)+w]=0 hc=Counter(Hline).most_common() wc=Counter(wline).most_common() ans=hc[0][1]+wc[0][1] hl=[] wl=[] for hcc in hc: if hcc[1]!= hc[0][1]: break hl.append(hcc[0]) for wcc in wc: if wcc[1]!= wc[0][1]: break wl.append(wcc[0]) for hll in hl: for wll in wl: if hll*(W+2)+wll not in blist: print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
p02580
H, W, M = list(map(int, input().split())) visited = set() h_sum = [0] * H w_sum = [0] * W for i in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 visited.add((h, w)) h_sum[h] += 1 w_sum[w] += 1 max_h = max_w = 0 can_h = [] can_w = [] for i in range(H): max_h = max(max_h, h_sum[i]) for i in range(W): max_w = max(max_w, w_sum[i]) for i in range(H): if h_sum[i] == max_h: can_h.append(i) for i in range(W): if w_sum[i] == max_w: can_w.append(i) ans = 0 for i in can_h: for j in can_w: if (i, j) in visited: ans = max(ans, max_h+max_w-1) else: ans = max(ans, max_h+max_w) print(ans)
H, W, M = list(map(int, input().split())) visited = set() h_sum = [0] * H w_sum = [0] * W for i in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 visited.add((h, w)) h_sum[h] += 1 w_sum[w] += 1 max_h = max_w = 0 can_h = [] can_w = [] for i in range(H): max_h = max(max_h, h_sum[i]) for i in range(W): max_w = max(max_w, w_sum[i]) for i in range(H): if h_sum[i] == max_h: can_h.append(i) for i in range(W): if w_sum[i] == max_w: can_w.append(i) ans = max_h + max_w for i in can_h: for j in can_w: if (i, j) not in visited: print(ans) exit() print((ans-1))
p02580
H,W,M=list(map(int,input().split())) nh=[0]*H nw=[0]*W boms=[] for _ in range(H): boms.append([False]*W) for _ in range(M): h,w=list(map(int,input().split())) nh[h-1] += 1 nw[w-1] += 1 boms[h-1][w-1]=True maxh = max(nh) maxw = max(nw) i_indexes=[] for i in range(H): if nh[i] == maxh: i_indexes.append(i) j_indexes=[] for j in range(W): if nw[j] == maxw: j_indexes.append(j) for i in i_indexes: for j in j_indexes: if not boms[i][j]: print((maxh + maxw)) exit() print((maxh + maxw - 1))
import sys input = sys.stdin.readline H,W,M=list(map(int,input().split())) nh=[0]*H nw=[0]*W boms=set() for _ in range(M): h,w=list(map(int,input().split())) nh[h-1] += 1 nw[w-1] += 1 boms.add((h-1, w-1)) maxh = max(nh) maxw = max(nw) i_indexes=[] for i in range(H): if nh[i] == maxh: i_indexes.append(i) j_indexes=[] for j in range(W): if nw[j] == maxw: j_indexes.append(j) for i in i_indexes: for j in j_indexes: if (i,j) in boms: continue print((maxh + maxw)) exit() print((maxh + maxw - 1))
p02580
from collections import Counter from collections import defaultdict from collections import deque from heapq import heapify from heapq import heappop from heapq import heappush h,w,m=[int(x) for x in input().split()] #defaultdictにすることにより後に使うmax関数のコストを削減 hcnt=defaultdict(int) wcnt=defaultdict(int) bomb=[] #O(M) for _ in range(m): hi,wi=[int(x)-1 for x in input().split()] hcnt[hi]+=1 wcnt[wi]+=1 bomb.append([hi,wi]) #O(M) hmax=max(hcnt.values()) wmax=max(wcnt.values()) #O(M) hidx=[x for x,y in list(hcnt.items()) if y==hmax] widx=[x for x,y in list(wcnt.items()) if y==wmax] #O(M**2*) ofst=-1 for i in hidx: for j in widx: if not [i,j] in bomb: ofst=0 break print((hmax+wmax+ofst))
from collections import Counter from collections import defaultdict from collections import deque from heapq import heapify from heapq import heappop from heapq import heappush h,w,m=[int(x) for x in input().split()] #defaultdictにすることにより後に使うmax関数のコストを削減 hcnt=defaultdict(int) wcnt=defaultdict(int) #存在チェックのアクセスがリストで持たせるより高速 #リストは突っ込めないので注意(hashabeのみOK) bomb=set() #O(H) for _ in range(m): hi,wi=[int(x)-1 for x in input().split()] hcnt[hi]+=1 wcnt[wi]+=1 bomb.add((hi,wi)) #O(H) hmax=max(hcnt.values()) wmax=max(wcnt.values()) #O(H) hidx=[x for x,y in list(hcnt.items()) if y==hmax] widx=[x for x,y in list(wcnt.items()) if y==wmax] #O(H**2) ofst=-1 for i in hidx: for j in widx: if not (i,j) in bomb: ofst=0 break print((hmax+wmax+ofst))
p02580
# E from collections import Counter H,W,M=list(map(int,input().split())) h,w,bomb=[0]*M,[0]*M,[] for i in range(M): h[i],w[i]=list(map(int,input().split())) bomb.append((h[i],w[i])) most_h,most_w=Counter(h).most_common(),Counter(w).most_common() def max_values(lis): max_num=lis[0][1] for i in range(len(lis)): if lis[i][1]<max_num: res=lis[:i] break else: res=lis return res most_h=max_values(most_h) most_w=max_values(most_w) res=-1 k=0 for i,i_n in most_h: for j,j_n in most_w: if not (i,j) in bomb or k>M: res=i_n+j_n break k+=1 if res>-1: break else: res=i_n+j_n-1 print(res)
H,W,M=list(map(int,input().split())) h,w,bomb=[0]*H,[0]*W,[] for i in range(M): a,b=list(map(int,input().split())) bomb.append((a-1,b-1)) h[a-1]+=1 w[b-1]+=1 max_h=max(h) max_w=max(w) bomb_and_max=0 for i,j in bomb: if h[i]==max_h and w[j]==max_w: bomb_and_max+=1 if bomb_and_max==h.count(max_h)*w.count(max_w): print((max_h+max_w-1)) else: print((max_h+max_w))
p02580
ans=0 h,w,m=list(map(int,input().split())) d=list() from collections import defaultdict r=defaultdict(int) c=defaultdict(int) r=[0]*(h+1) c=[0]*(w+1) for i in range(m): a,b=list(map(int,input().split())) d+=(a,b), r[a]+=1 c[b]+=1 R=max(r) C=max(c) x=0 nr=r.count(R) nc=c.count(C) for i in range(m): a,b=d[i] if r[a]==R and c[b]==C: x+=1 ans=R+C if x==nr*nc: ans-=1 print(ans)
H, W, M = list(map(int, input().split())) lh = [0]*(H+1) lw = [0]*(W+1) l = [] for _ in range(M): h, w = list(map(int, input().split())) lh[h] += 1 lw[w] += 1 l += [[h, w]] maxh = max(lh) maxw = max(lw) cnt = 0 ch = lh.count(maxh) cw = lw.count(maxw) for y, x in l: if lh[y] == maxh and lw[x] == maxw: cnt += 1 ans = maxh+maxw if cnt == ch*cw: ans -= 1 print(ans)
p02580
H, W, M = list(map(int, input().split())) countH = [[h, 0] for h in range(H)] countW = [[w, 0] for w in range(W)] Bh = {} for i in range(M): h, w = list(map(int, input().split())) h, w = h-1, w-1 if h in Bh: Bh[h].add(w) else: Bh[h] = {w} countH[h][1] += 1 countW[w][1] += 1 countH.sort(reverse=True, key=lambda x: x[1]) countW.sort(reverse=True, key=lambda x: x[1]) #print(countH) #print(countW) #rint(Bh) maxh = countH[0][1] maxw = countW[0][1] ans = maxh + maxw ch = [countH[0][0]] i = 1 while i < H and countH[i][1]==maxh: ch.append(countH[i][0]) i += 1 cw = [countW[0][0]] i = 1 while i < W and countW[i][1]==maxw: cw.append(countW[i][0]) i += 1 flag = False for h in ch: for w in cw: #print(h,w) if w not in Bh[h]: flag = True break if flag: print(ans) else: print((ans-1))
H, W, M = list(map(int, input().split())) countH = [0 for h in range(H)] countW = [0 for w in range(W)] Bh = {} for i in range(M): h, w = list(map(int, input().split())) h, w = h-1, w-1 if h in Bh: Bh[h].add(w) else: Bh[h] = {w} countH[h] += 1 countW[w] += 1 maxh = 0 ch = [] maxw = 0 cw = [] for i in range(H): if maxh==countH[i]: ch.append(i) elif maxh<countH[i]: ch = [i] maxh = countH[i] for i in range(W): if maxw==countW[i]: cw.append(i) elif maxw<countW[i]: cw = [i] maxw = countW[i] #print(countH) #print(countW) #rint(Bh) ans = maxh + maxw flag = False for h in ch: for w in cw: #print(h,w) if w not in Bh[h]: flag = True break if flag: print(ans) else: print((ans-1))
p02580
from bisect import bisect_left, bisect_right def exists(ite, x): return bool(bisect_right(ite, x) - bisect_left(ite, x)) H, W, M = list(map(int,input().split())) targets = [list([int(x) - 1 for x in input().split()]) for i in range(M)] cnth = [0] * H cntw = [0] * W wlist = [[] for i in range(H)] for i in range(M): hi, wi = targets[i] cnth[hi] += 1 cntw[wi] += 1 wlist[hi].append(wi) maxhi = [] maxwi = [] maxh = max(cnth) maxw = max(cntw) for i in range(H): wlist[i].sort() if cnth[i] == maxh: maxhi.append(i) for i in range(W): if cntw[i] == maxw: maxwi.append(i) for i in range(len(maxhi)): for j in range(len(maxwi)): if not exists(wlist[maxhi[i]], maxwi[j]): print((maxh + maxw)) exit() print((maxh + maxw - 1))
from bisect import bisect_left, bisect_right H, W, M = list(map(int,input().split())) targets = [list([int(x) - 1 for x in input().split()]) for i in range(M)] cnth = [0] * H cntw = [0] * W wlist = [[] for i in range(H)] for i in range(M): hi, wi = targets[i] cnth[hi] += 1 cntw[wi] += 1 wlist[hi].append(wi) maxhi = [] maxwi = [] maxh = max(cnth) maxw = max(cntw) for i in range(H): wlist[i].sort() if cnth[i] == maxh: maxhi.append(i) for i in range(W): if cntw[i] == maxw: maxwi.append(i) for i in range(len(maxhi)): for j in range(len(maxwi)): if bisect_right(wlist[maxhi[i]], maxwi[j]) - bisect_left(wlist[maxhi[i]], maxwi[j]) == 0: print((maxh + maxw)) exit() print((maxh + maxw - 1))
p02580
H, W, M = list(map(int, input().split())) bombs = [] for i in range(H): bombs.append([False] * W) rows = [] for i in range(H): rows.append([i, 0]) cols = [] for i in range(W): cols.append([i, 0]) for i in range(M): y, x = [x - 1 for x in list(map(int, input().split()))] bombs[y][x] = True rows[y][1] += 1 cols[x][1] += 1 rows = sorted(rows, key=lambda x: x[1], reverse=True) cols = sorted(cols, key=lambda x: x[1], reverse=True) answer = 0 for row in rows: a = cols[0][1] + row[1] - (1 if bombs[row[0]][cols[0][0]] else 0) if a > answer: answer = a for col in cols: a = rows[0][1] + col[1] - (1 if bombs[rows[0][0]][col[0]] else 0) if a > answer: answer = a print(answer)
H, W, M = list(map(int, input().split())) bombs = {} rows = [] cols = [] for i in range(H): rows.append([i, 0]) for i in range(W): cols.append([i, 0]) for i in range(M): y, x = [x - 1 for x in list(map(int, input().split()))] bombs[(y,x)] = True rows[y][1] += 1 cols[x][1] += 1 rows = sorted(rows, key=lambda x: x[1], reverse=True) cols = sorted(cols, key=lambda x: x[1], reverse=True) answer = 0 for row in rows: a = cols[0][1] + row[1] - (1 if (row[0], cols[0][0]) in bombs else 0) if a > answer: answer = a for col in cols: a = rows[0][1] + col[1] - (1 if (rows[0][0], col[0]) in bombs else 0) if a > answer: answer = a print(answer)
p02580
import sys input = sys.stdin.readline h, w, m = list(map(int,input().split())) row = [0]*h col = [0]*w enemy = [] for i in range(m): hh, ww = [int(x)-1 for x in input().split()] row[hh] += 1 col[ww] += 1 enemy.append((hh,ww)) enemy = set(enemy) rmax = max(row) cmax = max(col) rind = [i for i,v in enumerate(row) if v == rmax] cind = [i for i,v in enumerate(col) if v == cmax] ans = 0 for r in rind: for c in cind: if (r, c) in enemy: ans = max(ans, rmax+cmax-1) else: ans = max(ans, rmax+cmax) print(ans)
import sys input = sys.stdin.readline h, w, m = list(map(int,input().split())) row = [0]*h col = [0]*w enemy = [] for i in range(m): hh, ww = [int(x)-1 for x in input().split()] row[hh] += 1 col[ww] += 1 enemy.append((hh,ww)) enemy = set(enemy) rmax = max(row) cmax = max(col) on_r = row.count(rmax) on_c = col.count(cmax) on = 0 for hh, ww in enemy: if row[hh] == rmax and col[ww] == cmax: on += 1 if on == on_r*on_c: print((rmax+cmax-1)) else: print((rmax+cmax))
p02580
H, W, M = list(map(int, input().split())) h = [0] * (H + 1) w = [0] * (W + 1) boms = set() for _ in range(M): x, y = list(map(int, input().split())) h[x - 1] += 1 w[y - 1] += 1 boms.add((x, y)) h_max = max(h) w_max = max(w) h_idx = [x + 1 for x, y in enumerate(h) if y == h_max] w_idx = [x + 1 for x, y in enumerate(w) if y == w_max] def solve(h_max, w_max, boms): minus = [] for x in h_idx: for y in w_idx: if (x, y) in boms: minus.append(-1) else: minus.append(0) return h_max + w_max + max(minus) print((solve(h_max, w_max, boms)))
H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W boms = set() for _ in range(M): x, y = list(map(int, input().split())) h[x - 1] += 1 w[y - 1] += 1 boms.add((x, y)) h_max = max(h) w_max = max(w) h_idx = [x + 1 for x, y in enumerate(h) if y == h_max] w_idx = [x + 1 for x, y in enumerate(w) if y == w_max] minus = -1 for x in h_idx: for y in w_idx: if not (x, y) in boms: minus = 0 break print((h_max + w_max + minus))
p02580
h, w, m = list(map(int, input().split())) nh = [0 for i in range(h)] nw = [0 for j in range(w)] bomb = [[] for i in range(h)] for i in range(m): inp = list(map(int, input().split())) nh[inp[0] - 1] += 1 nw[inp[1] - 1] += 1 bomb[inp[0]-1].append(inp[1]-1) maxh = max(nh) maxw = max(nw) counth = 0 countw = 0 hlis = [] wlis = [] for j in range(h): if nh[j] == maxh: counth += 1 hlis.append(j) for i in range(w): if nw[i] == maxw: countw += 1 wlis.append(i) if counth * countw > m: print((maxh + maxw)) exit() else: for j in hlis: for i in wlis: flag = False if i in bomb[j]: flag = True if not flag: print((maxh + maxw)) exit() else: print((maxh + maxw - 1))
h, w, m = list(map(int, input().split())) nh = [0 for i in range(h)] nw = [0 for j in range(w)] bomb = [set() for i in range(h)] for i in range(m): inp = list(map(int, input().split())) nh[inp[0] - 1] += 1 nw[inp[1] - 1] += 1 bomb[inp[0]-1].add(inp[1]-1) maxh = max(nh) maxw = max(nw) counth = 0 countw = 0 hlis = [] wlis = [] for j in range(h): if nh[j] == maxh: counth += 1 hlis.append(j) for i in range(w): if nw[i] == maxw: countw += 1 wlis.append(i) if counth * countw > m: print((maxh + maxw)) exit() else: for j in hlis: for i in wlis: flag = False if i in bomb[j]: flag = True if not flag: print((maxh + maxw)) exit() else: print((maxh + maxw - 1))
p02580
# coding: utf-8 # Your code here! # 幅優先探索(行きがけ) import collections import sys import copy import re import math import itertools def I(): return int(sys.stdin.readline().rstrip()) 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()) def main(): H, W, M = LI() HList = [0]*H WList = [0]*W graph = [[0 for _ in range(W)] for _ in range(H)] for m in range(M): h, w = LI() HList[h-1] += 1 WList[w-1] += 1 graph[h-1][w-1] += 1 Hmax = max(HList) Wmax = max(WList) HIndex = [i for i, v in enumerate(HList) if v == Hmax] WIndex = [i for i, v in enumerate(WList) if v == Wmax] ans = Hmax + Wmax for h in HIndex: for w in WIndex: if graph[h][w] == 0: print(ans) return print((ans-1)) if __name__ == '__main__': main()
# coding: utf-8 # Your code here! # 幅優先探索(行きがけ) import collections import sys import copy import re import math import itertools def I(): return int(sys.stdin.readline().rstrip()) 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()) def main(): H, W, M = LI() HList = [0]*H WList = [0]*W graph = set() for m in range(M): h, w = LI() HList[h-1] += 1 WList[w-1] += 1 graph.add((h-1, w-1)) Hmax = max(HList) Wmax = max(WList) HIndex = [i for i, v in enumerate(HList) if v == Hmax] WIndex = [i for i, v in enumerate(WList) if v == Wmax] ans = Hmax + Wmax for h in HIndex: for w in WIndex: if not (h, w) in graph: print(ans) return print((ans-1)) if __name__ == '__main__': main()
p02580
from collections import Counter import sys H,W,M,*hw = list(map(int,open(0).read().split())) h = hw[::2] w = hw[1::2] hw_set = set((hi,wi) for hi,wi in zip(h,w)) raw_count = Counter(h) col_count = Counter(w) raw_max = raw_count.most_common()[0][1] col_max = col_count.most_common()[0][1] ans = 0 for hi, rcount in raw_count.most_common(): if rcount<raw_max:break for wi, ccount in col_count.most_common(): if ccount<col_max: break if (hi,wi) in hw_set: ans = raw_max + col_max - 1 else: print((raw_max + col_max)) sys.exit() print(ans)
from collections import Counter import sys H,W,M,*hw = list(map(int,open(0).read().split())) h = hw[::2] w = hw[1::2] hw_set = set((hi,wi) for hi,wi in zip(h,w)) raw_count = Counter(h).most_common() col_count = Counter(w).most_common() raw_max = raw_count[0][1] col_max = col_count[0][1] ans = 0 for hi, rcount in raw_count: if rcount<raw_max:break for wi, ccount in col_count: if ccount<col_max: break if (hi,wi) in hw_set: ans = raw_max + col_max - 1 else: print((raw_max + col_max)) sys.exit() print(ans)
p02580
H, W, M = list(map(int, input().split())) bomb = [] row = [0] * H column = [0] * W for i in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 bomb.append([h, w]) row[h] += 1 column[w] += 1 row_max = max(row) col_max = max(column) r_check = [] c_check = [] for i in range(H): if row[i] == row_max: r_check.append(i) for i in range(W): if column[i] == col_max: c_check.append(i) num = len(r_check) * len(c_check) ans = row_max + col_max - 1 flg = False if M < num: ans = row_max + col_max else: for r in r_check: if flg: break for c in c_check: if not [r, c] in bomb: ans = row_max + col_max flg = True break print(ans)
H, W, M = list(map(int, input().split())) bomb = set() row = [0] * H column = [0] * W for i in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 bomb.add((h, w)) row[h] += 1 column[w] += 1 row_max = max(row) col_max = max(column) r_check = [] c_check = [] for i in range(H): if row[i] == row_max: r_check.append(i) for i in range(W): if column[i] == col_max: c_check.append(i) num = len(r_check) * len(c_check) ans = row_max + col_max - 1 flg = False if M < num: ans += 1 else: for r in r_check: if flg: break for c in c_check: if not (r, c) in bomb: ans += 1 flg = True break print(ans)
p02580
import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) h_count = [0]*H w_count = [0]*W HW = [tuple(map(int, input().split())) for _ in range(M)] map = [[False]*W for _ in range(H)] for h, w in HW: h_count[h-1] += 1 w_count[w-1] += 1 map[h-1][w-1] = True h_max, w_max = 0, 0 hs, ws = [], [] for i in range(H): if h_max < h_count[i]: h_max = h_count[i] hs = [i] elif h_max == h_count[i]: hs.append(i) for i in range(W): if w_max < w_count[i]: w_max = w_count[i] ws = [i] elif w_max == w_count[i]: ws.append(i) cnt = len(hs)*len(ws) for h in hs: for w in ws: if not map[h][w]: print((h_max+w_max)) sys.exit() print((h_max+w_max-1))
import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) h_count = [0]*H w_count = [0]*W HW = [tuple(map(int, input().split())) for _ in range(M)] for h, w in HW: h_count[h-1] += 1 w_count[w-1] += 1 h_max, w_max = 0, 0 hs, ws = [], [] for i in range(H): if h_max < h_count[i]: h_max = h_count[i] hs = [i] elif h_max == h_count[i]: hs.append(i) for i in range(W): if w_max < w_count[i]: w_max = w_count[i] ws = [i] elif w_max == w_count[i]: ws.append(i) HW = set(HW) for h in hs: for w in ws: if (h+1, w+1) not in HW: print((h_max+w_max)) sys.exit() print((h_max+w_max-1))
p02580
import itertools H,W,M = list(map(int,input().split())) lsx = [0] + [0]*H lsy = [0] + [0]*W lsxy = [] for i in range(M): x,y = list(map(int,input().split())) lsx[x] += 1 lsy[y] += 1 lsxy.append((x,y)) maxx = max(lsx) maxy = max(lsy) lsmaxx = [i for i, x in enumerate(lsx) if x == maxx] lsmaxy = [i for i, x in enumerate(lsy) if x == maxy] lsp = list(itertools.product(lsmaxx,lsmaxy)) ii = 0 for i in range(M): if lsxy[i] in lsp: ii += 1 if len(lsp)-ii == 0: factor = 1 else: factor = 0 print((maxx+maxy-factor))
import itertools H,W,M = list(map(int,input().split())) lsx = [0] + [0]*H lsy = [0] + [0]*W lsxy = [] for i in range(M): x,y = list(map(int,input().split())) lsx[x] += 1 lsy[y] += 1 lsxy.append((x,y)) maxx = max(lsx) maxy = max(lsy) lsmaxx = [i for i, x in enumerate(lsx) if x == maxx] lsmaxy = [i for i, x in enumerate(lsy) if x == maxy] lsp = list(itertools.product(lsmaxx,lsmaxy)) factor = 1 for i in lsp: if not i in lsxy: factor = 0 break print((maxx+maxy-factor))
p02580
H,W,M = list(map(int,input().split())) lsx = [0] + [0]*H lsy = [0] + [0]*W lsxy = [] for i in range(M): x,y = list(map(int,input().split())) lsx[x] += 1 lsy[y] += 1 lsxy.append([x,y]) maxx = max(lsx) maxy = max(lsy) lsmaxx = [i for i, x in enumerate(lsx) if x == maxx] lsmaxy = [i for i, x in enumerate(lsy) if x == maxy] lenlen = len(lsmaxx)*len(lsmaxy) factor = 1 for i in lsmaxx: for j in lsmaxy: if not [i,j] in lsxy: factor = 0 break if factor == 0: break print((maxx+maxy-factor))
H,W,M = list(map(int,input().split())) lsx = [0] + [0]*H lsy = [0] + [0]*W lsxy = [] for i in range(M): x,y = list(map(int,input().split())) lsx[x] += 1 lsy[y] += 1 lsxy.append([x,y]) maxx = max(lsx) maxy = max(lsy) cx = lsx.count(maxx) cy = lsy.count(maxy) al = cx*cy for i in range(M): if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy: al -= 1 if al == 0: factor = 1 else: factor = 0 print((maxx+maxy-factor))
p02580
from itertools import product H,W,M = list(map(int,input().split())) h_list = [0] * M w_list = [0] * M for m in range(M): h_list[m],w_list[m] = list(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) cnt = 0 for i,j in zip(h_list,w_list): if i-1 in set(h_ans) and j-1 in set(w_ans): cnt += 1 if cnt == len(h_ans) * len(w_ans): print((h_max + w_max - 1)) else: print((h_max + w_max))
from itertools import product H,W,M = list(map(int,input().split())) h_list = [0] * M w_list = [0] * M for m in range(M): h_list[m],w_list[m] = list(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) cnt = 0 h_set = set(h_ans) w_set = set(w_ans) for i,j in zip(h_list,w_list): if i-1 in h_set and j-1 in w_set: cnt += 1 if cnt == len(h_ans) * len(w_ans): print((h_max + w_max - 1)) else: print((h_max + w_max))
p02580
from collections import defaultdict def solve(H, M, W, bombs): count_h = defaultdict(int) count_w = defaultdict(int) for b in bombs: h = str(b[0]) count_h[h] += 1 w = str(b[1]) count_w[w] += 1 max_h = max(count_h.values()) max_w = max(count_w.values()) points_h = [int(k) for k in list(count_h.keys()) if count_h[k] == max_h] points_w = [int(k) for k in list(count_w.keys()) if count_w[k] == max_w] ans = max_h + max_w if _find_cross_bomb(points_h, points_w, bombs): ans -= 1 print(ans) def _find_cross_bomb(points_h, points_w, bombs): c = 0 for b in bombs: if (b[0]) in points_h: if (b[1]) in points_w: c += 1 return c == len(points_h) * len(points_w) if __name__ == "__main__": H, W, M = list(map(int, input().split())) bombs = [list([int(x) - 1 for x in input().split()]) for i in range(M)] solve(H, M, W, bombs)
import sys def solve(): readline = sys.stdin.readline H, W, M = list(map(int, readline().split())) h = [0] * H w = [0] * W b = set() for _ in range(M): y, x = list(map(int, readline().split())) x -= 1 y -= 1 h[y] += 1 w[x] += 1 b.add(y * W + x) h = sorted(zip(h, list(range(H))), reverse=True) ans = 0 for i in range(W): x = w[i] for y, j in h: if x + y > ans: if j * W + i in b: ans = x + y - 1 else: ans = x + y break else: break print(ans) if __name__ == '__main__': solve()
p02580
import sys import math import collections import bisect import itertools # import numpy as np sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 # MOD = 10 ** 9 + 7 MOD = 998244353 ni = lambda: int(sys.stdin.readline().rstrip()) ns = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()]) # ===CODE=== def main(): h, w, m = ns() hm = [0 for _ in range(h)] wm = [0 for _ in range(w)] m_pos = {} for _ in range(m): hi, wi = ns() hi, wi = hi - 1, wi - 1 hm[hi] += 1 wm[wi] += 1 if hi in list(m_pos.keys()): m_pos[hi].add(wi) else: m_pos[hi] = {wi} h_max = [] w_max = [] tmax = -1 for i, hi in enumerate(hm): if hi > tmax: tmax = hi h_max = [i] elif hi == tmax: h_max.append(i) tmax = -1 for i, wi in enumerate(wm): if wi > tmax: tmax = wi w_max = [i] elif wi == tmax: w_max.append(i) ans = 0 for hi in h_max: for wi in w_max: if wi in m_pos[hi]: ans = max(ans, hm[hi] + wm[wi] - 1) else: ans = max(ans, hm[hi] + wm[wi]) print(ans) if __name__ == '__main__': main()
import sys import math import collections import bisect import itertools # import numpy as np sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 # MOD = 10 ** 9 + 7 MOD = 998244353 ni = lambda: int(sys.stdin.readline().rstrip()) ns = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()]) # ===CODE=== def main(): h, w, m = ns() hm = [0 for _ in range(h)] wm = [0 for _ in range(w)] m_pos = {} for _ in range(m): hi, wi = ns() hi, wi = hi - 1, wi - 1 hm[hi] += 1 wm[wi] += 1 if hi in list(m_pos.keys()): m_pos[hi].add(wi) else: m_pos[hi] = {wi} h_max = [] w_max = [] tmax = -1 for i, hi in enumerate(hm): if hi > tmax: tmax = hi h_max = [i] elif hi == tmax: h_max.append(i) tmax = -1 for i, wi in enumerate(wm): if wi > tmax: tmax = wi w_max = [i] elif wi == tmax: w_max.append(i) ans = 0 breakflg = False for hi in h_max: for wi in w_max: if wi in m_pos[hi]: ans = max(ans, hm[hi] + wm[wi] - 1) else: ans = max(ans, hm[hi] + wm[wi]) breakflg = True break if breakflg: break print(ans) if __name__ == '__main__': main()
p02580
H, W, M = list(map(int, input().split())) bomb = [list(map(int, input().split())) for i in range(M)] column_cnt = [0]*W row_cnt = [0]*H for i in range(M): row_cnt[bomb[i][0]-1] += 1 column_cnt[bomb[i][1]-1] += 1 row_max_index = row_cnt.index(max(row_cnt)) column_max_index = column_cnt.index(max(column_cnt)) bomb_cnt_max = 0 for i in range(M): bomb_cnt = row_cnt[bomb[i][0]-1] + column_cnt[column_max_index] if [bomb[i][0], column_max_index+1] in bomb: bomb_cnt -= 1 bomb_cnt_max = max(bomb_cnt_max, bomb_cnt) bomb_cnt = column_cnt[bomb[i][1]-1] + row_cnt[row_max_index] if [row_max_index+1, bomb[i][1]] in bomb: bomb_cnt -= 1 bomb_cnt_max = max(bomb_cnt_max, bomb_cnt) print(bomb_cnt_max)
H, W, M = list(map(int, input().split())) bomb = set([tuple(map(int, input().split())) for i in range(M)]) column_cnt = [0]*W row_cnt = [0]*H for bomb_pos in bomb: row_cnt[bomb_pos[0]-1] += 1 column_cnt[bomb_pos[1]-1] += 1 row_max_index = row_cnt.index(max(row_cnt)) column_max_index = column_cnt.index(max(column_cnt)) bomb_cnt_max = 0 for bomb_pos in bomb: bomb_cnt = row_cnt[bomb_pos[0]-1] + column_cnt[column_max_index] if (bomb_pos[0], column_max_index+1) in bomb: bomb_cnt -= 1 bomb_cnt_max = max(bomb_cnt_max, bomb_cnt) bomb_cnt = column_cnt[bomb_pos[1]-1] + row_cnt[row_max_index] if (row_max_index+1, bomb_pos[1]) in bomb: bomb_cnt -= 1 bomb_cnt_max = max(bomb_cnt_max, bomb_cnt) print(bomb_cnt_max)
p02580
from collections import Counter def main(H, W, M, obj_h, obj_w, obj): c_h = Counter(obj_h) c_w = Counter(obj_w) max_h = max(c_h.values()) max_w = max(c_w.values()) lst_h = [kv[0] for kv in list(c_h.items()) if kv[1] == max_h] lst_w = [kv[0] for kv in list(c_w.items()) if kv[1] == max_w] for h in lst_h: for w in lst_w: if [h, w] not in obj: print((max_h + max_w)) exit() else: print((max_h + max_w - 1)) if __name__ == '__main__': H, W, M = list(map(int, input().split())) obj = [] obj_h = [] obj_w = [] for _ in range(M): i = list(map(int, input().split())) obj.append(i) obj_h.append(i[0]) obj_w.append(i[1]) main(H, W, M, obj_h, obj_w, obj)
from collections import Counter def main(H, W, M, obj_h, obj_w, obj): c_h = Counter(obj_h) c_w = Counter(obj_w) max_h = max(c_h.values()) max_w = max(c_w.values()) lst_h = [kv[0] for kv in list(c_h.items()) if kv[1] == max_h] lst_w = [kv[0] for kv in list(c_w.items()) if kv[1] == max_w] for h in lst_h: for w in lst_w: if (h, w) not in obj: print((max_h + max_w)) exit() else: print((max_h + max_w - 1)) if __name__ == '__main__': H, W, M = list(map(int, input().split())) obj = set() obj_h = [] obj_w = [] for _ in range(M): i = list(map(int, input().split())) obj.add(tuple(i)) obj_h.append(i[0]) obj_w.append(i[1]) main(H, W, M, obj_h, obj_w, obj)
p02580
h,w,m=list(map(int,input().split())) HW=[list(map(int,input().split())) for _ in range(m)] H,W=[0 for _ in range(h)],[0 for _ in range(w)] for i,j in HW: i,j=i-1,j-1 H[i] +=1 W[j] +=1 max_h,max_w=max(H),max(W) ans=max_h+max_w cnt=H.count(max_h)*W.count(max_w) for i,j in HW: if H[i-1]==max_h and W[j-1]==max_w: cnt -=1 print((ans if cnt!=0 else ans-1))
h,w,m=list(map(int,input().split())) HW=[list(map(int,input().split())) for _ in range(m)] H,W=[0]*h,[0]*w for i,j in HW: H[i-1] +=1 W[j-1] +=1 max_h,max_w=max(H),max(W) ans=max_h+max_w cnt=H.count(max_h)*W.count(max_w) for i,j in HW: if H[i-1]==max_h and W[j-1]==max_w: cnt -=1 print((ans if cnt!=0 else ans-1))
p02580
H,W,M = list(map(int, input().split())) hs = [0] * H ws = [0] * W s = set() for i in range(M): h,w = list(map(int, input().split())) h -= 1 w -= 1 hs[h] += 1 ws[w] += 1 s.add((h,w)) mh = 0 mw = 0 for i in range(H): mh = max(mh,hs[i]) for j in range(W): mw = max(mw,ws[j]) i_s = list() j_s = list() for i in range(H): if mh == hs[i]: i_s.append(i) for j in range(W): if mw == ws[j]: j_s.append(j) ans = mh + mw for i in i_s: for j in j_s: if (i,j) in s: continue print(ans) exit() ans -= 1 print(ans)
H,W,M = list(map(int, input().split())) hs = [0] * H ws = [0] * W s = set() for i in range(M): h,w = list(map(int, input().split())) h -= 1 w -= 1 hs[h] += 1 ws[w] += 1 s.add((h,w)) mh = 0 mw = 0 for i in range(H): mh = max(mh, hs[i]) for j in range(W): mw = max(mw, ws[j]) l_s = list() j_s = list() for i in range(H): if mh == hs[i]: l_s.append(i) for j in range(W): if mw == ws[j]: j_s.append(j) ans = mh+mw for i in l_s: for j in j_s: if (i,j) in s: continue print(ans) exit() ans -= 1 print(ans)
p02580
H,W,M = list(map(int, input().split())) hs = [0] * H ws = [0] * W s = set() for i in range(M): h,w = list(map(int, input().split())) h -= 1 w -= 1 hs[h] += 1 ws[w] += 1 s.add((h,w)) mh = 0 mw = 0 for i in range(H): mh = max(mh, hs[i]) for j in range(W): mw = max(mw, ws[j]) i_s = list() j_s = list() for i in range(H): if hs[i] == mh: i_s.append(i) for j in range(W): if ws[j] == mw: j_s.append(j) ans = mh + mw for i in i_s: for j in j_s: if (i,j) in s: continue print(ans) exit() ans -= 1 print(ans)
H,W,M = list(map(int, input().split())) hs = [0] * H ws = [0] * W s = set() for i in range(M): h,w = list(map(int, input().split())) h -= 1 w -= 1 s.add((h,w)) hs[h] += 1 ws[w] += 1 mh = 0 mw = 0 for i in range(H): mh = max(mh, hs[i]) for j in range(W): mw = max(mw, ws[j]) i_s = list() j_s = list() for i in range(H): if mh == hs[i]: i_s.append(i) for j in range(W): if mw == ws[j]: j_s.append(j) ans = mh + mw for i in i_s: for j in j_s: if (i,j) in s: continue print(ans) exit() ans -= 1 print(ans)
p02580
h,w,m=list(map(int,input().split())) bomb=[list(map(int,input().split())) for _ in range(m)] a=[0 for i in range(h+1)] b=[0 for _ in range(w+1)] for i in range(m): a[bomb[i][0]]+=1 b[bomb[i][1]]+=1 am=max(a) bm=max(b) aa=[i for i, x in enumerate(a) if x==am] bb=[i for i, x in enumerate(b) if x==bm] if len(aa)*len(bb)>m: print((am+bm)) exit() for i in aa: for j in bb: if [i,j] in bomb: continue else: print((am+bm)) exit() print((am+bm-1))
h,w,m=list(map(int,input().split())) bomb=[list(map(int,input().split())) for _ in range(m)] #bombの位置 a=[0 for i in range(h+1)] #各行のbombの個数 b=[0 for _ in range(w+1)] #各列のbombの個数 for i in range(m): a[bomb[i][0]]+=1 b[bomb[i][1]]+=1 am=max(a) #1行にあるbombの最大値 bm=max(b) #1列にあるbombの最大値 hmax=[0]*(h+1) #最大値をとるh全部 wmax=[0]*(w+1) #最大値をとるw全部 for i in range(h+1): if am==a[i]: hmax[i]+=1 for i in range(w+1): if bm==b[i]: wmax[i]+=1 ans=am+bm #基本解 k=sum(hmax)*sum(wmax) if k>m: #鳩ノ巣原理 print(ans) exit() for i in bomb: if hmax[i[0]]==1 and wmax[i[1]]==1: k-=1 if k==0: print((ans-1)) else: print(ans)
p02580
H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W Mem = [tuple(map(int, input().split())) for _ in range(M) ] for i, j in Mem: h[i-1] += 1 w[j-1] += 1 maxh = max(h) maxw = max(w) listh = [i for i, v in enumerate(h, 1) if v == maxh] listw = [j for j, v in enumerate(w, 1) if v == maxw] cnt = len(listh) * len(listw) for i, j in Mem: if i in listh and j in listw: cnt -= 1 if cnt: ans = maxh + maxw else: ans = maxh + maxw - 1 print(ans)
h,w,m=list(map(int,input().split())) item=[list(map(int,input().split())) for i in range(m)] row=[0]*h col=[0]*w for i in range(m): x,y=item[i] row[x-1]+=1 col[y-1]+=1 mr,mc=max(row),max(col) xr=set([i for i in range(h) if row[i]==mr]) xc=set([i for i in range(w) if col[i]==mc]) check=len(xr)*len(xc) for i in range(m): r,c=item[i] if r-1 in xr and c-1 in xc: check-=1 print((mr+mc if check>0 else mr+mc-1))
p02580
H, W, M = list(map(int, input().split())) bombs = [list([int(x) - 1 for x in input().split()]) for _ in range(M)] field = [[False] * W for _ in range(H)] max_hw = max(H, W) H_count = {i:0 for i in range(max_hw)} W_count = {i:0 for i in range(max_hw)} for i in range(M): h, w = bombs[i] field[h][w] = True H_count[h] += 1 W_count[w] += 1 A = max(H_count.values()) B = max(W_count.values()) Ah = [] Bw = [] for i in range(max_hw): if H_count[i] == A: Ah.append(i) if W_count[i] == B: Bw.append(i) ans = A + B FLG = True for h in Ah: for w in Bw: if not field[h][w]: FLG = False break if not FLG: break print((ans - FLG))
H, W, M = list(map(int, input().split())) bombs = set() H_count = [0 for i in range(H)] W_count = [0 for i in range(W)] for i in range(M): h, w = [int(x) - 1 for x in input().split()] bombs.add((h, w)) H_count[h] += 1 W_count[w] += 1 A = max(H_count) B = max(W_count) Ah = [] Bw = [] for i, count in enumerate(H_count): if count == A: Ah.append(i) for i, count in enumerate(W_count): if count == B: Bw.append(i) ans = A + B for h in Ah: for w in Bw: if (h, w) not in bombs: print(ans) exit() print((ans - 1))
p02580
def my_index(l, x): return [i for i, _x in enumerate(l) if _x == x] H,W,M=list(map(int,input().split())) P=list() P_X=[0]*(H+1) P_Y=[0]*(W+1) for m in range(M): P.append(list(map(int,input().split()))) P_X[P[m][0]]+=1 P_Y[P[m][1]]+=1 Max_X=max(P_X) Max_Y=max(P_Y) max_X=my_index(P_X,Max_X) max_Y=my_index(P_Y,Max_Y) m_count=0 for k in P: if k[0] in max_X and k [1] in max_Y: m_count += 1 if m_count==len(max_X)*len(max_Y): answer=Max_X+Max_Y-1 else: answer=Max_X+Max_Y print(answer)
def my_index(l, x): return [i for i, _x in enumerate(l) if _x == x] H,W,M=list(map(int,input().split())) P=list() P_X=[0]*(H+1) P_Y=[0]*(W+1) for m in range(M): P.append(list(map(int,input().split()))) P_X[P[m][0]]+=1 P_Y[P[m][1]]+=1 Max_X=max(P_X) Max_Y=max(P_Y) max_X=my_index(P_X,Max_X) max_Y=my_index(P_Y,Max_Y) m_count=0 for k in P: if P_X[k[0]] == Max_X and P_Y[k [1]] == Max_Y: m_count += 1 if m_count==len(max_X)*len(max_Y): answer=Max_X+Max_Y-1 else: answer=Max_X+Max_Y print(answer)
p02580
H, W, M = list(map(int, input().split())) A = [list(map(int, input().split())) for i in range(M)] takasa = [0]*(H) haba = [0]*(W) for i in range(M): takasa[A[i][0]-1] += 1 haba[A[i][1]-1] += 1 mt = max(takasa) mh = max(haba) ct = takasa.count(mt) ch = haba.count(mh) a = 0 for i in range(M): if takasa[A[i][0]-1] == mt and haba[A[i][1]-1] == mh: a += 1 if a == ct*ch: print((mt+mh-1)) else: print((mt+mh))
H, W, M = list(map(int, input().split())) A = [list(map(int, input().split())) for i in range(M)] hl, wl = [0]*H, [0]*W for i,j in A: hl[i-1] += 1 wl[j-1] += 1 mt,mh = max(hl),max(wl) a = 0 for i,j in A: if hl[i-1] == mt and wl[j-1] == mh: a += 1 print((mt+mh-1 if a == hl.count(mt) * wl.count(mh) else mt+mh))
p02580
H,W,M=list(map(int,input().split())) mine=[list(map(int,input().split()))for i in range(M)] mine_h=[0]*H mine_w=[0]*W ans=0 val=-1 for i in range(M): mine_h[mine[i][0]-1]+=1 mine_w[mine[i][1]-1]+=1 max_h=max(mine_h) max_w=max(mine_w) h_index=[i+1 for i, x in enumerate(mine_h)if x == max_h] w_index=[i+1 for i, x in enumerate(mine_w)if x == max_w] for i in h_index: for j in w_index: if [i,j] in mine: continue else: val=0 break print((max_h+max_w+val))
H,W,M=list(map(int,input().split())) mine_h=[0]*H mine_w=[0]*W val=-1 mine=set() for i in range(M): a,b=list(map(int,input().split())) mine_h[a-1]+=1 mine_w[b-1]+=1 mine.add((a,b)) max_h=max(mine_h) max_w=max(mine_w) h_index=[i+1 for i, x in enumerate(mine_h)if x == max_h] w_index=[i+1 for i, x in enumerate(mine_w)if x == max_w] for i in h_index: for j in w_index: if (i,j) in mine: continue else: val=0 break print((max_h+max_w+val))
p02580
h,w,m=list(map(int,input().split())) bomb=[] x=[0]*(h+1) y=[0]*(w+1) for i in range(m): h1,w1=list(map(int,input().split())) x[h1]+=1 y[w1]+=1 bomb.append((h1,w1)) maxx=max(x) maxy=max(y) r=[] c=[] for i in range(1,h+1): if x[i]==maxx: r.append(i) for j in range(1,w+1): if y[j]==maxy: c.append(j) for j in r: for k in c: if (j,k) not in bomb: print((maxx+maxy)) exit() print((maxx+maxy-1))
h,w,m=list(map(int,input().split())) bomb=[] x=[0]*(h+1) y=[0]*(w+1) for i in range(m): h1,w1=list(map(int,input().split())) x[h1]+=1 y[w1]+=1 bomb.append((h1,w1)) maxx=max(x) maxy=max(y) r=[] c=[] bomb=set(bomb) for i in range(1,h+1): if x[i]==maxx: r.append(i) for j in range(1,w+1): if y[j]==maxy: c.append(j) for j in r: for k in c: if (j,k) not in bomb: print((maxx+maxy)) exit() print((maxx+maxy-1))
p02580
H,W,M = list(map(int,input().split())) P = [0]*(H+1) Q = [0]*(W+1) A = set() for k in range(M): a,b = list(map(int,input().split())) P[a] += 1 Q[b] += 1 A.add((a,b)) Pindex = [i for i, v in enumerate(P) if v == max(P)] Qindex = [i for i, v in enumerate(Q) if v == max(Q)] Pmax = P[Pindex[0]] Qmax = Q[Qindex[0]] ans = Pmax+Qmax-1 key = 0 for x in Pindex: for y in Qindex: if (x,y) not in A: ans += 1 key = 1 break if key == 1: break print(ans)
H,W,M = list(map(int,input().split())) P = [0]*(H+1) Q = [0]*(W+1) A = set() for k in range(M): a,b = list(map(int,input().split())) P[a] += 1 Q[b] += 1 A.add((a,b)) Pmax = max(P) Qmax = max(Q) Pindex = [] Qindex = [] for i in range(H+1): if P[i] == Pmax: Pindex.append(i) for i in range(W+1): if Q[i] == Qmax: Qindex.append(i) ans = Pmax+Qmax-1 key = 0 for x in Pindex: for y in Qindex: if (x,y) not in A: ans += 1 key = 1 break if key == 1: break print(ans)
p02580
from collections import Counter H,W,m = list(map(int,input().split())) ci = Counter([]) cj = Counter([]) s = set() for i in range(m): h,w = list(map(int,input().split())) ci[h] += 1 cj[w] += 1 s.add((h,w)) mi = max(ci.values()) mj = max(cj.values()) ci = sorted(list(ci.items()),key=lambda x:x[1], reverse=True) cj = sorted(list(cj.items()),key=lambda x:x[1], reverse=True) xi = [ci[i][0] for i in range(len(ci)) if ci[i][1] == mi] xj = [cj[i][0] for i in range(len(cj)) if cj[i][1] == mj] for i in xi: for j in xj: if (i,j) not in s: print((mi+mj)) quit() print((mi+mj-1))
from collections import Counter H,W,m = list(map(int,input().split())) ci = Counter([]) cj = Counter([]) s = set() for i in range(m): h,w = list(map(int,input().split())) ci[h] += 1 cj[w] += 1 s.add((h,w)) mi = max(ci.values()) mj = max(cj.values()) ci = list(ci.items()) cj = list(cj.items()) xi = [ci[i][0] for i in range(len(ci)) if ci[i][1] == mi] xj = [cj[i][0] for i in range(len(cj)) if cj[i][1] == mj] for i in xi: for j in xj: if (i,j) not in s: print((mi+mj)) quit() print((mi+mj-1))
p02580
def e_bomber(): from collections import defaultdict H, W, M = [int(i) for i in input().split()] bomb_row = [0] * H bomb_col = [0] * W bomb_pos = defaultdict(int) for _ in range(M): r, c = [int(i) - 1 for i in input().split()] bomb_row[r] += 1 bomb_col[c] += 1 bomb_pos[(r, c)] += 1 bomb_row_max = max(bomb_row) bomb_col_max = max(bomb_col) # 破壊できる数が最大になるような行と列の組を全探索する。 # (行, 列) が破壊対象の上になってしまわないような組があれば、そこに置けばいい。 # そのような組がまったくなければ、破壊対象の上に置かざるを得ない (-1 される)。 flag = False for row in [r for r in range(H) if bomb_row_max == bomb_row[r]]: for col in [c for c in range(W) if bomb_col_max == bomb_col[c]]: if bomb_pos[(row, col)] == 0: return bomb_row_max + bomb_col_max return bomb_row_max + bomb_col_max - 1 print((e_bomber()))
def e_bomber(): import sys input = sys.stdin.readline H, W, M = [int(i) for i in input().split()] bomb_row = [0] * H bomb_col = [0] * W bomb_pos = set() for _ in range(M): r, c = [int(i) - 1 for i in input().split()] bomb_row[r] += 1 bomb_col[c] += 1 bomb_pos.add((r, c)) bomb_row_max = max(bomb_row) bomb_col_max = max(bomb_col) row_index_list = [r for r, v in enumerate(bomb_row) if v == bomb_row_max] col_index_list = [c for c, v in enumerate(bomb_col) if v == bomb_col_max] # 破壊できる数が最大になるような行と列の組を全探索する。 # (行, 列) が破壊対象の上になってしまわないような組があれば、そこに置けばいい。 # そのような組がまったくなければ、破壊対象の上に置かざるを得ない (-1 される)。 for row in row_index_list: for col in col_index_list: if (row, col) not in bomb_pos: return bomb_row_max + bomb_col_max return bomb_row_max + bomb_col_max - 1 print((e_bomber()))
p02580
import collections as c h,w,m = list(map(int,input().split())) x = [] y = [] z = [] for i in range(m): s,t = list(map(int,input().split())) x.append(s) y.append(t) z.append(tuple([s,t])) a = c.Counter(x) b = c.Counter(y) a = a.most_common() b = b.most_common() c = [] d = [] e = a[0][1] f = b[0][1] for sa in a: if sa[1] == e: c.append(sa[0]) else: break for sb in b: if sb[1] == f: d.append(sb[0]) else: break fl = 0 ans = e+f-1 for s in c: for t in d: if tuple([s,t]) not in z: fl = 1 ans += 1 break if fl == 1: break print(ans)
import collections as c h,w,m = list(map(int,input().split())) x = [] y = [] z = set([]) for i in range(m): s,t = list(map(int,input().split())) x.append(s) y.append(t) z.add(tuple([s,t])) a = c.Counter(x) b = c.Counter(y) a = a.most_common() b = b.most_common() c = [] d = [] e = a[0][1] f = b[0][1] for sa in a: if sa[1] == e: c.append(sa[0]) else: break for sb in b: if sb[1] == f: d.append(sb[0]) else: break fl = 0 ans = e+f-1 for s in c: for t in d: if tuple([s,t]) not in z: fl = 1 ans += 1 break if fl == 1: break print(ans)
p02580
import sys H, W, M = list(map(int, input().split())) lis =[] Hlis = [0]*H Wlis = [0]*W for _ in range(M): Ch, Cm = list(map(int, input().split())) Hlis[Ch-1] += 1 Wlis[Cm-1] += 1 lis.append([Ch, Cm]) Hmax = max(Hlis) Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax] Wmax = max(Wlis) Widx = [i+1 for i, v in enumerate(Wlis) if v == Wmax] lis=tuple(lis) for i in range(len(Hidx)): for j in range(len(Widx)): if [Hidx[i], Widx[j]] not in lis: print((Hmax+Wmax)) sys.exit() else: print((Hmax + Wmax -1))
import sys H, W, M = list(map(int, input().split())) lis =set() Hlis = [0]*H Wlis = [0]*W for _ in range(M): Ch, Cm = list(map(int, input().split())) Hlis[Ch-1] += 1 Wlis[Cm-1] += 1 lis.add((Ch, Cm)) Hmax = max(Hlis) Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax] Wmax = max(Wlis) Widx = [i+1 for i, v in enumerate(Wlis) if v == Wmax] for i in range(len(Hidx)): for j in range(len(Widx)): if (Hidx[i], Widx[j]) not in lis: print((Hmax+Wmax)) sys.exit() else: print((Hmax + Wmax -1))
p02580
import os import sys from io import BytesIO, IOBase def main(): h, w, m = list(map(int, input().split())) row = [0] * h col = [0] * w d = set() ma = 0 for i in range(m): x, y = list(map(int, input().split())) row[x - 1] += 1 col[y - 1] += 1 d.add((x, y)) for i in range(h): for j in range(w): ma = max(ma, col[j] + row[i] - (1 if (i + 1, j + 1) in d else 0)) print(ma) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main()
import os import sys from io import BytesIO, IOBase def main(): h, w, m = list(map(int, input().split())) row = [0] * h col = [0] * w d = set() ma = 0 for i in range(m): x, y = list(map(int, input().split())) row[x - 1] += 1 col[y - 1] += 1 d.add((x, y)) e=max(row) f=row.index(e) g=max(col) z=col.index(g) for i in range(w): ma=max(ma,e+col[i]-(1 if (f+1,i+1) in d else 0)) for i in range(h): ma=max(ma,g+row[i]-(1 if (i+1,z+1) in d else 0)) print(ma) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main()
p02580
H,W,M = list(map(int,input().split())) h_target = [0]*(H+1) w_target = [0]*(W+1) target = [] for _ in range(M): h,w = list(map(int,input().split())) target.append((h,w)) h_target[h] += 1 w_target[w] += 1 max_h = max(h_target) max_w = max(w_target) num_max_h = 0 num_max_w = 0 for i in h_target: if i == max_h: num_max_h += 1 for i in w_target: if i == max_w: num_max_w += 1 total = num_max_h*num_max_w point = 0 for i,j in target: if h_target[i] == max_h and w_target[j] == max_w: point += 1 if point == total: print((max_h+max_w-1)) else: print((max_h+max_w))
H,W,M = list(map(int,input().split())) h_target = [0]*(H+1) w_target = [0]*(W+1) target = [] for _ in range(M): h,w = list(map(int,input().split())) target.append((h,w)) h_target[h] += 1 w_target[w] += 1 max_h = max(h_target) max_w = max(w_target) num_max_h = 0 num_max_w = 0 for i in h_target: if i == max_h: num_max_h += 1 for i in w_target: if i == max_w: num_max_w += 1 total = num_max_h*num_max_w # 最適地点の組み合わせ個数 point = 0 # 最適地点のうち爆破対象地点の個数 for i,j in target: if h_target[i] == max_h and w_target[j] == max_w: point += 1 if point == total: print((max_h+max_w-1)) else: print((max_h+max_w))
p02580
import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) Hsum = [0] * H Wsum = [0] * W hw = set() for m in range(M): h, w = list(map(int, input().split())) Hsum[h-1] += 1 Wsum[w-1] += 1 hw.add((h-1, w-1)) hcnt = Hsum.count(max(Hsum)) wcnt = Wsum.count(max(Wsum)) if hcnt * wcnt > M: print((max(Hsum) + max(Wsum))) sys.exit() hidx = [i for i, _ in enumerate(Hsum) if _ == max(Hsum)] widx = [i for i, _ in enumerate(Wsum) if _ == max(Wsum)] for h in hidx: for w in widx: if (h, w) not in hw: print((max(Hsum) + max(Wsum))) sys.exit() print((max(Hsum) + max(Wsum) - 1))
import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) Hsum = [0] * H Wsum = [0] * W hw = set() for m in range(M): h, w = [int(x) - 1 for x in input().split()] Hsum[h] += 1 Wsum[w] += 1 hw.add((h, w)) mh = max(Hsum) mw = max(Wsum) hidx = [i for i, _ in enumerate(Hsum) if _ == mh] widx = [i for i, _ in enumerate(Wsum) if _ == mw] if len(hidx) * len(widx) > M: print((mh + mw)) else: fi_flg = False for h in hidx: for w in widx: if (h, w) not in hw: print((mh + mw)) fi_flg = True break if fi_flg: break if fi_flg is False: print((mh + mw - 1))
p02580
import sys input = sys.stdin.readline h, w, m = list(map(int, input().split())) col = [0]*w row = [0]*h ypos = [] xpos = [] bomb = [] for i in range(m): H, W = [int(x) - 1 for x in input().split()] col[W] += 1 row[H] += 1 bomb.append((H, W)) maxcol = max(col) maxrow = max(row) xpos = [h for h, x in enumerate(col) if x == maxcol] ypos = [w for w, y in enumerate(row) if y == maxrow] ans = maxcol + maxrow - 1 for i in ypos: for j in xpos: if (i, j) not in bomb: ans += 1 print(ans) exit() print(ans)
h, w, m = list(map(int, input().split())) col = [0]*w row = [0]*h ypos = [] xpos = [] bomb = [] for i in range(m): H, W = [int(x) - 1 for x in input().split()] col[W] += 1 row[H] += 1 bomb.append((H, W)) maxcol = max(col) maxrow = max(row) for i in range(w): if col[i] == maxcol: xpos.append(i) for i in range(h): if row[i] == maxrow: ypos.append(i) ans = maxcol + maxrow - 1 bomb = set(bomb) #setにすると速い for i in ypos: for j in xpos: if (i, j) not in bomb: ans += 1 print(ans) exit() print(ans)
p02580