input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
########### E H, W, M = list(map(int, input().split())) bombs = [] for _ in range(M): bomb = list([int(x)-1 for x in input().split()]) bombs.append(bomb) H_list = [0]*H W_list = [0]*W sign = True for h,w in bombs: H_list[h] += 1 W_list[w] += 1 max_H = [i for i,k in enumerate(H_list) if k == max(H_list)] max_W = [i for i,k in enumerate(W_list) if k == max(W_list)] cross = [] for i in max_H: for k in max_W: if [i,k] not in bombs: sign = False print((max(H_list) + max(W_list))) break break if sign: print((max(H_list) + max(W_list) -1))
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 # X:各行の爆破対象の個数 Y = [0] * W # Y:各列の爆破対象の個数 for h, w in bomb: X[h] += 1 Y[w] += 1 maxX = max(X) maxY = max(Y) R = [h for h, x in enumerate(X) if x == maxX] # R:爆破対象の数が最大となる行の番号 C = [w for w, y in enumerate(Y) if y == maxY] # C:爆破対象の数が最大となる列の番号 bomb = set(bomb) for r in R: for c in C: if (r, c) not in bomb: # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため, # 即座に探索を終了する. これによりループの回数は最大でもM+1回となる. print((maxX + maxY)) exit() print((maxX + maxY - 1))
p02580
import sys h,w,m = list(map(int,input().split())) H = [0]*(h) W = [0]*(w) ch = [[False]*w for _ in range(h)] for _ in range(m): a,b = list(map(int,input().split())) H[a-1] += 1 W[b-1] += 1 ch[a-1][b-1] = True hm = max(H) wm = max(W) for i in range(len(H)): if H[i] != hm: continue for j in range(len(W)): if W[j] != wm: continue if ch[i][j] != True: print((hm+wm)) sys.exit() print((hm+wm-1))
import sys h,w,m = list(map(int,input().split())) H = [0]*(h) W = [0]*(w) ls = [] for _ in range(m): a,b = list(map(int,input().split())) ls.append([a-1,b-1]) H[a-1] += 1 W[b-1] += 1 hm = max(H) wm = max(W) for i in range(len(H)): for j in range(len(W)): if W[j] == wm and H[i] == hm and [i,j] not in ls: print((hm+wm)) sys.exit() print((hm+wm-1))
p02580
h,w,m=list(map(int,input().split())) max_h=[0 for i in range(h+1)] max_w=[0 for i in range(w+1)] grid=[[0 for i in range(w)] for j in range(h)] #pro=[list(map(int,input().split())) for i in range(m)] #pro.sort() for t in range(m): #h=pro[t][0] # w=pro[t][1] h,w=list(map(int,input().split())) max_h[h]+=1 max_w[w]+=1 grid[h-1][w-1]=1 h_max=[i for i, x in enumerate(max_h) if x == max(max_h)] w_max=[i for i, x in enumerate(max_w) if x == max(max_w)] ans=0 for i in h_max: for j in w_max: cnt=0 cnt +=list(zip(*grid))[j-1].count(1) cnt += grid[i-1].count(1) ''' for k in range(h): if grid[k][j-1]==1: cnt += 1 for l in range(w): if grid[i-1][l]==1: cnt += 1 ''' if grid[i-1][j-1]==1: cnt -= 1 if cnt > ans: ans=cnt print(ans)
H,W,M=list(map(int,input().split())) Hx=[] #爆破対象の座標を記録 Hy=[] X=[] for i in range(M): h,w=[int(x)-1 for x in input().split()] Hx.append(h) Hy.append(w) X.append([h,w]) sum_c=[0]*W #縦の合計 sum_r=[0]*H #横の合計 for i in Hy: sum_c[i] += 1 for j in Hx: sum_r[j] += 1 max_c=max(sum_c) max_r=max(sum_r) flag=0 #max_cの列とmax_rの行で交差点に爆弾がないところがあればflag=1 for i in range(H): for j in range(W): if sum_r[i]==max_r and sum_c[j]==max_c: if [i,j] not in X: flag=1 break if flag==1: break if flag==0: print((max_c+max_r-1)) else: print((max_c+max_r))
p02580
import collections H, W, M = list(map(int, input().split())) h, w = [0]*M, [0]*M for i in range(M): h[i], w[i] = list(map(int, input().split())) counter = collections.Counter(h) h_max = max(counter.values()) mode_h = [key for key , value in list(counter.items()) if value == h_max] counter = collections.Counter(w) w_max = max(counter.values()) mode_w = [key for key , value in list(counter.items()) if value == w_max] ans = 0 for i in mode_h: for j in mode_w: if ans < h.count(i) + w.count(j): ans = h.count(i) + w.count(j) for k in range(M): if h[k] == i and w[k] == j: ans -= 1 if ans == H + W - 1 or ans == M or ans == h_max + w_max: print(ans) exit() print(ans)
import collections H, W, M = list(map(int, input().split())) h, w = [0]*M, [0]*M dic = set() for i in range(M): h[i], w[i] = list(map(int, input().split())) dic.add((h[i],w[i])) counter = collections.Counter(h) h_max = max(counter.values()) mode_h = [key for key , value in list(counter.items()) if value == h_max] counter = collections.Counter(w) w_max = max(counter.values()) mode_w = [key for key , value in list(counter.items()) if value == w_max] for i in mode_h: for j in mode_w: if (i,j) not in dic: print((h_max+w_max)) exit() print((h_max+w_max-1))
p02580
import sys,bisect from sys import stdin,stdout from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right from math import gcd,ceil,floor,sqrt from collections import Counter,defaultdict,deque,OrderedDict from queue import Queue,PriorityQueue from string import ascii_lowercase sys.setrecursionlimit(10**6) INF = float('inf') MOD = 998244353 mod = 10**9+7 def isPrime(n): if (n <= 1) :return False if (n <= 3) :return True if (n%2 == 0 or n%3 == 0):return False for i in range(5,ceil(sqrt(n))+1,6): if (n%i==0 or n%(i+2)==0): return False return True def st(): return list(stdin.readline().strip()) def inp(): return int(stdin.readline()) def li(): return list(map(int,stdin.readline().split())) def mp(): return list(map(int,stdin.readline().split())) def pr(n): stdout.write(str(n)+"\n") def DFS(dictionary,vertex,visited): visited[vertex]=True stack=[vertex] print(vertex) while stack: a=stack.pop() for i in dictionary[a]: if not visited[i]: print(i) visited[i]=True stack.append(i) def BFS(dictionary, vertex,visited): visited[vertex]=True q=deque() q.append(vertex) while q: a=q.popleft() for i in dictionary[a]: if not visited[i]: visited[i]=True q.append(i) print(i) def soe(limit): l=[1]*(limit+1) l[0]=0 l[1]=0 prime=[] for i in range(2,limit+1): if l[i]: for j in range(i*i,limit+1,i): l[j]=0 for i in range(2,limit+1): if l[i]: prime.append(i) return prime def segsoe(low,high): limit=int(high**0.5)+1 prime=soe(limit) n=high-low+1 l=[0]*(n+1) for i in range(len(prime)): lowlimit=(low//prime[i])*prime[i] if lowlimit<low: lowlimit+=prime[i] if lowlimit==prime[i]: lowlimit+=prime[i] for j in range(lowlimit,high+1,prime[i]): l[j-low]=1 for i in range(low,high+1): if not l[i-low]: if i!=1: print(i) def gcd(a,b): while b: a=a%b b,a=a,b return a def power(a,n): r=1 while n: if n&1: r=(r*a) a*=a n=n>>1 return r def solve(): r,c,m=mp() row={} col={} s=[] for i in range(m): l=li() a=l[0] b=l[1] row[a]=row.get(a,0)+1 col[b]=col.get(b,0)+1 s.append(l) miR,miC=float('-inf'),float('-inf') for i in row: if row[i]>miR: miR=row[i] R=i for i in col: if col[i]>miC: miC=col[i] C=i ans=float('-inf') for i in col: c=miR+col[i] if [R,i] in s: c-=1 ans=max(ans,c) for i in row: c=miC+row[i] if [i,C] in s: c-=1 ans=max(ans,c) pr(ans) for _ in range(1): solve()
import sys,bisect from sys import stdin,stdout from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right from math import gcd,ceil,floor,sqrt from collections import Counter,defaultdict,deque,OrderedDict from queue import Queue,PriorityQueue from string import ascii_lowercase sys.setrecursionlimit(10**6) INF = float('inf') MOD = 998244353 mod = 10**9+7 def isPrime(n): if (n <= 1) :return False if (n <= 3) :return True if (n%2 == 0 or n%3 == 0):return False for i in range(5,ceil(sqrt(n))+1,6): if (n%i==0 or n%(i+2)==0): return False return True def st(): return list(stdin.readline().strip()) def inp(): return int(stdin.readline()) def li(): return list(map(int,stdin.readline().split())) def mp(): return list(map(int,stdin.readline().split())) def pr(n): stdout.write(str(n)+"\n") def DFS(dictionary,vertex,visited): visited[vertex]=True stack=[vertex] print(vertex) while stack: a=stack.pop() for i in dictionary[a]: if not visited[i]: print(i) visited[i]=True stack.append(i) def BFS(dictionary, vertex,visited): visited[vertex]=True q=deque() q.append(vertex) while q: a=q.popleft() for i in dictionary[a]: if not visited[i]: visited[i]=True q.append(i) print(i) def soe(limit): l=[1]*(limit+1) l[0]=0 l[1]=0 prime=[] for i in range(2,limit+1): if l[i]: for j in range(i*i,limit+1,i): l[j]=0 for i in range(2,limit+1): if l[i]: prime.append(i) return prime def segsoe(low,high): limit=int(high**0.5)+1 prime=soe(limit) n=high-low+1 l=[0]*(n+1) for i in range(len(prime)): lowlimit=(low//prime[i])*prime[i] if lowlimit<low: lowlimit+=prime[i] if lowlimit==prime[i]: lowlimit+=prime[i] for j in range(lowlimit,high+1,prime[i]): l[j-low]=1 for i in range(low,high+1): if not l[i-low]: if i!=1: print(i) def gcd(a,b): while b: a=a%b b,a=a,b return a def power(a,n): r=1 while n: if n&1: r=(r*a) a*=a n=n>>1 return r def solve(): r,c,m=mp() row={} col={} dd={} d={} for i in range(m): l=li() a=l[0] b=l[1] row[a]=row.get(a,0)+1 col[b]=col.get(b,0)+1 if a in d: d[a].add(b) else: d[a]={b} if b in dd: dd[b].add(a) else: dd[b]={a} miR,miC=float('-inf'),float('-inf') for i in row: if row[i]>miR: miR=row[i] R=i for i in col: if col[i]>miC: miC=col[i] C=i ans=float('-inf') for i in col: c=miR+col[i] if i in d[R]: c-=1 ans=max(ans,c) for i in row: c=miC+row[i] if i in dd[C]: c-=1 ans=max(ans,c) pr(ans) for _ in range(1): solve()
p02580
import sys input = sys.stdin.readline h,w,m=list(map(int, input().split())) from collections import defaultdict hd=defaultdict(int) wd=defaultdict(int) hd2=[[] for i in range(h+1)] hmax=0 wmax=0 for i in range(m): h0,w0=list(map(int, input().split())) hd[h0]+=1 hmax=max(hmax,hd[h0]) hd2[h0].append(w0) wd[w0]+=1 wmax=max(wmax,wd[w0]) max_h_list=[] max_w_list=[] for k in list(hd.keys()): if hd[k]==hmax: max_h_list.append(k) for k in list(wd.keys()): if wd[k]==wmax: max_w_list.append(k) ans=float('inf') for x in max_h_list: hlist=hd2[x] for y in max_w_list: if y in hlist: ans=min(ans,1) else: ans=min(ans,0) print((hmax+wmax-ans))
import sys from collections import defaultdict input = sys.stdin.readline h,w,m=list(map(int, input().split())) hd=[0 for i in range(h+1)] wd=[0 for i in range(w+1)] hw=defaultdict(int) hmax=0 wmax=0 for i in range(m): h0,w0=list(map(int, input().split())) hd[h0]+=1 hmax=max(hmax,hd[h0]) wd[w0]+=1 wmax=max(wmax,wd[w0]) hw[(h0,w0)]+=1 max_h_list=[] max_w_list=[] for k in range(h+1): if hd[k]==hmax: max_h_list.append(k) for k in range(w+1): if wd[k]==wmax: max_w_list.append(k) ans=float('inf') for x in max_h_list: for y in max_w_list: if hw[(x,y)]==1: ans=min(ans,1) else: ans=min(ans,0) break print((hmax+wmax-ans))
p02580
h,w,m=list(map(int, input().split())) from collections import defaultdict hd=defaultdict(int) wd=defaultdict(int) hw=defaultdict(int) for i in range(m): h0,w0=list(map(int, input().split())) hd[h0]+=1 hw[(h0,w0)]+=1 wd[w0]+=1 max_h_list = [kv[0] for kv in list(hd.items()) if kv[1] == max(hd.values())] max_w_list = [kv[0] for kv in list(wd.items()) if kv[1] == max(wd.values())] ans=float('inf') for x in max_h_list: for y in max_w_list: if hw[(x,y)]==1: ans=min(ans,1) else: ans=min(ans,0) break print((hd[max_h_list[0]]+wd[max_w_list[0]]-ans))
import sys from collections import defaultdict input = sys.stdin.readline h,w,m=list(map(int, input().split())) hd=[0 for i in range(h+1)] wd=[0 for i in range(w+1)] hw=defaultdict(int) hmax=0 wmax=0 for i in range(m): h0,w0=list(map(int, input().split())) hd[h0]+=1 hmax=max(hmax,hd[h0]) wd[w0]+=1 wmax=max(wmax,wd[w0]) hw[(h0,w0)]+=1 max_h_list=[] max_w_list=[] for k in range(h+1): if hd[k]==hmax: max_h_list.append(k) for k in range(w+1): if wd[k]==wmax: max_w_list.append(k) ans=float('inf') for x in max_h_list: for y in max_w_list: if hw[(x,y)]==1: ans=min(ans,1) else: ans=min(ans,0) break print((hmax+wmax-ans))
p02580
def main(): import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) H_list = [[0, i] for i in range(H + 1)] W_list = [[0, i] for i in range(W + 1)] S = set() S_add = S.add INF = 10 ** 6 for _ in range(M): a, b = list(map(int, input().split())) tmp = INF * a + b S_add(tmp) H_list[a][0] += 1 W_list[b][0] += 1 ans = 0 H_list.sort(reverse=True) W_list.sort(reverse=True) tmp_H = H_list[0][0] tmp_W = W_list[0][0] tmp_ans = tmp_H + tmp_W for h in range(H): if H_list[h][0] + 1 < tmp_H: continue h_ = H_list[h][1] H_ = H_list[h][0] for w in range(W): if W_list[w][0] + 1 < tmp_W: break w_ = W_list[w][1] tmp = H_ + W_list[w][0] if INF * h_ + w_ in S: tmp -= 1 ans = max(ans, tmp) if ans == tmp_ans: print (ans) return print (ans) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) H_list = [[0, i] for i in range(H + 1)] W_list = [[0, i] for i in range(W + 1)] S = set() S_add = S.add INF = 10 ** 6 for _ in range(M): a, b = list(map(int, input().split())) tmp = INF * a + b S_add(tmp) H_list[a][0] += 1 W_list[b][0] += 1 ans = 0 H_list.sort(reverse=True) W_list.sort(reverse=True) tmp_H = H_list[0][0] tmp_W = W_list[0][0] tmp_ans = tmp_H + tmp_W for h in range(H): if H_list[h][0] + 1 < tmp_H: continue h_ = H_list[h][1] H_ = H_list[h][0] for w in range(W): if W_list[w][0] + H_ + 1 < tmp_ans: break w_ = W_list[w][1] tmp = H_ + W_list[w][0] if INF * h_ + w_ in S: tmp -= 1 ans = max(ans, tmp) if ans == tmp_ans: print (ans) return print (ans) if __name__ == '__main__': main()
p02580
#!/usr/bin/python3 # -*- coding: utf-8 -*- h, w, m = list(map(int, input().split())) bom_set = set() h_dict = {} w_dict = {} for i in range(m): hh, ww = list(map(int, input().split())) bom_set.add(tuple([hh, ww])) if hh in h_dict: h_dict[hh] += 1 else: h_dict[hh] = 1 if ww in w_dict: w_dict[ww] += 1 else: w_dict[ww] = 1 h_max_count = max(h_dict.values()) w_max_count = max(w_dict.values()) flag = 0 for hh in h_dict: if h_dict[hh] < h_max_count: continue for ww in w_dict: if w_dict[ww] < w_max_count: continue if tuple([hh, ww]) not in bom_set: flag = 1 break if flag == 1: break if flag == 1: print((h_max_count + w_max_count)) else: print((h_max_count + w_max_count - 1))
#!/usr/bin/python3 # -*- coding: utf-8 -*- h, w, m = list(map(int, input().split())) bom_set = set() h_dict = {} w_dict = {} for i in range(m): hh, ww = list(map(int, input().split())) bom_set.add(tuple([hh, ww])) if hh in h_dict: h_dict[hh] += 1 else: h_dict[hh] = 1 if ww in w_dict: w_dict[ww] += 1 else: w_dict[ww] = 1 h_max_count = max(h_dict.values()) w_max_count = max(w_dict.values()) hh_dict = {} ww_dict = {} for hh in h_dict: if h_dict[hh] == h_max_count: hh_dict[hh] = h_max_count for ww in w_dict: if w_dict[ww] == w_max_count: ww_dict[ww] = w_max_count flag = 0 for hh in hh_dict: for ww in ww_dict: if tuple([hh, ww]) not in bom_set: flag = 1 break if flag == 1: break if flag == 1: print((h_max_count + w_max_count)) else: print((h_max_count + w_max_count - 1))
p02580
#!/usr/bin/env python3 # from typing import Optional from typing import List # from typing import Dict from typing import Tuple from typing import Set # from typing import Sequence Cod = Tuple[int, int] def main(): args = input().split() H = int(args[0]) W = int(args[1]) M = int(args[2]) codList: Set[Cod] = [] columnSumList: List[int] = [0] * W rowSumList: List[int] = [0] * H for i in range(M): h, w = [int(x) for x in input().split()] item = (h, w) codList.append(item) columnSumList[w - 1] += 1 rowSumList[h - 1] += 1 maxColumnSum = max(columnSumList) maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum] maxRowSum = max(rowSumList) maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum] result = maxColumnSum + maxRowSum for row in maxRowIndexList: for column in maxColumIndexList: if (row + 1, column + 1) in codList: continue else: print(result) return print((result - 1)) if __name__ == "__main__": main()
#!/usr/bin/env python3 # from typing import Optional from typing import List # from typing import Dict from typing import Tuple from typing import Set # from typing import Sequence Cod = Tuple[int, int] def main(): args = input().split() H = int(args[0]) W = int(args[1]) M = int(args[2]) codList = {} columnSumList: List[int] = [0] * W rowSumList: List[int] = [0] * H for i in range(M): h, w = [int(x) for x in input().split()] item = (h, w) codList.setdefault(h, {}) codList[h][w] = item columnSumList[w - 1] += 1 rowSumList[h - 1] += 1 maxColumnSum = max(columnSumList) maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum] maxRowSum = max(rowSumList) maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum] result = maxColumnSum + maxRowSum for row in maxRowIndexList: for column in maxColumIndexList: if row + 1 in codList and column + 1 in codList[row + 1]: continue else: print(result) return print((result - 1)) if __name__ == "__main__": main()
p02580
#!/usr/bin/env python3 # from typing import Optional from typing import List # from typing import Dict from typing import Tuple from typing import Set # from typing import Sequence Cod = Tuple[int, int] def main(): args = input().split() H = int(args[0]) W = int(args[1]) M = int(args[2]) codList = {} columnSumList: List[int] = [0] * W rowSumList: List[int] = [0] * H for i in range(M): h, w = [int(x) for x in input().split()] item = (h, w) codList.setdefault(h, {}) codList[h][w] = item columnSumList[w - 1] += 1 rowSumList[h - 1] += 1 maxColumnSum = max(columnSumList) maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum] maxRowSum = max(rowSumList) maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum] result = maxColumnSum + maxRowSum for row in maxRowIndexList: for column in maxColumIndexList: if row + 1 in codList and column + 1 in codList[row + 1]: continue else: print(result) return print((result - 1)) if __name__ == "__main__": main()
#!/usr/bin/env python3 # from typing import Optional from typing import List # from typing import Dict from typing import Tuple from typing import Set # from typing import Sequence Cod = Tuple[int, int] def main(): args = input().split() H = int(args[0]) W = int(args[1]) M = int(args[2]) codList = set() columnSumList: List[int] = [0] * W rowSumList: List[int] = [0] * H for i in range(M): h, w = [int(x) for x in input().split()] item = (h, w) codList.add(item) # codList.setdefault(h, {}) # codList[h][w] = item columnSumList[w - 1] += 1 rowSumList[h - 1] += 1 maxColumnSum = max(columnSumList) maxColumIndexList = [i for i, x in enumerate(columnSumList) if x == maxColumnSum] maxRowSum = max(rowSumList) maxRowIndexList = [i for i, x in enumerate(rowSumList) if x == maxRowSum] result = maxColumnSum + maxRowSum for row in maxRowIndexList: for column in maxColumIndexList: if (row + 1, column + 1) in codList: continue else: print(result) return print((result - 1)) if __name__ == "__main__": main()
p02580
H, W, M = list(map(int, input().split())) bombs_h = [0] * H bombs_w = [0] * W S = [[] for _ in range(H)] for _ in range(M): h, w = [int(x)-1 for x in input().split()] S[h].append(w) bombs_h[h] += 1 bombs_w[w] += 1 max_h = max(bombs_h) max_w = max(bombs_w) hs = [i for i, x in enumerate(bombs_h) if x == max_h] ws = [i for i, x in enumerate(bombs_w) if x == max_w] p = 1 for i in hs: for j in ws: if j not in S[i]: p = 0 break ans = max_w + max_h - p print(ans)
H, W, M = list(map(int, input().split())) bombs_h = [0] * H bombs_w = [0] * W B = [] for _ in range(M): h, w = [int(x)-1 for x in input().split()] B.append((h, w)) bombs_h[h] += 1 bombs_w[w] += 1 max_h = max(bombs_h) max_w = max(bombs_w) hs = [i for i, x in enumerate(bombs_h) if x == max_h] ws = [i for i, x in enumerate(bombs_w) if x == max_w] k = len(hs)*len(ws) cnt = 0 for h, w in B: if bombs_h[h] == max_h and bombs_w[w] == max_w: cnt += 1 ans = max_w + max_h - (cnt == k) print(ans)
p02580
H, W, M = list(map(int, input().split())) hk = [[0, i] for i in range(H + 1)] wk = [[0, j] for j in range(W + 1)] s = set() for i in range(M): h, w = list(map(int, input().split())) hk[h][0] += 1 wk[w][0] += 1 s.add((h, w)) hk.sort(reverse=True) wk.sort(reverse=True) colmax = wk[0][0] ans = 0 for lowacc, i in hk: if lowacc + colmax < ans: break for colacc, j in wk: ans = max(ans, lowacc + colacc - ((i, j) in s)) if lowacc + colacc < ans: break print(ans)
H, W, M = list(map(int, input().split())) hk = [[0, i] for i in range(H + 1)] wk = [[0, j] for j in range(W + 1)] s = set() for i in range(M): h, w = list(map(int, input().split())) hk[h][0] += 1 wk[w][0] += 1 s.add((h, w)) hk.sort(reverse=True) wk.sort(reverse=True) colmax = wk[0][0] ans = 0 for lowacc, i in hk: if lowacc + colmax <= ans: break for colacc, j in wk: if lowacc + colacc <= ans: break else: ans = max(ans, lowacc + colacc - ((i, j) in s)) print(ans)
p02580
from collections import deque h, w, m = list(map(int, input().split())) hl=[0]*h wl=[0]*w mh=0 mw=0 mhi=deque([]) dic = {} mwi=deque([]) #ans =[[0]*w for i in range(h)] s = [list(map(int, input().split())) for i in range(m)] for i in range(m): a, b = s[i] a-=1 b-=1 if not a in dic: dic[a] = deque([b]) else: dic[a].append(b) hl[a]+=1 if hl[a]>mh: mh=hl[a] mhi = [a] elif hl[a]==mh: mhi.append(a) wl[b]+=1 if wl[b]>mw: mw=wl[b] mwi=[b] elif wl[b]==mw: mwi.append(b) #ans[a][b]+=1 for i in mhi: for j in mwi: if not j in dic[i]: print((mw+mh)) quit() print((mh+mw-1))
from collections import deque h, w, m = list(map(int, input().split())) hl=[0]*h wl=[0]*w mh=0 mw=0 mhi=deque([]) dic = {} mwi=deque([]) #ans =[[0]*w for i in range(h)] s = [list(map(int, input().split())) for i in range(m)] for i in range(m): a, b = s[i] a-=1 b-=1 if not a in dic: dic[a] = {} dic[a][b]=1 else: dic[a][b]=1 hl[a]+=1 if hl[a]>mh: mh=hl[a] mhi = [a] elif hl[a]==mh: mhi.append(a) wl[b]+=1 if wl[b]>mw: mw=wl[b] mwi=[b] elif wl[b]==mw: mwi.append(b) #ans[a][b]+=1 for i in mhi: for j in mwi: if not j in dic[i]: print((mw+mh)) quit() print((mh+mw-1))
p02580
from operator import itemgetter h, w, m = (int(x) for x in input().split()) H = [0] * h W = [0] * w HW = [] for _ in range(m): h_, w_ = (int(x) - 1 for x in input().split()) HW.append((h_, w_)) H[h_] += 1 W[w_] += 1 hmax = max(H) wmax = max(W) hindex = [] windex = [] ans = hmax + wmax - 1 HW.sort(key=itemgetter(0, 1)) for y in range(h): if H[y] == hmax: hindex.append(y) for x in range(w): if W[x] == wmax: windex.append(x) HW_set = set(HW) for y in hindex: for x in windex: if not (y, x) in HW_set: ans = hmax + wmax print(ans)
from operator import itemgetter h, w, m = (int(x) for x in input().split()) H = [0] * h W = [0] * w HW = [] for _ in range(m): h_, w_ = (int(x) - 1 for x in input().split()) HW.append((h_, w_)) H[h_] += 1 W[w_] += 1 hmax = max(H) wmax = max(W) hindex = set() windex = set() HW.sort(key=itemgetter(0, 1)) for y in range(h): if H[y] == hmax: hindex.add(y) for x in range(w): if W[x] == wmax: windex.add(x) count = 0 for h, w in HW: if h in hindex and w in windex: count += 1 if count == len(hindex)*len(windex): ans = hmax + wmax - 1 else: ans = hmax + wmax print(ans)
p02580
h,w,m = list(map(int,input().split())) l = [list(map(int,input().split())) for _ in range(m)] count_h = [0 for i in range(h)] count_w = [0 for i in range(w)] bit = list([0 for i in range(w)] for _ in range(h)) for j,k in l: count_h[j-1] += 1 count_w[k-1] += 1 bit[j-1][k-1] = 1 h_max = max(count_h) w_max = max(count_w) h_kouho = [] w_kouho = [] ans = h_max + w_max - 1 for i in range(h): if count_h[i]==h_max: h_kouho.append(i) for j in range(w): if count_w[j]==w_max: w_kouho.append(j) for i in w_kouho: for j in h_kouho: if bit[j][i] == 0: ans += 1 print(ans) exit() print(ans)
h,w,m = list(map(int,input().split())) l = [list(map(int,input().split())) for _ in range(m)] count_h = [0 for i in range(h)] count_w = [0 for i in range(w)] for j,k in l: count_h[j-1] += 1 count_w[k-1] += 1 h_max = max(count_h) w_max = max(count_w) h_kouho = [] ko_hh = [0 for _ in range(h)] ko_ww = [0 for _ in range(w)] w_kouho = [] ans = h_max + w_max -1 for i in range(h): if count_h[i]==h_max: h_kouho.append(i) ko_hh[i] = 1 for j in range(w): if count_w[j]==w_max: w_kouho.append(j) ko_ww[j] = 1 ans_kouho = len(h_kouho) * len(w_kouho) su = 0 for j,k in l: if ko_hh[j-1]==1 and ko_ww[k-1]==1: su += 1 if su==ans_kouho: print(ans) else: print((ans+1))
p02580
from sys import stdin, setrecursionlimit #input = stdin.buffer.readline setrecursionlimit(10 ** 7) from heapq import heappush, heappop from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter from itertools import combinations, permutations, combinations_with_replacement from itertools import accumulate from math import ceil, sqrt, pi, radians, sin, cos MOD = 10 ** 9 + 7 INF = 10 ** 6 H, W, M = list(map(int, input().split())) hw = [list(map(int, input().split())) for _ in range(M)] cnt = defaultdict(int) cnt_h = defaultdict(int) cnt_w = defaultdict(int) for h, w in hw: cnt[h * INF + w] += 1 #print(cnt) for h, w in hw: cnt_h[h] += 1 cnt_w[w] += 1 cnt_h = list(cnt_h.items()) cnt_w = list(cnt_w.items()) cnt_h.sort(key = lambda x: -x[1]) cnt_w.sort(key = lambda x: -x[1]) #print(cnt_h) #print(cnt_w) max_h = [] max_w = [] for h, n in cnt_h: if n == cnt_h[0][1]: max_h.append(h) for w, n in cnt_w: if n == cnt_w[0][1]: max_w.append(w) #print(max_h) #print(max_w) answer = cnt_h[0][1] + cnt_w[0][1] for mh in max_h: for mw in max_w: if cnt[mh * INF + mw] == 0: print(answer) exit() print((answer - 1))
from sys import stdin, setrecursionlimit input = stdin.buffer.readline from collections import deque, defaultdict, Counter H, W, M = list(map(int, input().split())) hw = [list(map(int, input().split())) for _ in range(M)] cnt = defaultdict(int) cnt_h = defaultdict(int) cnt_w = defaultdict(int) for h, w in hw: cnt[(h, w)] += 1 for h, w in hw: cnt_h[h] += 1 cnt_w[w] += 1 cnt_h = list(cnt_h.items()) cnt_w = list(cnt_w.items()) cnt_h.sort(key = lambda x: -x[1]) cnt_w.sort(key = lambda x: -x[1]) max_h = [] max_w = [] for h, n in cnt_h: if n == cnt_h[0][1]: max_h.append(h) for w, n in cnt_w: if n == cnt_w[0][1]: max_w.append(w) answer = cnt_h[0][1] + cnt_w[0][1] for mh in max_h: for mw in max_w: if cnt[(mh, mw)] == 0: print(answer) exit() print((answer - 1))
p02580
import sys HK,WK,M = list(map(int, input().split())) W = [0] * (WK + 1) H = [0] * (HK + 1) HW = [[0 for i in range(WK+1)] for _ in range(HK+1)] # 3*10^5 for i in range(M): h, w = list(map(int, input().split())) H[h] += 1 W[w] += 1 HW[h][w] = 1 answer = 0 HMAX = max(H) WMAX = max(W) HEMAX = H.count(HMAX) WEMAX = W.count(WMAX) if HEMAX * WEMAX > M: print((HMAX + WMAX)) sys.exit(0) HMAXES = [i for i, _ in enumerate(H) if _ == HMAX] WMAXES = [i for i, _ in enumerate(W) if _ == WMAX] # 3*10^5 answer = HMAX + WMAX for h in HMAXES: for w in WMAXES: if HW[h][w] == 0: print(answer) sys.exit(0) print((answer-1))
import sys HK,WK,M = list(map(int, input().split())) W = [0] * (WK + 1) H = [0] * (HK + 1) HW = {} # 3*10^5 for i in range(M): h, w = list(map(int, input().split())) H[h] += 1 W[w] += 1 HW[(h,w)] = 1 answer = 0 HMAX = max(H) WMAX = max(W) HEMAX = H.count(HMAX) WEMAX = W.count(WMAX) if HEMAX * WEMAX > M: print((HMAX + WMAX)) sys.exit(0) HMAXES = [i for i, _ in enumerate(H) if _ == HMAX] WMAXES = [i for i, _ in enumerate(W) if _ == WMAX] # 3*10^5 answer = HMAX + WMAX for h in HMAXES: for w in WMAXES: if not (h,w) in HW: print(answer) sys.exit(0) print((answer-1))
p02580
def find(): h,w,m=list(map(int,input().split())) idx=[] for i in range(m): var=list(map(int,input().split())) idx.append(var) r={} c={} maze=[[0 for j in range(w)]for i in range(h)] for i in idx: maze[i[0]-1][i[1]-1]=1 r.setdefault(i[0]-1,0) r[i[0]-1]+=1 c.setdefault(i[1]-1,0) c[i[1]-1]+=1 ans=0 maxval=0 row=[] col=[] maxr=max(r.values()) maxc=max(c.values()) for i in range(h): r.setdefault(i,0) if r[i]==maxr: row.append(i) for j in range(w): c.setdefault(j,0) if c[j]==maxc: col.append(j) for i in row: for j in col: if(maze[i][j]==0): return maxc+maxr return maxc+maxr-1 print((find()))
def find(): h,w,m=list(map(int,input().split())) idx=[] for i in range(m): var=list(map(int,input().split())) idx.append(var) r={} c={} #maze=[[0 for j in range(w)]for i in range(h)] mz={} for i in idx: mz.setdefault((i[0]-1,i[1]-1),0) mz[(i[0]-1,i[1]-1)]=1 #maze[i[0]-1][i[1]-1]=1 r.setdefault(i[0]-1,0) r[i[0]-1]+=1 c.setdefault(i[1]-1,0) c[i[1]-1]+=1 ans=0 maxval=0 row=[] col=[] maxr=max(r.values()) maxc=max(c.values()) for i in range(h): r.setdefault(i,0) if r[i]==maxr: row.append(i) for j in range(w): c.setdefault(j,0) if c[j]==maxc: col.append(j) for i in row: for j in col: mz.setdefault((i,j),0) if(mz[(i,j)]==0): return maxc+maxr return maxc+maxr-1 print((find()))
p02580
from collections import Counter from itertools import groupby def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def ilen(ll): return sum(1 for _ in ll) def solve(): H, W, M = read_ints() hw = [] for _ in range(M): hw.append(read_ints()) hw.sort() max_ws = {} max_count_ws = 0 for h, ws in groupby(hw, key=lambda pair: pair[0]): ws = list(ws) max_count_ws = max(max_count_ws, len(ws)) max_ws[h] = [w for _, w in ws] ks = list(max_ws.keys()) for k in ks: if len(max_ws[k]) < max_count_ws: del max_ws[k] hw.sort(key=lambda pair: pair[1]) max_hs = {} max_count_hs = 0 for w, hs in groupby(hw, key=lambda pair: pair[1]): hs = list(hs) max_count_hs = max(max_count_hs, len(hs)) max_hs[w] = [h for h, _ in hs] ks = list(max_hs.keys()) for k in ks: if len(max_hs[k]) < max_count_hs: del max_hs[k] counter = Counter() for v in list(max_hs.values()): counter += Counter(v) for k in list(max_ws.keys()): if counter[k] != len(max_hs): return max_count_ws+max_count_hs return max_count_ws+max_count_hs-1 if __name__ == '__main__': print((solve()))
from collections import Counter from itertools import groupby def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def ilen(ll): return sum(1 for _ in ll) def solve(): H, W, M = read_ints() hw = [] for _ in range(M): hw.append(tuple(read_ints())) hw.sort() rows = set() max_count_row = 0 for h, ws in groupby(hw, key=lambda pair: pair[0]): count = ilen(ws) if count == max_count_row: rows.add(h) elif count > max_count_row: rows = set([h]) max_count_row = count hw.sort(key=lambda pair: pair[1]) cols = set() max_count_col = 0 for w, hs in groupby(hw, key=lambda pair: pair[1]): count = ilen(hs) if count == max_count_col: cols.add(w) elif count > max_count_col: cols = set([w]) max_count_col = count hw = set(hw) for h in rows: for w in cols: if (h, w) not in hw: return max_count_row+max_count_col return max_count_row+max_count_col-1 if __name__ == '__main__': print((solve()))
p02580
H, W, M = list(map(int, input().split())) hlist = [0] * H wlist = [0] * W hw = [[0 for _ in range(W)] for _ in range(H)] for i in range(M): h, w = list(map(int, input().split())) hlist[h - 1] += 1 wlist[w - 1] += 1 hw[h - 1][w - 1] = 1 hmax = max(hlist) wmax = max(wlist) hmaxlist = [i for i, v in enumerate(hlist) if v == hmax] wmaxlist = [i for i, v in enumerate(wlist) if v == wmax] cnt = -1 for i in hmaxlist: bf = False for j in wmaxlist: if hw[i][j] != 1: cnt = 0 bf = True break if bf: break print((hmax + wmax + cnt))
H, W, M = list(map(int, input().split())) hlist = [0] * H wlist = [0] * W hw = set() for i in range(M): h, w = list(map(int, input().split())) hlist[h - 1] += 1 wlist[w - 1] += 1 hw.add((h - 1, w - 1)) hmax = max(hlist) wmax = max(wlist) hmaxlist = [i for i, v in enumerate(hlist) if v == hmax] wmaxlist = [i for i, v in enumerate(wlist) if v == wmax] cnt = -1 for i in hmaxlist: bf = False for j in wmaxlist: if not (i, j) in hw: cnt = 0 bf = True break if bf: break print((hmax + wmax + cnt))
p02580
def main(): H, W, M = (int(i) for i in input().split()) hc = [0]*(H+1) wc = [0]*(W+1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = -1 maw = -1 hmaps = set() wmaps = set() for i, h in enumerate(hc): if mah < h: mah = h hmaps = {i} elif mah == h: hmaps.add(i) for i, w in enumerate(wc): if maw < w: maw = w wmaps = {i} elif maw == w: wmaps.add(i) ans = mah+maw aru = True for h in list(hmaps): for w in list(wmaps): if (h, w) not in maps: aru = False break if aru: print((ans - 1)) else: print(ans) if __name__ == '__main__': main()
def main(): H, W, M = (int(i) for i in input().split()) hc = [0]*(H+1) wc = [0]*(W+1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = -1 maw = -1 hmaps = set() wmaps = set() for i, h in enumerate(hc): if mah < h: mah = h hmaps = {i} elif mah == h: hmaps.add(i) for i, w in enumerate(wc): if maw < w: maw = w wmaps = {i} elif maw == w: wmaps.add(i) ans = mah+maw aru = True if len(hmaps) * len(wmaps) <= 5*10**6: for h in list(hmaps): for w in list(wmaps): if (h, w) not in maps: aru = False break else: aru = False if aru: print((ans - 1)) else: print(ans) if __name__ == '__main__': main()
p02580
def main(): H, W, M = (int(i) for i in input().split()) hc = [0]*(H+1) wc = [0]*(W+1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = -1 maw = -1 hmaps = set() wmaps = set() for i, h in enumerate(hc): if mah < h: mah = h hmaps = {i} elif mah == h: hmaps.add(i) for i, w in enumerate(wc): if maw < w: maw = w wmaps = {i} elif maw == w: wmaps.add(i) ans = mah+maw aru = True for h in hmaps: for w in wmaps: if (h, w) not in maps: aru = False break if not aru: break if aru: print((ans - 1)) else: print(ans) if __name__ == '__main__': main()
def main(): H, W, M = (int(i) for i in input().split()) hc = [0]*(H+1) wc = [0]*(W+1) maps = set() for _ in range(M): h, w = (int(i) for i in input().split()) hc[h] += 1 wc[w] += 1 maps.add((h, w)) mah = max(hc) maw = max(wc) ans = mah+maw hmaps = [] wmaps = [] for i, h in enumerate(hc): if mah == h: hmaps.append(i) for i, w in enumerate(wc): if maw == w: wmaps.append(i) if M < len(hmaps) * len(wmaps): # 爆破対象の合計が最大になるマスがM個より多ければ, # 必ず爆破対象がないマスに爆弾を置くことができる # 逆にM個以下なら3*10^5のループにしかならないので # このようにif文で分けなくても,必ずO(M)になるのでelse節のforを回してよい print(ans) else: for h in hmaps: for w in wmaps: if (h, w) not in maps: print(ans) return else: print((ans-1)) if __name__ == '__main__': main()
p02580
def main(): h, w, m = list(map(int, input().split())) bombs_h = [0] * h bombs_w = [0] * w B = [] for n in range(m): h1, w1 = list(map(int, input().split())) B.append((h1-1, w1-1)) bombs_w[w1-1] += 1 bombs_h[h1-1] += 1 h_maxindex = [i for i, x in enumerate(bombs_h) if x == max(bombs_h)] w_maxindex = [i for i, x in enumerate(bombs_w) if x == max(bombs_w)] max_h = max(bombs_h) max_w = max(bombs_w) cnt = 0 k = len(h_maxindex) * len(w_maxindex) for i, j in B: if bombs_h[i] == max_h and bombs_w[j] == max_w: cnt += 1 ans = max_h + max_w - (cnt == k) print(ans) if __name__ == "__main__": main()
def main(): h, w, m = list(map(int, input().split())) bombs_h = [0] * h bombs_w = [0] * w B = [] for n in range(m): h1, w1 = [int(x)-1 for x in input().split()] B.append((h1, w1)) bombs_w[w1] += 1 bombs_h[h1] += 1 max_h = max(bombs_h) max_w = max(bombs_w) h_maxindex = [i for i, x in enumerate(bombs_h) if x == max_h] w_maxindex = [i for i, x in enumerate(bombs_w) if x == max_w] cnt = 0 k = len(h_maxindex) * len(w_maxindex) for i, j in B: if bombs_h[i] == max_h and bombs_w[j] == max_w: cnt += 1 ans = max_h + max_w - (cnt == k) print(ans) if __name__ == "__main__": main()
p02580
h,w,m = list(map(int,input().split())) hw = [list(map(int,input().split())) for _ in range(m)] hc = [0]*h wc = [0]*w d={} for _h, _w in hw: hc[_h-1]+=1 wc[_w-1]+=1 d[(_h-1,_w-1)]=1 maxh = max(hc) maxw = max(wc) hoge = True wi = [i for i in range(w) if wc[i]==maxw] for h in [i for i in range(h) if hc[i]==maxh]: for w in wi: if (h,w) not in d: hoge=False if hoge: print((maxh+maxw-1)) else: print((maxh+maxw))
h,w,m = list(map(int,input().split())) hw = [list(map(int,input().split())) for _ in range(m)] hc = [0]*h wc = [0]*w d={} for _h, _w in hw: hc[_h-1]+=1 wc[_w-1]+=1 d[(_h-1,_w-1)]=1 maxh = max(hc) maxw = max(wc) hoge = True wi = [i for i in range(w) if wc[i]==maxw] for h in [i for i in range(h) if hc[i]==maxh]: for w in wi: if (h,w) not in d: hoge=False break if hoge: print((maxh+maxw-1)) else: print((maxh+maxw))
p02580
H, W, M = [int(v) for v in input().split()] targets = [] for _ in range(M): targets.append([int(v) for v in input().split()]) grid = [] for _ in range(H): grid.append([0] * W) for x, y in targets: for i in range(H): grid[i][y-1] += 1 for j in range(W): grid[x-1][j] += 1 grid[x-1][y-1] -= 1 max_val = max(list([max(x) for x in grid])) print(max_val)
H, W, M = [int(v) for v in input().split()] targets = [] for _ in range(M): targets.append([int(v) - 1 for v in input().split()]) h_count = [0] * H w_count = [0] * W for x, y in targets: h_count[x] += 1 w_count[y] += 1 h_count_max = max(h_count) max_val = -1 for i in range(H): if h_count_max == h_count[i]: w_tmp = w_count.copy() for x, y in targets: if x == i: w_tmp[y] -= 1 max_val = max(max_val, max(w_tmp) + h_count_max) print(max_val)
p02580
import sys def resolve(in_): H, W, M = list(map(int, next(in_).split())) targets = tuple(tuple(map(int, line.split())) for line in in_) # H, W, M = 3, 3, 3 # targets = ((1, 1), (2, 1), (1, 3)) target_h = {} target_w = {} target_hw = set() for h, w in targets: target_h[h - 1] = target_h.setdefault(h - 1, 0) + 1 target_w[w - 1] = target_w.setdefault(w - 1, 0) + 1 target_hw.add((h - 1, w - 1)) ans = 0 for h, a in list(target_h.items()): for w, b in list(target_w.items()): ans = max(ans, target_h[h] + target_w[w] - (1 if (h, w) in target_hw else 0)) return ans def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
import sys import itertools def resolve(in_): H, W, M = list(map(int, next(in_).split())) targets = tuple(tuple(map(int, line.split())) for line in in_) target_h = {} target_w = {} target_hw = set() for h, w in targets: target_h[h] = target_h.setdefault(h, 0) + 1 target_w[w] = target_w.setdefault(w, 0) + 1 target_hw.add((h, w)) max_h = max(target_h.values()) max_w = max(target_w.values()) h_set = {h for h, v in list(target_h.items()) if max_h == v} w_set = {w for w, v in list(target_w.items()) if max_w == v} ans = max_h + max_w - 1 for hw in itertools.product(h_set, w_set): if hw not in target_hw: ans += 1 break return ans def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
p02580
H, W, M = list(map(int, input().split())) targets = [list(map(int, input().split())) for _ in range(M)] x_counter = [0 for _ in range(W + 1)] y_counter = [0 for _ in range(H + 1)] y_index = [] x_index = [] check = 0 for i in range(M): x, y = targets[i] y_counter[x] += 1 x_counter[y] += 1 y_max, x_max = max(y_counter), max(x_counter) for i in range(H + 1): if y_counter[i] == y_max: y_index.append(i) for j in range(W + 1): if x_counter[j] == x_max: x_index.append(j) check = len(y_index) * len(x_index) for k in range(M): r, c = targets[k] if r in y_index and c in x_index: check -= 1 print((y_max + x_max if check > 0 else y_max + x_max -1))
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
import sys from collections import Counter def main(): input = sys.stdin.buffer.readline h, w, m = list(map(int, input().split())) h = [0] * m w = [0] * m object_set = set() for i in range(m): h[i], w[i] = list(map(int, input().split())) object_set.add((h[i], w[i])) h_counter = Counter(h) w_counter = Counter(w) max_h_num = h_counter.most_common()[0][1] max_w_num = w_counter.most_common()[0][1] ans = max_h_num + max_w_num h_cand = [] w_cand = [] for e, n in h_counter.most_common(): if n == max_h_num: h_cand.append(e) for e, n in w_counter.most_common(): if n == max_w_num: w_cand.append(e) ok = False for h_e in h_cand: for w_e in w_cand: if (h_e, w_e) not in object_set: ok = True print((ans if ok else ans - 1)) if __name__ == "__main__": main()
import sys from collections import Counter def main(): input = sys.stdin.buffer.readline h, w, m = list(map(int, input().split())) h = [0] * m w = [0] * m object_set = set() for i in range(m): h[i], w[i] = list(map(int, input().split())) object_set.add((h[i], w[i])) h_counter = Counter(h) w_counter = Counter(w) max_h_num = h_counter.most_common()[0][1] max_w_num = w_counter.most_common()[0][1] ans = max_h_num + max_w_num h_cand = set() w_cand = set() for e, n in h_counter.most_common(): if n == max_h_num: h_cand.add(e) for e, n in w_counter.most_common(): if n == max_w_num: w_cand.add(e) cnt = 0 for h_e, w_e in object_set: if h_e in h_cand and w_e in w_cand: cnt += 1 print((ans if cnt < len(h_cand) * len(w_cand) else ans - 1)) if __name__ == "__main__": main()
p02580
from collections import defaultdict as dd h, w, m = list(map(int, input().split())) #dic[row, col] -> set(ids) h_dic = dd(set) w_dic = dd(set) spot = set() for i in range(m): h_c, w_c = list(map(int, input().split())) h_dic[h_c].add(i) w_dic[w_c].add(i) spot.add((h_c, w_c)) #print(h_dic, w_dic) #H_lis -> [i, num_spot(int)] max_h_num = 0 H_lis = [] for key, val in list(h_dic.items()): H_lis.append([key, len(val)]) max_h_num = max(max_h_num, len(val)) max_w_num = 0 W_lis = [] for key, val in list(w_dic.items()): W_lis.append([key, len(val)]) max_w_num = max(max_w_num, len(val)) #print(H_lis, W_lis) #print(max_h) ans = 0 max_h_lis = [val[0] for val in H_lis if val[1] == max_h_num] max_w_lis = [val[0] for val in W_lis if val[1] == max_w_num] for i in max_h_lis: for j in max_w_lis: count = max_h_num + max_w_num if (i, j) in spot: count -= 1 ans = max(ans, count) print(ans) """ max_counter = 0 for i in h_dic.keys(): for j in w_dic.keys(): counter = len(h_dic[i] | w_dic[j]) #print(i, j, h_dic[i] | w_dic[j],counter) max_counter = max(max_counter, counter) print(max_counter) """
from sys import exit from collections import defaultdict as dd h, w, m = list(map(int, input().split())) #dic[row, col] -> set(ids) h_dic = dd(int) w_dic = dd(int) spot = set() for i in range(m): h_c, w_c = list(map(int, input().split())) h_dic[h_c] += 1 w_dic[w_c] += 1 spot.add((h_c, w_c)) #print(h_dic, w_dic) #H_lis -> [i, num_spot(int)] max_h_num = 0 for key, val in list(h_dic.items()): max_h_num = max(max_h_num, val) max_w_num = 0 W_lis = [] for key, val in list(w_dic.items()): max_w_num = max(max_w_num, val) #print(H_lis, W_lis) #print(max_h) ans = 0 max_h_lis = [key for key in h_dic if h_dic[key] == max_h_num] max_w_lis = [key for key in w_dic if w_dic[key] == max_w_num] for i in max_h_lis: for j in max_w_lis: if (i, j) not in spot: print((max_h_num + max_w_num)) exit() else: print((max_h_num + max_w_num - 1)) """ max_counter = 0 for i in h_dic.keys(): for j in w_dic.keys(): counter = len(h_dic[i] | w_dic[j]) #print(i, j, h_dic[i] | w_dic[j],counter) max_counter = max(max_counter, counter) print(max_counter) """
p02580
# -*- coding: utf-8 -*- # E import sys from collections import defaultdict, deque, Counter from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) H, W, M = list(map(int, input().split())) h = [] * M w = [] * M dic_combi = defaultdict(int) for _ in range(M): h_, w_ = list(map(int, input().split())) h.append(h_) w.append(w_) dic_combi[h_ * (10**6) + w_]=1 dic_h = Counter(h) dic_w = Counter(w) # print(dic_h, dic_w) max_h_key = max(list(dic_h.items()), key=lambda x:x[1])[0] max_w_key = max(list(dic_w.items()), key=lambda x:x[1])[0] max_h = dic_h[max_h_key] max_w = dic_w[max_w_key] keys_h = [k for k, v in list(dic_h.items()) if v == max_h] keys_w = [k for k, v in list(dic_w.items()) if v == max_w] def get_num(ind_h, ind_w): ret = 0 for i in range(M): if h[i] == ind_h or w[i] == ind_w: ret += 1 return ret ans = 0 for ind_h in keys_h: for ind_w in keys_w: # ret = get_num(ind_h, ind_w) ret = max_h + max_w if dic_combi[ind_h*(10**6) + ind_w] == 1: ret -= 1 ans = max(ans, ret) print(ans)
# -*- coding: utf-8 -*- # E import sys from collections import defaultdict, deque, Counter from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) H, W, M = list(map(int, input().split())) h = [] * M w = [] * M dic_combi = defaultdict(int) for _ in range(M): h_, w_ = list(map(int, input().split())) h.append(h_) w.append(w_) dic_combi[h_ * (10**6) + w_]=1 dic_h = Counter(h) dic_w = Counter(w) # print(dic_h, dic_w) max_h_key = max(list(dic_h.items()), key=lambda x:x[1])[0] max_w_key = max(list(dic_w.items()), key=lambda x:x[1])[0] max_h = dic_h[max_h_key] max_w = dic_w[max_w_key] keys_h = [k for k, v in list(dic_h.items()) if v == max_h] keys_w = [k for k, v in list(dic_w.items()) if v == max_w] ans = 0 for ind_h in keys_h: for ind_w in keys_w: ret = max_h + max_w if dic_combi[ind_h*(10**6) + ind_w] == 1: ret -= 1 else: print(ret) sys.exit() ans = max(ans, ret) print(ans)
p02580
H, W, M = list(map(int, input().split())) m = [[False] * W for _ in range(H)] dh = dict() dw = dict() for _ in range(M): h_, w_ = list(map(int, input().split())) m[h_ - 1][w_ - 1] = True if h_ in dh: dh[h_] += 1 else: dh[h_] = 1 if w_ in dw: dw[w_] += 1 else: dw[w_] = 1 dhl = list(dh.items()) dhl.sort(key=lambda x: x[1], reverse=True) dwl = list(dw.items()) dwl.sort(key=lambda x: x[1], reverse=True) h, w = [], [] maxh = dhl[0][1] maxw = dwl[0][1] for i, n in dhl: if n == maxh: h.append(i) for i, n in dwl: if n == maxw: w.append(i) res = maxh + maxw - 1 for hh in h: for ww in w: if m[hh - 1][ww - 1] is False: res = maxh + maxw break print(res)
H, W, M = list(map(int, input().split())) boms = [] h, w = [0] * (H + 1), [0] * (W + 1) for _ in range(M): h_, w_ = list(map(int, input().split())) boms.append([h_, w_]) h[h_] += 1 w[w_] += 1 hmax = max(h) wmax = max(w) cnt = h.count(hmax) * w.count(wmax) for hh, ww in boms: if hmax == h[hh] and wmax == w[ww]: cnt -= 1 print((hmax + wmax - (cnt == 0)))
p02580
h,w,m = list(map(int,input().split())) p = [[0 for i in range(w)]for i in range(h)] hlist = [0 for i in range(h)] wlist = [0 for i in range(w)] for i in range(m): a,b = list(map(int,input().split())) hlist[a-1] += 1 wlist[b-1] += 1 p[a-1][b-1] = 1 q = 0 for i in range(h): q = max(q,hlist[i]) s = [] for i in range(h): if hlist[i] == q: s.append(i) r = 0 for i in range(w): r = max(r,wlist[i]) t = [] for i in range(w): if wlist[i] == r: t.append(i) ans = 0 for i in range(len(s)): for j in range(len(t)): if p[s[i]][t[j]] == 1: pass else: ans = q+r break if ans == 0: print((q+r-1)) else: print(ans)
h,w,m = list(map(int,input().split())) p = [] hlist = [0 for i in range(h)] wlist = [0 for i in range(w)] for i in range(m): a,b = list(map(int,input().split())) hlist[a-1] += 1 wlist[b-1] += 1 p.append([a-1,b-1]) q = 0 for i in range(h): q = max(q,hlist[i]) s = [] for i in range(h): if hlist[i] == q: s.append(i) r = 0 for i in range(w): r = max(r,wlist[i]) t = [] for i in range(w): if wlist[i] == r: t.append(i) z = 0 for i in range(m): if hlist[p[i][0]] == q and wlist[p[i][1]] == r: z += 1 if z == len(s)*len(t): print((q+r-1)) else: print((q+r))
p02580
from collections import defaultdict H, W, M = list(map(int, input().split())) r = defaultdict(int) c = defaultdict(int) rc = defaultdict(int) for i in range(M): h, w = list(map(int, input().split())) rc[(h, w)] += 1 r[w] += 1 c[h] += 1 ri, rmax = 0, 0 ci, cmax = 0, 0 for i in list(r.keys()): v = r[i] if v > rmax: ri = i rmax = v for i in list(c.keys()): v = c[i] if v > cmax: ci = i cmax = v rml, cml = [], [] for i, v in list(r.items()): if v == rmax: rml.append((i, v)) for i, v in list(c.items()): if v == cmax: cml.append((i, v)) ans = rmax+cmax-1 for i, vi in rml: find = False for j, vj in cml: if not (j, i) in rc: ans += 1 find = True break if find: break print(ans)
H, W, M = list(map(int, input().split())) r = [0]*(W+1) c = [0]*(H+1) rc = {} for i in range(M): h, w = list(map(int, input().split())) rc[(h, w)] = True r[w] += 1 c[h] += 1 rm = max(r) cm = max(c) ri = {i for i, v in enumerate(r) if v == rm} ci = {i for i, v in enumerate(c) if v == cm} cnt = sum([w in ri and h in ci for h, w in rc]) print((rm+cm-(len(ri)*len(ci) == cnt)))
p02580
from collections import Counter from collections import defaultdict def li(): return [int(x) for x in input().split()] H, W, M = li() PH = [] PW = [] PF = defaultdict(int) for i in range(M): h, w = li() PH.append(h) PW.append(w) PF[h, w] += 1 frequency_h_list = Counter(PH).most_common() frequency_w_list = Counter(PW).most_common() most_common_h_cnt = frequency_h_list[0][1] most_common_w_cnt = frequency_w_list[0][1] most_common_h_list = [] for x in frequency_h_list: if x[1] < most_common_h_cnt: break most_common_h_list.append(x[0]) most_common_w_list = [] for x in frequency_w_list: if x[1] < most_common_w_cnt: break most_common_w_list.append(x[0]) add = -1 for h in most_common_h_list: for w in most_common_w_list: if PF[h, w] == 0: add = 0 cnt = most_common_h_cnt + most_common_w_cnt + add print(cnt)
from collections import Counter from collections import defaultdict def li(): return [int(x) for x in input().split()] H, W, M = li() PH = [] PW = [] PF = defaultdict(int) for i in range(M): h, w = li() PH.append(h) PW.append(w) PF[h, w] += 1 frequency_h_list = Counter(PH).most_common() frequency_w_list = Counter(PW).most_common() most_common_h_cnt = frequency_h_list[0][1] most_common_w_cnt = frequency_w_list[0][1] most_common_h_list = [] for x in frequency_h_list: if x[1] < most_common_h_cnt: break most_common_h_list.append(x[0]) most_common_w_list = [] for x in frequency_w_list: if x[1] < most_common_w_cnt: break most_common_w_list.append(x[0]) add = -1 for h in most_common_h_list: for w in most_common_w_list: if PF[h, w] == 0: add = 0 break cnt = most_common_h_cnt + most_common_w_cnt + add print(cnt)
p02580
h,w,m=list(map(int,input().split())) hlist=[0]*(h+1) wlist=[0]*(w+1) cnt=[] for i in range(m): a,b=list(map(int,input().split())) hlist[a]+=1 wlist[b]+=1 cnt.append([a,b]) hcnt,wcnt=max(hlist),max(wlist) hhh=[i for i,v in enumerate(hlist) if v==hcnt] www=[i for i,v in enumerate(wlist) if v==wcnt] for i in hhh: for j in www: if [i,j] not in cnt: print((hcnt+wcnt)) exit() print((hcnt+wcnt-1))
h,w,m=list(map(int,input().split())) hlist=[0]*(h+1) wlist=[0]*(w+1) cnt=set() for i in range(m): a,b=list(map(int,input().split())) hlist[a]+=1 wlist[b]+=1 cnt.add((a,b)) hcnt,wcnt=max(hlist),max(wlist) hhh=[i for i,v in enumerate(hlist) if v==hcnt] www=[i for i,v in enumerate(wlist) if v==wcnt] for i in hhh: for j in www: if not (i,j) in cnt: print((hcnt+wcnt)) exit() print((hcnt+wcnt-1))
p02580
h,w,m=list(map(int,input().split())) hlist=[0]*(h+1) wlist=[0]*(w+1) cnt=set() for i in range(m): a,b=list(map(int,input().split())) hlist[a]+=1 wlist[b]+=1 cnt.add((a,b)) hcnt,wcnt=max(hlist),max(wlist) hhh=[i for i,v in enumerate(hlist) if v==hcnt] www=[i for i,v in enumerate(wlist) if v==wcnt] for i in hhh: for j in www: if not (i,j) in cnt: print((hcnt+wcnt)) exit() print((hcnt+wcnt-1))
h,w,m=list(map(int,input().split())) hlist=[0]*(h+1) wlist=[0]*(w+1) cnt=set() for i in range(m): a,b=list(map(int,input().split())) hlist[a]+=1 wlist[b]+=1 cnt.add((a,b)) hcnt,wcnt=max(hlist),max(wlist) hhh=[i for i,v in enumerate(hlist) if v==hcnt] www=[i for i,v in enumerate(wlist) if v==wcnt] for i in hhh: for j in www: if (i,j) not in cnt: print((hcnt+wcnt)) exit() print((hcnt+wcnt-1))
p02580
h,w,m=list(map(int,input().split())) hlis=[0 for i in range(h)] wlis=[0 for i in range(w)] lis=[[0 for _ in range(w)] for _ in range(h)] for i in range(m): hi,wi=list(map(int,input().split())) hlis[hi-1]+=1 wlis[wi-1]+=1 lis[hi-1][wi-1]+=1 hmax=max(hlis) wmax=max(wlis) ph=[] pw=[] for i in range(h): if hlis[i]==hmax: ph.append(i) for i in range(w): if wlis[i]==wmax: pw.append(i) cvac=0 for phi in ph: for pwj in pw: if lis[phi][pwj]==0: cvac+=1 break if cvac==1: break if cvac==1: print((hmax+wmax)) else: print((hmax+wmax-1))
import sys h,w,m=list(map(int,input().split())) hlis=[0 for i in range(h)] wlis=[0 for i in range(w)] hw=[] for i in range(m): hi,wi=list(map(int,input().split())) hlis[hi-1]+=1 wlis[wi-1]+=1 hw.append([hi-1,wi-1]) hmax=max(hlis) wmax=max(wlis) ph=[] pw=[] for i in range(h): if hlis[i]==hmax: ph.append(i) for i in range(w): if wlis[i]==wmax: pw.append(i) if len(ph)*len(pw)>3*(10**5): print((hmax+wmax)) sys.exit() plis=[] for phi in ph: for pwj in pw: plis.append(phi*(10**6)+pwj) plis.sort() hwlis=[] for hi,wi in hw: hwlis.append(hi*(10**6)+wi) hwlis.sort() c=0 check=0 for pi in plis: while pi!=hwlis[c]: c+=1 if c>=len(hwlis): check=1 break if check==1: break if check==1: print((hmax+wmax)) else: print((hmax+wmax-1))
p02580
import itertools H, W, M = list(map(int, input().split())) row=[0]*H col=[0]*W mat=[[0 for i in range(W)] for j in range(H)] for i in range(M): h, w = list(map(int, input().split())) h-=1 w-=1 row[h]+=1 col[w]+=1 mat[h][w]+=1 r=max(row) c=max(col) rr=[i for i in range(H) if row[i]==r] cc=[i for i in range(W) if col[i]==c] x=min([min([mat[i][j] for j in cc]) for i in rr]) if x==0: print((r+c)) else: print((r+c-1))
H, W, M = list(map(int, input().split())) row=[0]*H col=[0]*W mat=[] for i in range(M): h, w = list(map(int, input().split())) row[h-1]+=1 col[w-1]+=1 mat.append((h-1,w-1)) r=max(row) c=max(col) rr=[1 if row[i]==r else 0 for i in range(H)] cc=[1 if col[i]==c else 0 for i in range(W)] x=0 for k in mat: if rr[k[0]]==1 and cc[k[1]]==1: x+=1 if sum(rr)*sum(cc)==x: print((r+c-1)) else: print((r+c))
p02580
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) H, W, M = MI() h = [0] * H w = [0] * W item_list = [[0, 0] for _ in range(M)] for i in range(M): item_h, item_w = MI() item_h -= 1 item_w -= 1 h[item_h] += 1 w[item_w] += 1 item_list[i][0] = item_h item_list[i][1] = item_w ans = max(h) + max(w) index_num_h = [n for n, v in enumerate(h) if v == max(h)] index_num_w = [n for n, v in enumerate(w) if v == max(w)] cnt = 0 for item in item_list: if item[0] in index_num_h and item[1] in index_num_w: cnt += 1 x = len(index_num_h) * len(index_num_w) if cnt == x: ans -= 1 print(ans)
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) H, W, M = MI() h = [0] * H w = [0] * W item_list = [[0, 0] for _ in range(M)] for i in range(M): item_h, item_w = MI() item_h -= 1 item_w -= 1 h[item_h] += 1 w[item_w] += 1 item_list[i][0] = item_h item_list[i][1] = item_w h_max = max(h) w_max = max(w) h_cnt = h.count(h_max) w_cnt = w.count(w_max) ans = h_max + w_max cnt = 0 for item in item_list: if h[item[0]] == h_max and w[item[1]] == w_max: cnt += 1 x = h_cnt * w_cnt if cnt == x: ans -= 1 print(ans)
p02580
H, W, M = list(map(int, input().split())) HW = list(tuple(int(x) - 1 for x in input().split()) for _ in range(M)) h = [0] * H w = [0] * W for hi, wi in HW: h[hi] += 1 w[wi] += 1 hm = max(h) wm = max(w) hh = [i for i, v in enumerate(h) if v == hm] ww = [i for i, v in enumerate(w) if v == wm] ans = hm + wm - 1 for h in hh: for w in ww: if (h, w) not in HW: ans += 1 break else: continue break print(ans)
H, W, M = list(map(int, input().split())) HW = set(tuple(int(x) - 1 for x in input().split()) for _ in range(M)) h = [0] * H w = [0] * W for hi, wi in HW: h[hi] += 1 w[wi] += 1 hm = max(h) wm = max(w) hh = [i for i, v in enumerate(h) if v == hm] ww = [i for i, v in enumerate(w) if v == wm] ans = hm + wm - 1 for h in hh: for w in ww: if (h, w) not in HW: ans += 1 break else: continue break print(ans)
p02580
from collections import defaultdict def get_keys_of_max_value(d): v_max = 0 keys = [] for k, v in list(d.items()): if v_max < v: v_max = v keys = [k] elif v_max == v: keys.append(k) return keys, v_max h, w, m = list(map(int, input().split())) targets = [tuple(map(int, input().split())) for _ in range(m)] n_r = defaultdict(int) n_c = defaultdict(int) for x, y in targets: n_r[x] += 1 n_c[y] += 1 rows, n_r_max = get_keys_of_max_value(n_r) columns, n_c_max = get_keys_of_max_value(n_c) for r in rows: for c in columns: if (r, c) not in targets: print((n_r_max + n_c_max)) break else: continue break else: print((n_r_max + n_c_max - 1))
from collections import defaultdict def get_keys_of_max_value(d): v_max = 0 keys = [] for k, v in list(d.items()): if v_max < v: v_max = v keys = [k] elif v_max == v: keys.append(k) return keys, v_max h, w, m = list(map(int, input().split())) targets = {tuple(map(int, input().split())) for _ in range(m)} n_r = defaultdict(int) n_c = defaultdict(int) for x, y in targets: n_r[x] += 1 n_c[y] += 1 rows, n_r_max = get_keys_of_max_value(n_r) columns, n_c_max = get_keys_of_max_value(n_c) for r in rows: for c in columns: if (r, c) not in targets: print((n_r_max + n_c_max)) break else: continue break else: print((n_r_max + n_c_max - 1))
p02580
from collections import Counter 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())) S = Counter(h) T = Counter(w) if (S.most_common()[0][1] > T.most_common()[0][1]): for i in range(M): if (h[i] == S.most_common()[0][0]): w[i] = 'boom' w1 = [s for s in w if s != 'boom'] T = Counter(w1) for i in range(len(w1)): if (w1[i] == T.most_common()[0][0]): w1[i] = 'boom' w2 = [s for s in w1 if s != 'boom'] print((M-len(w2))) else: for i in range(M): if (w[i] == T.most_common()[0][0]): h[i] = 'boom' h1 = [s for s in h if s != 'boom'] S = Counter(h1) for i in range(len(h1)): if (h1[i] == S.most_common()[0][0]): h1[i] = 'boom' h2 = [s for s in h1 if s != 'boom'] print((M-len(h2)))
from collections import Counter import sys 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())) S = Counter(h) T = Counter(w) if (M == 1): print((1)) else: if (S.most_common()[0][1] > T.most_common()[0][1]): smc = S.most_common()[0][0] for i in range(M): if (h[i] == smc): w[i] = 'boom' w1 = [s for s in w if s != 'boom'] T = Counter(w1) if (len(w1) == 0): print(M) sys.exit() tmc = T.most_common()[0][0] for i in range(len(w1)): if (w1[i] == tmc): w1[i] = 'boom' w2 = [s for s in w1 if s != 'boom'] print((M-len(w2))) else: tmc = T.most_common()[0][0] for i in range(M): if (w[i] == tmc): h[i] = 'boom' h1 = [s for s in h if s != 'boom'] S = Counter(h1) if (len(h1) == 0): print(M) sys.exit() smc = S.most_common()[0][0] for i in range(len(h1)): if (h1[i] == smc): h1[i] = 'boom' h2 = [s for s in h1 if s != 'boom'] print((M-len(h2)))
p02580
H, W, M = list(map(int, input().split())) A = [0]*H B = [0]*W D = set() for _ in range(M): h,w = list(map(int, input().split())) A[h-1] += 1 B[w-1] += 1 D.add((h-1,w-1)) a, b = max(A), max(B) res = a+b-1 for i in range(H): for j in range(W): if (A[i],B[j]) == (a,b): if (i,j) not in D: print((res+1)) exit() print(res)
H, W, M = list(map(int, input().split())) A = [0]*H B = [0]*W D = set() for _ in range(M): h,w = list(map(int, input().split())) A[h-1] += 1 B[w-1] += 1 D.add((h-1,w-1)) a, b = max(A), max(B) res = a+b-1 E, F = [], [] for i in range(H): if A[i] == a: E.append(i) for j in range(W): if B[j] == b: F.append(j) for i in E: for j in F: if (i,j) not in D: print((res+1)) exit() print(res)
p02580
H, W, M = list(map(int, input().split())) h = [0] * (H+1) w = [0] * (W+1) l = set() for i in range(M): x, y = list(map(int, input().split())) h[x] += 1 w[y] += 1 l.add((x, y)) a = [i for i, x in enumerate(h) if x == max(h)] b = [i for i, x in enumerate(w) if x == max(w)] flag = False for s in a: for t in b: if (s, t) not in l: flag = True break if flag: break ans = max(h)+max(w) if not flag: ans -= 1 print(ans)
H, W, M = list(map(int, input().split())) h = [0] * (H+1) w = [0] * (W+1) l = set() for i in range(M): x, y = list(map(int, input().split())) h[x] += 1 w[y] += 1 l.add((x, y)) c = max(h) d = max(w) a = [i for i, x in enumerate(h) if x == c] b = [i for i, x in enumerate(w) if x == d] flag = False for s in a: for t in b: if (s, t) not in l: flag = True break if flag: break ans = c+d if not flag: ans -= 1 print(ans)
p02580
h,w,n=list(map(int,input().split())) H=[0]*h W=[0]*w L=[[0 for i in range(w)] for i in range(h)] for i in range(n): a,b=list(map(int,input().split())) L[a-1][b-1]=1 H[a-1]+=1 W[b-1]+=1 h_max=max(H) w_max=max(W) H_max=[i+1 for i, x in enumerate(H) if x == h_max] W_max=[i+1 for i, x in enumerate(W) if x == w_max] ans=h_max+w_max-1 for hh in H_max: for ww in W_max: if L[hh-1][ww-1]==0: ans+=1 break else: continue break print(ans)
h,w,n=list(map(int,input().split())) H=[0]*h W=[0]*w L=[(0,0)]*n for i in range(n): a,b=list(map(int,input().split())) L[i]=(a,b) H[a-1]+=1 W[b-1]+=1 h_max=max(H) w_max=max(W) ans=h_max+w_max cnt=0 for l in L: if H[l[0]-1]==h_max and W[l[1]-1]==w_max: cnt+=1 if H.count(h_max)*W.count(w_max)==cnt: ans-=1 print(ans)
p02580
import sys readline = sys.stdin.buffer.readline from collections import defaultdict dic1 = defaultdict(int) def even(n): return 1 if n%2==0 else 0 H,W,M = list(map(int,readline().split())) columns = [0]*W row = [0]*H for i in range(M): h,w = list(map(int,readline().split())) h,w = h-1,w-1 dic1[(h,w)] = 1 columns[w] += 1 row[h] += 1 def rank(lst,syoujun=False): res2 = list(set(lst)) ans = [] if syoujun: res2.sort() else: res2.sort(reverse=True) dic1 = dict() for i in range(len(res2)): dic1[res2[i]] = i for idx,i in enumerate(lst): if dic1[i] == 0: ans.append(idx) return ans col2 = rank(columns) row2 = rank(row) ans = 0 for i in col2: for j in row2: if dic1[(j,i)]: ans = max(ans,columns[i]+row[j]-1) else: ans = max(ans,columns[i]+row[j]) print(ans)
import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 H,W,M = list(map(int,readline().split())) col = [0]*W row = [0]*H elements = [] for i in range(M): h,w = list(map(int,readline().split())) h,w = h-1,w-1 elements.append((h,w)) col[w] += 1 row[h] += 1 def rank(lst,syoujun=False): res2 = list(set(lst)) ans = [] if syoujun: res2.sort() else: res2.sort(reverse=True) dic1 = dict() for i in range(len(res2)): dic1[res2[i]] = i for i in lst: #ans.append(dic1[i]) #zero-indexed ans.append(dic1[i] + 1) #one-indexed return ans col2 = rank(col) row2 = rank(row) cmax = col2.count(1) rmax = row2.count(1) counter = 0 for i,j in elements: if col2[j] == 1 and row2[i] == 1: counter += 1 if counter == cmax*rmax: print((max(col) + max(row)-1)) else: print((max(col) + max(row)))
p02580
h,w,m=list(map(int,input().split())) a=[list(map(int,input().split())) for _ in range(m)] b,c=[0]*h,[0]*w for t1,t2 in a: b[t1-1]+=1 c[t2-1]+=1 bm,cm=max(b),max(c) b1,c1=[],[] d=[] for x,y in a: d.append((x-1,y-1)) d=set(d) for i in range(h): if b[i]==bm: b1.append(i) for i in range(w): if c[i]==cm: c1.append(i) f=1 for i in b1: for j in c1: if (i,j) not in d: f=0 print((bm+cm-f))
h,w,m=list(map(int,input().split())) a=[list(map(int,input().split())) for _ in range(m)] b,c=[0]*h,[0]*w for t1,t2 in a: b[t1-1]+=1 c[t2-1]+=1 bm,cm=max(b),max(c) b1,c1=[],[] d=[] for x,y in a: d.append((x-1,y-1)) d=set(d) for i in range(h): if b[i]==bm: b1.append(i) for i in range(w): if c[i]==cm: c1.append(i) for i in b1: for j in c1: if (i,j) not in d: print((bm+cm)) exit() print((bm+cm-1))
p02580
import pprint H, W, M = list(map(int, input().split())) bombs = set() hCount = [0]*H vCount = [0]*W for i in range(M): h, w = list(map(int, input().split())) h -= 1; w -= 1; hCount[h] += 1 vCount[w] += 1 bombs.add((h, w)) hMax = max(hCount) vMax = max(vCount) hMaxIndex = [i for i, x in enumerate(hCount) if x==max(hCount)] vMaxIndex = [i for i, x in enumerate(vCount) if x==max(vCount)] ans = -1 for x in vMaxIndex: for y in hMaxIndex: if (y, x) in bombs: continue else: print((hMax + vMax)) exit() print((hMax + vMax - 1))
import pprint H, W, M = list(map(int, input().split())) bombs = set() hCount = [0]*H vCount = [0]*W for i in range(M): h, w = list(map(int, input().split())) h -= 1; w -= 1; hCount[h] += 1 vCount[w] += 1 bombs.add((h, w)) hMax = max(hCount) vMax = max(vCount) hMaxIndex = [i for i, x in enumerate(hCount) if x==hMax] vMaxIndex = [i for i, x in enumerate(vCount) if x==vMax] ans = -1 for x in vMaxIndex: for y in hMaxIndex: if (y, x) in bombs: continue else: print((hMax + vMax)) exit() print((hMax + vMax - 1))
p02580
H, W, M = list(map(int, input().split())) bomb = [tuple([int(a) - 1 for a in input().split()]) for _ in range(M)] cntRow = [0] * H cntCol = [0] * W for h, w in bomb: cntRow[h] += 1 cntCol[w] += 1 mxR = max(cntRow) mxC = max(cntCol) R = set([h for h in range(H) if cntRow[h] == mxR]) C = set([w for w in range(W) if cntCol[w] == mxC]) ans = mxR + mxC if len([0 for h, w in bomb if h in R and w in C]) == len(R) * len(C): ans -= 1 print(ans)
H, W, M = list(map(int, input().split())) bombs = set([tuple(map(int, input().split())) for _ in range(M)]) cntH = [0] * (H + 1) cntW = [0] * (W + 1) for h, w in bombs: cntH[h] += 1 cntW[w] += 1 mxH = max(cntH) mxW = max(cntW) ans = mxH + mxW - 1 mxH = [h for h in range(1, H + 1) if cntH[h] == mxH] mxW = [w for w in range(1, W + 1) if cntW[w] == mxW] for h in mxH: for w in mxW: if not (h, w) in bombs: ans += 1 print(ans) exit() print(ans)
p02580
import sys input = sys.stdin.readline def main(): ans = 0 H, W, M = list(map(int, input().split())) bombs = [] hs = [0]*(H) ws = [0]*(W) for _ in range(M): h, w = list(map(int, input().split())) bombs.append([h-1, w-1]) hs[h-1] += 1 ws[w-1] += 1 maxh = max(hs) maxw = max(ws) ans = maxh + maxw maxhindex = [i for i, x in enumerate(hs) if x == maxh] maxwindex = [i for i, x in enumerate(ws) if x == maxw] isfound = False for i in maxhindex: for j in maxwindex: if [i, j] not in bombs: print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): ans = 0 H, W, M = list(map(int, input().split())) bombs = [] hs = [0]*(H) ws = [0]*(W) for _ in range(M): h, w = list(map(int, input().split())) bombs.append(tuple([h-1, w-1])) hs[h-1] += 1 ws[w-1] += 1 maxh = max(hs) maxw = max(ws) ans = maxh + maxw maxhindex = [i for i, x in enumerate(hs) if x == maxh] maxwindex = [i for i, x in enumerate(ws) if x == maxw] isfound = False bombs = set(bombs) for i in maxhindex: for j in maxwindex: if (i, j) not in bombs: print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
p02580
import sys input = sys.stdin.readline def main(): ans = 0 H, W, M = list(map(int, input().split())) bombs = [] hs = [0]*(H) ws = [0]*(W) for _ in range(M): h, w = list(map(int, input().split())) bombs.append(tuple([h-1, w-1])) hs[h-1] += 1 ws[w-1] += 1 maxh = max(hs) maxw = max(ws) ans = maxh + maxw maxhindex = [i for i, x in enumerate(hs) if x == maxh] maxwindex = [i for i, x in enumerate(ws) if x == maxw] isfound = False bombs = set(bombs) for i in maxhindex: for j in maxwindex: if (i, j) not in bombs: print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): ans = 0 H, W, M = list(map(int, input().split())) bombs = [] hs = [0]*(H) ws = [0]*(W) for _ in range(M): h, w = list(map(int, input().split())) bombs.append(tuple([h-1, w-1])) hs[h-1] += 1 ws[w-1] += 1 maxh = max(hs) maxw = max(ws) ans = maxh + maxw maxhindex = [i for i, x in enumerate(hs) if x == maxh] maxwindex = [i for i, x in enumerate(ws) if x == maxw] bombs = set(bombs) for i in maxhindex: for j in maxwindex: if (i, j) not in bombs: print(ans) exit() print((ans-1)) if __name__ == '__main__': main()
p02580
h,w,m = list(map(int, input().split())) hl = [0] * h wl = [0] * w dic = set() for i in range(m): x,y = list(map(int, input().split())) dic.add((x,y)) hl[x-1] += 1 wl[y-1] += 1 h_max = max(hl) r = [i for i in range(h) if hl[i] == h_max] w_max = max(wl) c = [i for i in range(w) if wl[i] == w_max] flg = 0 for rc in r: for cc in c: if (rc+1,cc+1) not in dic: flg = 1 if flg == 0: print((h_max + w_max - 1)) else: print((h_max + w_max))
def main(): h,w,m = list(map(int, input().split())) hl = [0] * h wl = [0] * w dic = set() for i in range(m): x,y = list(map(int, input().split())) dic.add((x,y)) hl[x-1] += 1 wl[y-1] += 1 h_max = max(hl) r = [i for i in range(h) if hl[i] == h_max] w_max = max(wl) c = [i for i in range(w) if wl[i] == w_max] flg = 0 for rc in r: for cc in c: if (rc+1,cc+1) not in dic: print((h_max + w_max)) return print((h_max + w_max - 1)) if __name__ == '__main__': main()
p02580
h,w,m=list(map(int, input().split())) hw=[list(map(int, input().split())) for _ in range(m)] tate=[] yoko=[] for i in range(m): tate.append(hw[i][0]) yoko.append(hw[i][1]) from collections import Counter tatec=Counter(tate).most_common() yokoc=Counter(yoko).most_common() c_1_max=tatec[0][1] c_1s=[] for t in tatec: if t[1]==c_1_max: c_1s.append(t[0]) else: break c_2_max=yokoc[0][1] c_2s=[] for y in yokoc: if y[1]==c_2_max: c_2s.append(y[0]) else: break flag=False for c_1 in c_1s: for c_2 in c_2s: tmp_flag=0 for i in range(m): h_i=hw[i][0] w_i=hw[i][1] if h_i!=c_1 or w_i!=c_2: tmp_flag+=1 if tmp_flag==m: flag=True if flag: break if flag: break print((max(tatec[0][1]+yokoc[0][1], 1) if flag else max(tatec[0][1]+yokoc[0][1]-1, 1)))
h,w,m=list(map(int, input().split())) hw=[list(map(int, input().split())) for _ in range(m)] y_list=[0]*h x_list=[0]*w for h_i, w_i in hw: y_list[h_i-1]+=1 x_list[w_i-1]+=1 my_cnt=max(y_list) mx_cnt=max(x_list) y_cnt=0 x_cnt=0 my_set=set() mx_set=set() for h_i, w_i in hw: if y_list[h_i-1]==my_cnt: my_set.add(h_i-1) if x_list[w_i-1]==mx_cnt: mx_set.add(w_i-1) cnt=0 for h_i, w_i in hw: if y_list[h_i-1]==my_cnt and x_list[w_i-1]==mx_cnt: cnt+=1 print((my_cnt+mx_cnt-1 if cnt==len(my_set)*len(mx_set) else my_cnt+mx_cnt))
p02580
h,w,m=list(map(int,input().split())) r=dict() c=dict() pos=[] rmax=0 cmax=0 for i in range(m): row,col=list(map(int,input().split())) if(row in r): r[row]+=1 rmax=max(r[row],rmax) else: r[row]=1 rmax=max(r[row],rmax) if(col in c): c[col]+=1 cmax=max(c[col],cmax) else: c[col]=1 cmax=max(c[col],cmax) pos.append(str(row)+str(col)) sorted(list(r.items()),key=lambda x:x[1]) sorted(list(c.items()),key=lambda x:x[1]) ans=-100 for i in list(r.keys()): if(r[i]<rmax): continue for j in list(c.keys()): if(c[j]<cmax): continue tmp=r[i]+c[j] if((str(i)+str(j)) in pos): tmp-=1 ans=max(ans,tmp) print(ans)
h,w,m=list(map(int,input().split())) row=[0 for i in range(h)] col=[0 for i in range(w)] a=[] for i in range(m): r,c=[int(x)-1 for x in input().split()] a.append([r,c]) row[r]+=1 col[c]+=1 rmax=max(row) cmax=max(col) ans=rmax+cmax flag=row.count(rmax)*col.count(cmax) for i,j in a: if(row[i]==rmax and col[j]==cmax): flag-=1 if(flag==0): ans-=1 print(ans)
p02580
import sys from collections import deque def input(): return sys.stdin.readline().rstrip() def main(): H, W, M = list(map(int, input().split())) lh = [0] * H lw = [0] * W s = set() for _ in range(M): h, w = list(map(int, input().split())) lh[h - 1] += 1 lw[w - 1] += 1 s.add((h-1, w-1)) maxh = max(lh) maxw = max(lw) for i in range(H): if lh[i] !=maxh: continue for j in range(W): if lw[j] !=maxw: continue if (i,j) not in s: print((maxh+maxw)) exit() print((maxh+maxw-1)) if __name__ == "__main__": main()
import sys from collections import deque def input(): return sys.stdin.readline().rstrip() def main(): H, W, M = list(map(int, input().split())) lh = [0] * H lw = [0] * W s = set() for _ in range(M): h, w = list(map(int, input().split())) lh[h - 1] += 1 lw[w - 1] += 1 s.add((h-1, w-1)) maxh = max(lh) maxw = max(lw) wlist=[] for j in range(W): if maxw==lw[j]: wlist.append(j) for i in range(H): if lh[i] !=maxh: continue for j in wlist: if (i,j) not in s: print((maxh+maxw)) exit() print((maxh+maxw-1)) if __name__ == "__main__": main()
p02580
import collections h, w, m = list(map(int, input().split())) x = [] y = [] bomb = [] for i in range(m): tmp_x, tmp_y = list(map(int, input().split())) x.append(tmp_x) y.append(tmp_y) bomb.append([tmp_x, tmp_y]) c_x = collections.Counter(x) c_y = collections.Counter(y) _max_x = c_x.most_common()[0][1] _max_y = c_y.most_common()[0][1] count = 0 for i in bomb: if c_x[i[0]] == _max_x and c_y[i[1]] == _max_y: count += 1 if count == len([kv[0] for kv in list(c_x.items()) if kv[1] == max(c_x.values())]) * len([kv[0] for kv in list(c_y.items()) if kv[1] == max(c_y.values())]): print((_max_x + _max_y - 1)) else: print((_max_x + _max_y))
h,w,n=list(map(int,input().split())) H=[0]*h W=[0]*w L=[(0,0)]*n for i in range(n): a,b=list(map(int,input().split())) L[i]=(a,b) H[a-1]+=1 W[b-1]+=1 h_max=max(H) w_max=max(W) ans=h_max+w_max cnt=0 for l in L: if H[l[0]-1]==h_max and W[l[1]-1]==w_max: cnt+=1 if H.count(h_max)*W.count(w_max)==cnt: ans-=1 print(ans)
p02580
import heapq H, W, M = list(map(int, input().split())) bn_h = {} bn_v = {} for i in range(M): h, w = list(map(int, input().split())) bn_h.setdefault(h, set()) bn_h[h].add(w) bn_v.setdefault(w, set()) bn_v[w].add(h) b1 = sorted(list(bn_h.items()), key = lambda x:len(x[1]), reverse=True) b2 = sorted(list(bn_v.items()), key = lambda x:len(x[1]), reverse=True) m1 = len(b1[0][1]) m2 = len(b2[0][1]) max_result = 0 for i in b1: h, sh = i if len(sh) < m1: break for j in b2: v, sv = j if len(sv) < m2: break result = len(sh) + len(sv) - 1 if h not in sv: result += 1 max_result = max(max_result, result) print(max_result)
import heapq def main(): H, W, M = list(map(int, input().split())) bn_h = {} bn_v = {} for i in range(M): h, w = list(map(int, input().split())) bn_h.setdefault(h, set()) bn_h[h].add(w) bn_v.setdefault(w, set()) bn_v[w].add(h) b1 = sorted(list(bn_h.items()), key = lambda x:len(x[1]), reverse=True) b2 = sorted(list(bn_v.items()), key = lambda x:len(x[1]), reverse=True) m1 = len(b1[0][1]) m2 = len(b2[0][1]) flag = False max_result = 0 for i in b1: h, sh = i if len(sh) < m1: break for j in b2: v, sv = j if len(sv) < m2: break result = len(sh) + len(sv) - 1 if h not in sv: result += 1 flag = True max_result = max(max_result, result) if flag == True: break if flag == True: break print(max_result) if __name__ == '__main__': main()
p02580
h, w, m = list(map(int, input().split())) bord_x, bord_y = [0 for i in range(h)], [0 for i in range(w)] bord = [[0 for _j in range(w)] for _i in range(h)] hw = [] for _i in range(m): s, t = list(map(int, input().split())) s -= 1 t -= 1 bord_x[s] += 1 bord_y[t] += 1 hw.append([s, t]) x_max, y_max = max(bord_x), max(bord_y) cnt = 0 for i, j in hw: if bord_x[i] == x_max and bord_y[j] == y_max: cnt += 1 if cnt == bord_x.count(x_max)*bord_y.count(y_max): x_max -= 1 print((x_max+y_max))
h, w, m = list(map(int, input().split())) bord_x, bord_y = [0]*h, [0]*w hw = [] for _i in range(m): s, t = list(map(int, input().split())) s -= 1 t -= 1 bord_x[s] += 1 bord_y[t] += 1 hw.append([s, t]) x_max, y_max = max(bord_x), max(bord_y) cnt = 0 for i, j in hw: if bord_x[i] == x_max and bord_y[j] == y_max: cnt += 1 if cnt == bord_x.count(x_max)*bord_y.count(y_max): x_max -= 1 print((x_max+y_max))
p02580
H, W, M = list(map(int, input().split())) h = [0 for i in range(H)] w = [0 for i in range(W)] dp = [[0 for i in range(W)] for j in range(H)] for i in range(M): hh, ww = list(map(int, input().split())) dp[hh - 1][ww - 1] += 1 for i in range(H): h[i] = sum(dp[i]) for i in range(W): w[i] = sum(dp[j][i] for j in range(H)) hhh = max(h) www = max(w) hhhh = [i for i, x in enumerate(h) if x == hhh] wwww = [i for i, x in enumerate(w) if x == www] check = 0 for i in hhhh: if check == 1: break for j in wwww: if dp[i][j] == 0: check = 1 break print((hhh + www - (1 - check)))
H, W, M = list(map(int, input().split())) h = [0 for i in range(H)] w = [0 for i in range(W)] DP = [] for i in range(M): hh, ww = list(map(int, input().split())) h[hh - 1] += 1 w[ww - 1] += 1 DP.append((hh - 1, ww - 1)) hhh = max(h) www = max(w) hhhh = [i for i, x in enumerate(h) if x == hhh] wwww = [i for i, x in enumerate(w) if x == www] check = 0 for i in hhhh: for j in wwww: if (i, j) not in DP: check = 1 break print((hhh + www - (1 - check)))
p02580
import sys h,w,m = list(map(int, input().split())) h_t = [] w_t = [] s = [] for i1 in range(h): h_t.append(0) for i2 in range(w): w_t.append(0) for i in range(h): s.append([]) for j in range(w): s[i].append(0) for i3 in range(m): hi,wi = list(map(int, input().split())) h_t[hi-1] += 1 w_t[wi-1] += 1 s[hi-1][wi-1] = 1 hmax = max(h_t) wmax = max(w_t) hmaxi = [i for i, v in enumerate(h_t) if v == max(h_t)] wmaxi = [i for i, v in enumerate(w_t) if v == max(w_t)] for ht in hmaxi: for wt in wmaxi: if s[ht][wt] == 0: print((hmax + wmax)) sys.exit() print((hmax + wmax-1))
import sys h,w,m = list(map(int, input().split())) h_t = [0 for _ in range(h)] w_t = [0 for _ in range(w)] t = [] for _ in range(m): hi,wi = list(map(int, input().split())) h_t[hi-1] += 1 w_t[wi-1] += 1 t.append([hi-1,wi-1]) hmax = max(h_t) wmax = max(w_t) hmaxi = [i1 for i1 in range(h) if h_t[i1] == hmax] wmaxi = [i2 for i2 in range(w) if w_t[i2] == wmax] c = len(hmaxi)*len(wmaxi) d = 0 for ht,wt in t: if h_t[ht] == hmax: if w_t[wt] == wmax: d += 1 if c ==d: print((hmax + wmax-1)) else: print((hmax + wmax))
p02580
h,w,m=list(map(int,input().split())) h_=[0]*(h+1) w_=[0]*(w+1) plot=set() for _ in range(m): x,y=list(map(int,input().split())) h_[x]+=1 w_[y]+=1 plot.add((x,y)) x=max(h_) y=max(w_) a=[i for i,v in enumerate(h_) if v==x] b=[j for j,q in enumerate(w_) if q==y] u=0 c=0 for i in a: for j in b: if (i,j) in plot: u+=1 c+=1 ans=x+y if u==c: print((ans-1)) else: print(ans)
h,w,m=list(map(int,input().split())) h_=[0]*(h+1) w_=[0]*(w+1) plot=set() for _ in range(m): x,y=list(map(int,input().split())) h_[x]+=1 w_[y]+=1 plot.add((x,y)) x=max(h_) y=max(w_) a=[i for i,v in enumerate(h_) if v==x] b=[j for j,q in enumerate(w_) if q==y] ans=x+y-1 c=False for i in a: for j in b: if (i,j) not in plot: c=True break if c: break if c: print((ans+1)) else: print(ans)
p02580
H,W,M=list(map(int,input().split())) l = [ list(map(int,input().split(" "))) for i in range(M)] h=[0]*H w=[0]*W for i in range(M): h[l[i][0]-1]+=1 w[l[i][1]-1]+=1 maxh=max(h) maxw=max(w) hlist=[] wlist=[] for i in range(H): if h[i]==maxh: hlist.append(i) for i in range(W): if w[i]==maxw: wlist.append(i) c=0 for i in hlist: for j in wlist: flag=0 for k in range(M): if (i+1)==l[k][0] and (j+1)==l[k][1]: flag=1 break if flag==0: print((maxh+maxw)) c=1 break if c==1: break if c==0: print((maxh+maxw-1))
H,W,M=list(map(int,input().split())) l = [ list(map(int,input().split(" "))) for i in range(M)] h=[0]*H w=[0]*W for i in range(M): h[l[i][0]-1]+=1 w[l[i][1]-1]+=1 maxh=max(h) maxw=max(w) hlist=[] wlist=[] for i in range(H): if h[i]==maxh: hlist.append(i) for i in range(W): if w[i]==maxw: wlist.append(i) c=0 for i in range(M): if h[l[i][0]-1]==maxh and w[l[i][1]-1]==maxw: c+=1 if len(hlist)*len(wlist)==c: print((maxh+maxw-1)) else: print((maxh+maxw))
p02580
h,w,m=list(map(int,input().split())) s=[] t=[] st=[[] for i in range(h+1)] for i in range(m): H,W=list(map(int,input().split())) s.append(H) t.append(W) st[H].append(W) from collections import Counter u=Counter(s) v=Counter(t) max_u=max(u.values()) max_v=max(v.values()) import sys for i in u: if u[i]==max_u: for j in v: if v[j]==max_v: if j not in st[i]: print((max_u+max_v)) sys.exit() print((max_u+max_v-1))
h,w,m=list(map(int,input().split())) s=[] t=[] for i in range(m): H,W=list(map(int,input().split())) s.append(H) t.append(W) from collections import Counter u=Counter(s) v=Counter(t) max_u=max(u.values()) max_u_set = set([kv[0] for kv in list(u.items()) if kv[1]==max_u]) max_v=max(v.values()) max_v_set = set([kv[0] for kv in list(v.items()) if kv[1]==max_v]) check=len(max_u_set)*len(max_v_set) ans=0 for i in range(m): if u[s[i]]==max_u and v[t[i]]==max_v: ans=ans+1 if check-ans==0: print((max_u+max_v-1)) else: print((max_u+max_v))
p02580
H, W, M = list(map(int, input().split())) hw = [] h_cnt = [0] * H w_cnt = [0] * W hw = [tuple([int(x)-1 for x in input().split()]) for _ in range(M)] for h, w in hw: h_cnt[h] += 1 w_cnt[w] += 1 max_h = max(h_cnt) max_w = max(w_cnt) hs = [i for i in range(H) if h_cnt[i]==max_h] ws = [i for i in range(W) if w_cnt[i]==max_w] cnt = 0 for h, w in hw: if h in hs and w in ws: cnt += 1 if cnt < len(hs)*len(ws): print((max_h+max_w)) else: print((max_h+max_w-1))
H, W, M = list(map(int, input().split())) h_cnt = [0] * H w_cnt = [0] * W hw = [tuple([int(x)-1 for x in input().split()]) for _ in range(M)] for h, w in hw: h_cnt[h] += 1 w_cnt[w] += 1 max_h = max(h_cnt) max_w = max(w_cnt) hs = [i for i in range(H) if h_cnt[i]==max_h] ws = [i for i in range(W) if w_cnt[i]==max_w] ans = max_h+max_w-1 hw = set(hw) for h in hs: for w in ws: if (h, w) not in hw: print((max_h+max_w)) exit() print((max_h+max_w-1))
p02580
from collections import defaultdict h, w, m = list(map(int, input().split())) targets = defaultdict(int) targets_count_yoko = defaultdict(int) targets_count_tate = defaultdict(int) for _ in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 targets_count_yoko[x] += 1 targets_count_tate[y] += 1 targets[(y, x)] = -1 max_row = max(targets_count_yoko.values()) max_line = max(targets_count_tate.values()) y_idx = [] x_idx = [] max_count_x = 0 max_count_y = 0 for i in range(w): if targets_count_yoko[i] == max_row: x_idx.append(i) max_count_x += 1 for i in range(h): if targets_count_tate[i] == max_line: y_idx.append(i) max_count_y += 1 ans = max_line + max_row kumi = max_count_x*max_count_y for key_y, key_x in list(targets.keys()): if key_y in y_idx and key_x in x_idx: kumi -= 1 if kumi == 0: break if kumi == 0: print((ans-1)) else: print(ans)
from collections import defaultdict h, w, m = list(map(int, input().split())) targets = defaultdict(int) targets_count_yoko = defaultdict(int) targets_count_tate = defaultdict(int) for _ in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 targets_count_yoko[x] += 1 targets_count_tate[y] += 1 targets[(y, x)] = -1 max_row = max(targets_count_yoko.values()) max_line = max(targets_count_tate.values()) y_idx = defaultdict(bool) x_idx = defaultdict(bool) max_count_x = 0 max_count_y = 0 for i in range(w): if targets_count_yoko[i] == max_row: x_idx[i] = True max_count_x += 1 for i in range(h): if targets_count_tate[i] == max_line: y_idx[i] = True max_count_y += 1 ans = max_line + max_row kumi = max_count_x*max_count_y for key_y, key_x in list(targets.keys()): if y_idx[key_y] and x_idx[key_x]: kumi -= 1 if kumi == 0: break if kumi == 0: print((ans-1)) else: print(ans)
p02580
from collections import defaultdict h, w, m = list(map(int, input().split())) targets = [] targets_count_yoko = [0]*w targets_count_tate = [0]*h for _ in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 targets_count_yoko[x] += 1 targets_count_tate[y] += 1 targets.append((y, x)) max_row = max(targets_count_yoko) max_line = max(targets_count_tate) y_idx = [i for i, v in enumerate(targets_count_tate) if v == max_line] x_idx = [i for i, v in enumerate(targets_count_yoko) if v == max_row] ans = max_line + max_row flag = False for y in y_idx: for x in x_idx: if (y, x) not in targets: flag = True break else: continue break if flag: print(ans) else: print((ans-1))
from collections import defaultdict h, w, m = list(map(int, input().split())) targets = [] targets_count_w = defaultdict(int) targets_count_h = defaultdict(int) for _ in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 targets_count_w[x] += 1 targets_count_h[y] += 1 targets.append((y, x)) max_w = max(targets_count_w.values()) max_h = max(targets_count_h.values()) y_idx = defaultdict(bool) x_idx = defaultdict(bool) max_count_x = 0 max_count_y = 0 for i in range(w): if targets_count_w[i] == max_w: x_idx[i] = True max_count_x += 1 for i in range(h): if targets_count_h[i] == max_h: y_idx[i] = True max_count_y += 1 ans = max_w + max_h kumi = max_count_x*max_count_y for ty, tx in targets: if y_idx[ty] and x_idx[tx]: kumi -= 1 if kumi == 0: break if kumi == 0: print((ans-1)) else: print(ans)
p02580
from collections import defaultdict H, W, M = list(map(int, input().split())) tate = defaultdict(int) yoko = defaultdict(int) T = {} for i in range(M): h, w = list(map(int, input().split())) tate[h-1] += 1 yoko[w-1]+= 1 T[(h-1, w-1)] = 1 tate = sorted(list(tate.items()), key=lambda x:x[1], reverse=True) yoko = sorted(list(yoko.items()), key=lambda x:x[1], reverse=True) tate_m = tate[0][1] yoko_m = yoko[0][1] ans = 0 for i in range(len(tate)): if tate[i][1] == tate_m: for j in range(len(yoko)): if yoko[j][1] == yoko_m: if (tate[i][0], yoko[j][0]) in T: ans = max(ans, tate_m + yoko_m - 1) else: ans = max(ans, tate_m + yoko_m) else: break else: break print(ans)
from collections import defaultdict H, W, M = list(map(int, input().split())) tate = defaultdict(int) yoko = defaultdict(int) T = {} for i in range(M): h, w = list(map(int, input().split())) tate[h-1] += 1 yoko[w-1]+= 1 T[(h-1, w-1)] = 1 tate = sorted(list(tate.items()), key=lambda x:x[1], reverse=True) yoko = sorted(list(yoko.items()), key=lambda x:x[1], reverse=True) tate_m = tate[0][1] yoko_m = yoko[0][1] ans = 0 for i in range(len(tate)): if ans == tate_m + yoko_m: break if tate[i][1] == tate_m: for j in range(len(yoko)): if yoko[j][1] == yoko_m: if (tate[i][0], yoko[j][0]) in T: ans = max(ans, tate_m + yoko_m - 1) else: ans = max(ans, tate_m + yoko_m) else: break else: break print(ans)
p02580
import sys input = sys.stdin.readline import heapq from collections import Counter H,W,M = list(map(int, input().split())) BH = [[0,i] for i in range(H)] BW = [[0,i] for i in range(W)] Bomb = set() for _ in range(M): h,w = list(map(int, input().split())) h,w = h-1,w-1 BH[h][0] += 1 BW[w][0] += 1 Bomb.add((h,w)) BH.sort(reverse=True) BW.sort(reverse=True) """ print(BombC) print(BH) print(BW) """ h = [] ans = 0 nowh, noww = 0,0 i,j = 0,0 BHMAX, BWMAX = BH[i][0], BW[j][0] heapq.heappush(h, (-BH[i][0] - BW[j][0], BH[i][1], BW[j][1], i,j)) while h: cost, nowh, noww,i,j = heapq.heappop(h) cost = -cost #print(cost,nowh,noww) if (nowh,noww) not in Bomb: ans = max(ans,cost) break else: ans = max(ans, cost-1) if i+1 < H and BH[i+1][0] == BHMAX: heapq.heappush(h, (-BH[i+1][0] - BW[j][0], BH[i+1][1], BW[j][1],i+1, j)) if j+1 < W and BW[i+1][0] == BWMAX: heapq.heappush(h, (-BH[i][0] - BW[j+1][0], BH[i][1], BW[j+1][1],i, j+1)) print(ans)
import sys input = sys.stdin.readline H,W,M = list(map(int, input().split())) BH = [0 for i in range(H)] BW = [0 for i in range(W)] Bomb = set() for _ in range(M): h,w = list(map(int, input().split())) h,w = h-1,w-1 BH[h] += 1 BW[w] += 1 Bomb.add((h,w)) BHMAX = max(BH) BWMAX = max(BW) HS = set() WS = set() for i in range(H): if BH[i] == BHMAX: HS.add(i) for i in range(W): if BW[i] == BWMAX: WS.add(i) ans = 0 cnt = 0 for h,w in Bomb: if h in HS and w in WS: ans = max(ans, BHMAX + BWMAX - 1) cnt += 1 if cnt < len(HS) * len(WS): ans = BHMAX + BWMAX print(ans)
p02580
H, W, M = list(map(int, input().split())) bom = [list(map(int, input().split())) for _ in range(M)] hBom = [0]*H wBom = [0]*W # 各行、各列の爆破対象をカウント for h, w in bom: hBom[h-1] += 1 wBom[w-1] += 1 # 爆破対象の最大数と最大になる行と列の番号を調べる maxHBom = max(hBom) maxWBom = max(wBom) maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom] maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom] # 爆破対象が最大になる行と列の組み合わせについて、 # 爆弾を配置する場所が爆破対象であるかないかで場合分け for h in maxHBomIndex: for w in maxWBomIndex: if [h+1, w+1] not in bom: print((maxHBom + maxWBom)) exit() else: print((maxHBom + maxWBom - 1))
H, W, M = list(map(int, input().split())) boms = [tuple(map(int, input().split())) for _ in range(M)] # boms = [list(map(int, input().split())) for _ in range(M)] hBom = [0]*H wBom = [0]*W # 各行、各列の爆破対象をカウント for h, w in boms: hBom[h-1] += 1 wBom[w-1] += 1 # 爆破対象の最大数と最大になる行と列の番号を調べる maxHBom = max(hBom) maxWBom = max(wBom) maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom] maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom] # 爆破対象が最大になる行と列の組み合わせについて、 # 爆弾を配置する場所が爆破対象であるかないかで場合分け boms = set(boms) for h in maxHBomIndex: for w in maxWBomIndex: if (h+1, w+1) not in boms: print((maxHBom + maxWBom)) exit() else: print((maxHBom + maxWBom - 1))
p02580
import sys H,W,M=list(map(int, input().split())) h=[] w=[] Hcount=[0 for _ in range(H)] Wcount=[0 for _ in range(W)] B=set() for i in range(M): hi,wi=list(map(int, input().split())) h.append(hi) w.append(wi) B.add((hi,wi)) Hcount[hi-1]+=1 Wcount[wi-1]+=1 h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)] w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)] #print(h_max,w_max) for ii in range(len(h_max)): for jj in range(len(w_max)): if (h_max[ii]+1,w_max[jj]+1) not in B: print((max(Hcount)+max(Wcount))) sys.exit() print((max(Hcount)+max(Wcount)-1))
import sys input = sys.stdin.readline def main(): H, W, M = list(map(int, input().split())) row = [0] * (H) col = [0] * (W) bomb = set() for _ in range(M): h, w = list(map(int, input().split())) bomb.add((h, w)) row[h-1] += 1 col[w-1] += 1 row_max = max(row) row_index_list = [i for i, v in enumerate(row) if v == row_max] col_max = max(col) col_index_list = [i for i, v in enumerate(col) if v == col_max] ans = row_max + col_max - 1 c = False for x in row_index_list: for y in col_index_list: if not (x + 1, y + 1) in bomb: c = True break if c: break if c: ans += 1 print(ans) if __name__ == '__main__': main()
p02580
import sys H,W,M=list(map(int, input().split())) h=[] w=[] Hcount=[0 for _ in range(H)] Wcount=[0 for _ in range(W)] B=set() for i in range(M): hi,wi=list(map(int, input().split())) #h.append(hi) #w.append(wi) B.add((hi,wi)) Hcount[hi-1]+=1 Wcount[wi-1]+=1 h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)] w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)] #print(h_max,w_max) for ii in range(len(h_max)): for jj in range(len(w_max)): if (h_max[ii]+1,w_max[jj]+1) not in B: print((max(Hcount)+max(Wcount))) sys.exit() print((max(Hcount)+max(Wcount)-1))
import sys H,W,M=list(map(int, input().split())) h=[] w=[] Hcount=[0 for _ in range(H)] Wcount=[0 for _ in range(W)] B=set() for i in range(M): hi,wi=list(map(int, input().split())) #h.append(hi) #w.append(wi) B.add((hi,wi)) Hcount[hi-1]+=1 Wcount[wi-1]+=1 Hcountmax=max(Hcount) Wcountmax=max(Wcount) h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax] w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax] #print(h_max,w_max) for ii in range(len(h_max)): for jj in range(len(w_max)): if (h_max[ii]+1,w_max[jj]+1) not in B: print((max(Hcount)+max(Wcount))) sys.exit() print((max(Hcount)+max(Wcount)-1))
p02580
import sys H,W,M=list(map(int, input().split())) h=[] w=[] Hcount=[0 for _ in range(H)] Wcount=[0 for _ in range(W)] B=set() for i in range(M): hi,wi=list(map(int, input().split())) #h.append(hi) #w.append(wi) B.add((hi,wi)) Hcount[hi-1]+=1 Wcount[wi-1]+=1 Hcountmax=max(Hcount) Wcountmax=max(Wcount) h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax] w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax] #print(h_max,w_max) for ii in range(len(h_max)): for jj in range(len(w_max)): if (h_max[ii]+1,w_max[jj]+1) not in B: print((max(Hcount)+max(Wcount))) sys.exit() print((max(Hcount)+max(Wcount)-1))
import sys H,W,M=list(map(int, input().split())) h=[] w=[] Hcount=[0 for _ in range(H)] Wcount=[0 for _ in range(W)] B=set() for i in range(M): hi,wi=list(map(int, input().split())) #h.append(hi) #w.append(wi) B.add((hi,wi)) Hcount[hi-1]+=1 Wcount[wi-1]+=1 Hcountmax=max(Hcount) Wcountmax=max(Wcount) h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax] w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax] #print(h_max,w_max) for ii in h_max: for jj in w_max: if (ii+1,jj+1) not in B: print((max(Hcount)+max(Wcount))) sys.exit() print((max(Hcount)+max(Wcount)-1))
p02580
# -*- coding: utf-8 -*- # スペース区切りの整数の入力 h, w, m = list(map(int, input().split())) h_list = [0]*h w_list = [0]*w # h_w_list = [[0 for j in range(w)] for i in range(h)] h_w_list = [] for zzz in range(m): # print("---") bom_h, bom_w = list(map(int, input().split())) # print(bom_h, bom_w) h_list[bom_h-1] += 1 w_list[bom_w-1] += 1 # h_w_list[bom_h-1][bom_w-1] = 1 h_w_list.append([bom_h, bom_w]) mh = max(h_list) mw = max(w_list) h_max_indexs = [i for i, v in enumerate(h_list) if v == mh] w_max_indexs = [i for i, v in enumerate(w_list) if v == mw] double_chance = False # print("---") for h_index in h_max_indexs: if double_chance: break for w_index in w_max_indexs: if double_chance: break # chance = h_w_list[h_index][w_index] != 1 chance = h_w_list.count([h_index + 1, w_index + 1]) == 0 # print(h_w_list) # print([h_index, w_index], chance) # print(h_index, w_index, chance) if chance: double_chance = True if double_chance: result = mh + mw else: result = mh + mw -1 print(result)
# -*- coding: utf-8 -*- # スペース区切りの整数の入力 h, w, m = list(map(int, input().split())) h_list = [0]*h w_list = [0]*w # h_w_list = [[0 for j in range(w)] for i in range(h)] # h_w_list = [] h_w_list = set() for zzz in range(m): # print("---") bom_h, bom_w = list(map(int, input().split())) # print(bom_h, bom_w) h_list[bom_h-1] += 1 w_list[bom_w-1] += 1 # h_w_list[bom_h-1][bom_w-1] = 1 # h_w_list.append([bom_h, bom_w]) h_w_list.add((bom_h, bom_w)) mh = max(h_list) mw = max(w_list) h_max_indexs = [i for i, v in enumerate(h_list) if v == mh] w_max_indexs = [i for i, v in enumerate(w_list) if v == mw] double_chance = False # print("---") for h_index in h_max_indexs: if double_chance: break for w_index in w_max_indexs: if double_chance: break # chance = h_w_list.count([h_index + 1, w_index + 1]) == 0 chance = (h_index + 1, w_index + 1) not in h_w_list if chance: double_chance = True if double_chance: result = mh + mw else: result = mh + mw -1 print(result)
p02580
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string from copy import deepcopy INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 h,w,m= LI() s=set() D1=defaultdict(int) D2=defaultdict(int) for _ in range(m): h,w=LI() D1[h-1]+=1 D2[w-1]+=1 s.add((h-1,w-1)) A=[[v,i] for i,v in list(D1.items())]+[[-INF,-INF]] B=[[v,i] for i,v in list(D2.items())]+[[-INF,-INF]] A.sort(reverse=True) B.sort(reverse=True) a_now=0 b_now=0 ans=-INF while True: av,ak=A[a_now] bv,bk = B[b_now] ans=max(ans,av+bv-int((ak,bk) in s)) if a_now==len(A)-2 and b_now==len(B)-2: break elif A[a_now+1][0]+B[b_now][0]>A[a_now][0]+B[b_now+1][0]: a_now+=1 else: b_now+=1 print(ans)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string from copy import deepcopy INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 h,w,m= LI() s=set() D1=defaultdict(int) D2=defaultdict(int) for _ in range(m): h,w=LI() D1[h-1]+=1 D2[w-1]+=1 s.add((h-1,w-1)) h_max = max(D1.values()) w_max = max(D2.values()) A=[i for i,v in list(D1.items()) if v==h_max] B=[i for i,v in list(D2.items()) if v==w_max] flg = 1 for i in A: for j in B: if (i, j) not in s: flg = 0 break print((w_max+h_max-flg))
p02580
import sys input = sys.stdin.readline r,c,m=list(map(int,input().split())) q=[list([int(x)-1 for x in input().split()]) for _ in range(m)] M=[[0 for i in range(c)] for _ in range(r)] for i,j in q: M[i][j]=1 rows = [0]*r cols = [0]*c for i in range(r): rows[i]=sum(M[i]) for i in range(c): A = [M[j][i] for j in range(r)] cols[i] = sum(A) #print(rows,cols) MAX = 0 for i in range(r): for j in range(c): if M[i][j]==1: MAX = max(MAX,rows[i]+cols[j]-1) else: MAX = max(MAX,rows[i]+cols[j]) print(MAX)
import sys input = sys.stdin.readline r,c,m=list(map(int,input().split())) q=set(tuple([int(x)-1 for x in input().split()]) for _ in range(m)) rows = [0]*r cols = [0]*c for i,j in q: rows[i]+=1 cols[j]+=1 MAXR = max(rows) MAXC = max(cols) ans = MAXR+MAXC-1 rlist=[] clist=[] for i in range(r): if rows[i]==MAXR: rlist.append(i) for j in range(c): if cols[j]==MAXC: clist.append(j) for i in rlist: for j in clist: if (i,j) in q: continue else: ans+=1 print(ans) sys.exit() print(ans)
p02580
from collections import defaultdict def main(): height, width, target_count = [int(x) for x in input().split()] count_by_height = defaultdict(int) count_by_width = defaultdict(int) bomb_is = set() for _ in range(target_count): bom_h, bom_w = [int(x) - 1 for x in input().split()] count_by_height[bom_h] += 1 count_by_width[bom_w] += 1 bomb_is.add((bom_h, bom_w)) max_h = max(v for v in list(count_by_height.values())) max_w = max(v for v in list(count_by_width.values())) max_h_index = [i for i, x in list(count_by_height.items()) if x == max_h] max_w_index = [i for i, x in list(count_by_width.items()) if x == max_w] no_cross = any( (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index) return max_h + max_w - (not no_cross) if __name__ == '__main__': ans = main() print(ans)
from collections import defaultdict def main(): height, width, target_count = [int(x) for x in input().split()] count_by_height = defaultdict(int) count_by_width = defaultdict(int) bomb_locations = set() for _ in range(target_count): h, w = [int(x) - 1 for x in input().split()] count_by_height[h] += 1 count_by_width[w] += 1 bomb_locations.add((h, w)) max_h = max(v for v in list(count_by_height.values())) max_w = max(v for v in list(count_by_width.values())) max_h_index = [i for i, x in list(count_by_height.items()) if x == max_h] max_w_index = [i for i, x in list(count_by_width.items()) if x == max_w] no_cross = any((h, w) not in bomb_locations for h in max_h_index for w in max_w_index) return max_h + max_w - (not no_cross) if __name__ == '__main__': print((main()))
p02580
# -*- coding: utf-8 -*- import sys import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H, W, M = list(map(int,readline().split())) h_cnt = [0]*(H+1) w_cnt = [0]*(W+1) data = [[False]*(W+1) for i in range(H+1)] for i in range(M): h,w = list(map(int,readline().split())) data[h][w] = True h_cnt[h] += 1 w_cnt[w] += 1 maxh = max(h_cnt) maxw = max(w_cnt) maxhInd = [] maxwInd = [] maxhInd = [i for i,a in enumerate(h_cnt) if a == maxh] maxwInd = [i for i,a in enumerate(w_cnt) if a == maxw] maxhCnt = len(maxhInd) maxwCnt = len(maxwInd) ans = maxh+maxw if maxhCnt * maxwCnt > M: print(ans) else: t = list(itertools.product(maxhInd, maxwInd)) for h,w in t: if data[h][w] == False: print(ans) sys.exit() print((ans-1))
# -*- coding: utf-8 -*- import sys import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H, W, M = list(map(int,readline().split())) h_cnt = [0]*(H+1) w_cnt = [0]*(W+1) bomb = [] for i in range(M): h,w = list(map(int,readline().split())) bomb.append((h,w)) h_cnt[h] += 1 w_cnt[w] += 1 maxh = max(h_cnt) maxw = max(w_cnt) maxhCnt = h_cnt.count(maxh) maxwCnt = w_cnt.count(maxw) total = maxhCnt*maxwCnt ans = maxh+maxw cnt = 0 for h,w in bomb: if h_cnt[h] == maxh and w_cnt[w] == maxw: cnt += 1 print((ans-1 if cnt == total else ans))
p02580
h,w,m=list(map(int,input().split())) lh=[0]*h lw=[0]*w l=[[0 for _ in range(w)] for _ in range(h)] for i in range(m): h1,w1=list(map(int,input().split())) l[h1-1][w1-1]=1 lh[h1-1]+=1 lw[w1-1]+=1 hmax=max(lh) wmax=max(lw) lh2=[] lw2=[] for i in range(h): if lh[i]==hmax: lh2.append(i) for i in range(w): if lw[i]==wmax: lw2.append(i) s=1 for m in lh2: for m2 in lw2: if l[m][m2]==0: s=0 print((hmax+wmax-s))
h,w,m=list(map(int,input().split())) lh=[0]*h lw=[0]*w l=set() for i in range(m): h1,w1=input().split() l.add(h1+"_"+w1) lh[int(h1)-1]+=1 lw[int(w1)-1]+=1 hmax=max(lh) wmax=max(lw) lh2=[] lw2=[] for i in range(h): if lh[i]==hmax: lh2.append(i) for i in range(w): if lw[i]==wmax: for m in lh2: if str(m+1)+"_"+str(i+1) not in l: print((hmax+wmax)) exit() print((hmax+wmax-1))
p02580
h, w, m = list(map(int, input().split())) HW = [[*[int(x)-1 for x in input().split()]] for _ in range(m)] sum_h = [[0,0] for _ in range(h)] # [sum, index] sum_w = [[0,0] for _ in range(w)] for i in range(m): h,w = HW[i] sum_h[h][0] += 1 sum_w[w][0] += 1 sum_h[h][1] = h sum_w[w][1] = w h_num_ix = {} for num,ix in sum_h: if not num in h_num_ix: h_num_ix[num] = set() h_num_ix[num].add(ix) w_num_ix = {} for num,ix in sum_w: if not num in w_num_ix: w_num_ix[num] = set() w_num_ix[num].add(ix) max_h_num = max(h_num_ix) max_w_num = max(w_num_ix) # print(h_num_ix) # print(w_num_ix) # print(max_h_num) # print(max_w_num) # print('====') max_num = max_h_num + max_w_num - 1 for h_ix in h_num_ix[max_h_num]: for w_ix in w_num_ix[max_w_num]: num = max_h_num + max_w_num if [h_ix, w_ix] in HW: continue max_num += 1 print(max_num) exit() print(max_num)
h, w, m = list(map(int, input().split())) HW = [[*[int(x)-1 for x in input().split()]] for _ in range(m)] sum_h = [[0,0] for _ in range(h)] # [sum, index] sum_w = [[0,0] for _ in range(w)] for i in range(m): h,w = HW[i] sum_h[h][0] += 1 sum_w[w][0] += 1 sum_h[h][1] = h sum_w[w][1] = w h_num_ix = {} for num,ix in sum_h: if not num in h_num_ix: h_num_ix[num] = set() h_num_ix[num].add(ix) w_num_ix = {} for num,ix in sum_w: if not num in w_num_ix: w_num_ix[num] = set() w_num_ix[num].add(ix) max_h_num = max(h_num_ix) max_w_num = max(w_num_ix) # print(sorted(HW)) # print('---') # print(h_num_ix) # print(w_num_ix) # print(max_h_num) # print(max_w_num) # print('====') SHW = set() for h,w in HW: SHW.add((h,w)) # print(SHW) max_num = max_h_num + max_w_num - 1 for h_ix in h_num_ix[max_h_num]: for w_ix in w_num_ix[max_w_num]: num = max_h_num + max_w_num # if [h_ix, w_ix] in HW: continue if (h_ix, w_ix) in SHW: continue max_num += 1 print(max_num) exit() print(max_num)
p02580
H, W, M = list(map(int, input().split())) HW = set(tuple([int(x)-1 for x in input().split()]) for _ in range(M)) sum_h = [0]*H; sum_w = [0]*W for h, w in HW: sum_h[h] += 1 sum_w[w] += 1 max_h_num = 0 h_num_ix = {} for i in range(H): num = sum_h[i] if num == 0: continue if not num in h_num_ix: h_num_ix[num] = set() h_num_ix[num].add(i) max_h_num = max(max_h_num, num) max_w_num = 0 w_num_ix = {} for i in range(W): num = sum_w[i] if num == 0: continue if not num in w_num_ix: w_num_ix[num] = set() w_num_ix[num].add(i) max_w_num = max(max_w_num, num) max_num = max_h_num + max_w_num - 1 for h_ix in h_num_ix[max_h_num]: for w_ix in w_num_ix[max_w_num]: if (h_ix, w_ix) in HW: continue print((max_num + 1)) exit() print(max_num)
H, W, M = list(map(int, input().split())) HW = set() sum_h = [0]*H; sum_w = [0]*W max_sum_h = max_sum_w = 0 for _ in range(M): h, w = [int(x)-1 for x in input().split()] HW.add((h, w)) sum_h[h] += 1 sum_w[w] += 1 max_sum_h = max(max_sum_h, sum_h[h]) max_sum_w = max(max_sum_w, sum_w[w]) hs = []; ws = [] for i in range(H): if sum_h[i] == max_sum_h: hs.append(i) for i in range(W): if sum_w[i] == max_sum_w: ws.append(i) ans = max_sum_h + max_sum_w - 1 for h in hs: for w in ws: if (h, w) in HW: continue print((ans + 1)) exit() print(ans)
p02580
import sys import math import fractions from collections import defaultdict import heapq from bisect import bisect_left,bisect stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: list(map(int, stdin.readline().split())) nl = lambda: list(map(int, stdin.readline().split())) H,W,M=nm() r=[0]*(10**6) c=[0]*(10**6) ans=0 mass=[] for i in range(M): h,w=nm() mass.append((h,w)) r[h]+=1 c[w]+=1 inds1=list(range(10**6)) inds1.sort(reverse=True,key=lambda x: r[x]) inds2=list(range(10**6)) inds2.sort(reverse=True,key=lambda x: c[x]) r.sort(reverse=True) c.sort(reverse=True) r1=0 l1=0 while(1): if(r[r1+1]==r[r1]): r1+=1 else: break while(1): if(c[l1+1]==c[l1]): l1+=1 else: break flag=False for i in range(r1+1): for j in range(l1+1): flag=True for k in mass: if(k[0]==inds1[i] and k[1]==inds2[j]): flag=False if(flag==True): print((r[0]+c[0])) sys.exit(0) print((r[0]+c[0]-1))
import sys import math import fractions from collections import defaultdict import heapq from bisect import bisect_left,bisect stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: list(map(int, stdin.readline().split())) nl = lambda: list(map(int, stdin.readline().split())) H,W,M=nm() r=[0]*(10**6) c=[0]*(10**6) mass=set() for i in range(M): h,w=nm() mass.add(H*h+w) r[h]+=1 c[w]+=1 rl=[] cl=[] r_max=0 for i in range(1,H+1): r_max=max(r[i],r_max) c_max=0 for i in range(1,W+1): c_max=max(c[i],c_max) for i in range(1,H+1): if(r[i]==r_max): rl.append(i) for i in range(1,W+1): if(c[i]==c_max): cl.append(i) for i in rl: for j in cl: if(i*H+j not in mass): print((r_max+c_max)) sys.exit(0) print((r_max+c_max-1))
p02580
h,w,m = list(map(int,input().split())) row = [0]*(h+1) col = [0]*(w+1) bombs = set([]) for i in range(m): a,b = list(map(int,input().split())) row[a] += 1 col[b] += 1 bombs.add((a,b)) r,c = max(row),max(col) for i in range(1,h+1): if row[i]!=r: continue for j in range(1,w+1): if col[j]!=c: continue if (i,j) not in bombs: print((r+c)) exit() else: print((r+c-1))
h,w,m = list(map(int,input().split())) row = [0]*(h+1) col = [0]*(w+1) bombs = set([]) for i in range(m): a,b = list(map(int,input().split())) row[a] += 1 col[b] += 1 bombs.add((a,b)) r,c = max(row),max(col) rcnt,ccnt = 0,0 for v in row: if v==r: rcnt += 1 for v in col: if v==c: ccnt += 1 doubled = 0 for i,j in bombs: if row[i]==r and col[j]==c: doubled += 1 if doubled==rcnt*ccnt: print((r+c-1)) else: print((r+c))
p02580
H, W, m = list(map(int, input().split())) H_bomb = [0]*H W_bomb = [0]*W S = set() for _ in range(m): h, w = list(map(int, input().split())) h, w = h-1, w-1 S.add(tuple([h, w])) H_bomb[h] += 1 W_bomb[w] += 1 H_max = max(H_bomb) W_max = max(W_bomb) H_memo = [] W_memo = [] for i in range(H): if H_bomb[i] == H_max: H_memo.append(i) for j in range(W): if W_bomb[j] == W_max: W_memo.append(j) ans = H_max + W_max daburi = 1 for i in H_memo: for j in W_memo: if tuple([i, j]) not in S: daburi = 0 print((ans - daburi))
import sys H, W, m = list(map(int, input().split())) H_bomb = [0]*H W_bomb = [0]*W S = set() for _ in range(m): h, w = list(map(int, sys.stdin.readline().split())) h, w = h-1, w-1 S.add(tuple([h, w])) H_bomb[h] += 1 W_bomb[w] += 1 H_max = max(H_bomb) W_max = max(W_bomb) H_memo = [] W_memo = [] for i in range(H): if H_bomb[i] == H_max: H_memo.append(i) for j in range(W): if W_bomb[j] == W_max: W_memo.append(j) ans = H_max + W_max for i in H_memo: for j in W_memo: if tuple([i, j]) not in S: print(ans) exit() print((ans-1))
p02580
H, W, M = list(map(int, input().split())) cnth = [[0, i] for i in range(H)] cntw = [[0, i] for i in range(W)] L = [[False for _ in range(W)] for _ in range(H)] for _ in range(M): h, w = [int(x) - 1 for x in input().split()] cnth[h][0] += 1 cntw[w][0] += 1 L[h][w] = True cnth.sort(reverse=True) cntw.sort(reverse=True) mh = set() ph = cnth[0] for h in cnth: if ph[0] == h[0]: mh.add(h[1]) else: break ph = h mw = set() pw = cntw[0] for w in cntw: if pw[0] == w[0]: mw.add(w[1]) else: break pw = w max = cnth[0][0] + cntw[0][0] for h in mh: for w in mw: if not (L[h][w]): print(max) break else: continue break else: print((max - 1))
def main(): H, W, M = list(map(int, input().split())) cnth = [[0, i] for i in range(H)] cntw = [[0, i] for i in range(W)] L = set() for _ in range(M): h, w = [int(x) - 1 for x in input().split()] cnth[h][0] += 1 cntw[w][0] += 1 L.add((h, w)) cnth.sort(reverse=True) cntw.sort(reverse=True) mh = set() ph = cnth[0] for h in cnth: if ph[0] == h[0]: mh.add(h[1]) else: break ph = h mw = set() pw = cntw[0] for w in cntw: if pw[0] == w[0]: mw.add(w[1]) else: break pw = w maxans = cnth[0][0] + cntw[0][0] for h in mh: for w in mw: if not ((h, w) in L): print(maxans) break else: continue break else: print((maxans - 1)) if __name__ == "__main__": main()
p02580
h, w, m = list(map(int, input().split())) h_cnt = [0 for _ in range(h)] w_cnt = [0 for _ in range(w)] mat = [[0 for _ in range(w)] for _ in range(h)] for _ in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 h_cnt[y] += 1 w_cnt[x] += 1 mat[y][x] += 1 h_dict = {i:v for i, v in enumerate(h_cnt)} w_dict = {i:v for i, v in enumerate(w_cnt)} h_max = max(h_dict.values()) w_max = max(w_dict.values()) h_max_induce = [i for i in list(h_dict.keys()) if h_dict[i] == h_max] w_max_induce = [i for i in list(w_dict.keys()) if w_dict[i] == w_max] for h_idx in h_max_induce: for w_idx in w_max_induce: if mat[h_idx][w_idx] == 0: print((h_max+w_max)) exit() print((h_max+w_max-1))
h, w, m = list(map(int, input().split())) h_cnt = [0 for _ in range(h)] w_cnt = [0 for _ in range(w)] xs = [] ys = [] for _ in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 h_cnt[y] += 1 w_cnt[x] += 1 xs.append(x) ys.append(y) h_max = max(h_cnt) w_max = max(w_cnt) h_max_induce = {i: v for i, v in enumerate(h_cnt) if v == h_max} w_max_induce = {i: v for i, v in enumerate(w_cnt) if v == w_max} cnt = 0 for i in range(m): x = xs[i] y = ys[i] if x in w_max_induce and y in h_max_induce: cnt += 1 if cnt == len(list(h_max_induce.keys()))*len(list(w_max_induce.keys())): print((h_max+w_max-1)) else: print((h_max+w_max))
p02580
h,w,m=list(map(int,input().split())) g=[0]*h l=[0]*w b=[] for i in range(m): x,y=list(map(int,input().split())) g[x-1]+=1 l[y-1]+=1 b.append((x-1,y-1)) mxg=max(g);mxl=max(l) mg=[i for i,x in enumerate(g) if x==mxg] ml=[i for i,x in enumerate(l) if x==mxl] c=0 for x,y in b: if x in mg and y in ml: c+=1 print((mxg+mxl-(c==(len(mg)*len(ml)))))
h,w,m=list(map(int,input().split())) g=[0]*h l=[0]*w b=[] for i in range(m): x,y=list(map(int,input().split())) g[x-1]+=1 l[y-1]+=1 b.append((x-1,y-1)) mxg=max(g);mxl=max(l) mg=set([i for i,x in enumerate(g) if x==mxg]) ml=set([i for i,x in enumerate(l) if x==mxl]) c=0 for x,y in b: if x in mg and y in ml: c+=1 print((mxg+mxl-(c==(len(mg)*len(ml)))))
p02580
h,w,m = list(map(int,input().split())) hw = [list(map(int,input().split())) for _ in range(m)] hlist = [0]*(h+1) wlist = [0]*(w+1) for x,y in hw: hlist[x]+=1 wlist[y]+=1 hmax=max(hlist) h_index = [n for n, v in enumerate(hlist) if v == hmax] wmax=max(wlist) w_index = [n for n, v in enumerate(wlist) if v == wmax] count = sum(x in h_index and y in w_index for x,y in hw) print((hmax+wmax-(len(h_index)*len(w_index)==count)))
#実験 貼り付けコード h,w,m = list(map(int,input().split())) s = [list(map(int,input().split())) for _ in range(m)] r = [0] * (h + 1) c = [0] * (w + 1) for x, y in s: r[x] += 1 c[y] += 1 R = max(r) nr = {i for i, x in enumerate(r) if x == R} C = max(c) nc = {i for i, x in enumerate(c) if x == C} count = sum(x in nr and y in nc for x, y in s) print((R + C - (len(nr) * len(nc) == count)))
p02580
from collections import Counter h, w, m = list(map(int, input().split())) blist = [list(map(int, input().split())) for _ in range(m)] rowdict = Counter([blist[i][0] for i in range(m)]) coldict = Counter([blist[i][1] for i in range(m)]) maxr = rowdict.most_common()[0][1] maxr_keys = [] for i in rowdict.most_common(): if i[1] == maxr: maxr_keys.append(i[0]) else: break maxc = coldict.most_common()[0][1] maxc_keys = [] for i in coldict.most_common(): if i[1] == maxc: maxc_keys.append(i[0]) else: break for i in maxr_keys: for j in maxc_keys: if [i, j] not in blist: print((maxr + maxc)) break else: continue break else: print((maxr + maxc - 1))
from collections import Counter h, w, m = list(map(int, input().split())) blist = [list(map(int, input().split())) for _ in range(m)] blist_set = set(map(tuple, blist)) rowdict = Counter([blist[i][0] for i in range(m)]) coldict = Counter([blist[i][1] for i in range(m)]) maxr = rowdict.most_common()[0][1] maxr_keys = [] for i in rowdict.most_common(): if i[1] == maxr: maxr_keys.append(i[0]) else: break maxc = coldict.most_common()[0][1] maxc_keys = [] for i in coldict.most_common(): if i[1] == maxc: maxc_keys.append(i[0]) else: break for i in maxr_keys: for j in maxc_keys: if (i, j) not in blist_set: print((maxr + maxc)) break else: continue break else: print((maxr + maxc - 1))
p02580
from collections import defaultdict row=defaultdict(int) col=defaultdict(int) H,W,M=list(map(int,input().split())) matrix=[[1 for i in range(W)] for j in range(H)] for i in range(M): h,w=list(map(int,input().split())) row[h]+=1 col[w]+=1 matrix[h-1][w-1]=0 #print(row) #print(col) #for i in matrix: # print(*i) temp=list(row.items()) temp.sort(key=lambda x:x[1]) a,b=temp[-1][0],temp[-1][1] cnt=0 for i in range(W): temp=0 if matrix[a-1][i]==0: temp=(b+col[i+1]-1) else: temp=(b+col[i+1]) cnt=max(cnt,temp) print(cnt)
from collections import defaultdict row=defaultdict(int) col=defaultdict(int) H,W,M=list(map(int,input().split())) #matrix=[[1 for i in range(W)] for j in range(H)] matrix=defaultdict(bool) for i in range(M): h,w=list(map(int,input().split())) row[h-1]+=1 col[w-1]+=1 matrix[(h-1,w-1)]=True #print(row) #print(col) #for i in matrix: # print(*i) temp=list(row.items()) temp.sort(key=lambda x:x[1]) a,b=temp[-1][0],temp[-1][1] cnt=0 for i in range(W): temp=0 if matrix[(a,i)]: temp=(b+col[i]-1) else: temp=(b+col[i]) cnt=max(cnt,temp) #print(cnt) temp=list(col.items()) temp.sort(key=lambda x:x[1]) a,b=temp[-1][0],temp[-1][1] cnt2=0 for i in range(H): temp=0 if matrix[(i,a)]: temp=(b+row[i]-1) else: temp=(b+row[i]) cnt2=max(cnt2,temp) print((max(cnt,cnt2)))
p02580
h,w,m=[int(i) for i in input().split()] r=[0 for i in range(h)] c=[0 for i in range(w)] d={} for i in range(m): h1,w1=[int(i)-1 for i in input().split()] r[h1]+=1 c[w1]+=1 x=str(h1)+"#"+str(w1) d[x]=d.get(x,0)+1 maxx=0 for i in range(h): for j in range(w): x=str(i)+"#"+str(j) maxx=max(maxx,r[i]+c[j]-d.get(x,0)) print(maxx)
h,w,m=[int(i) for i in input().split()] r=[0 for i in range(h)] c=[0 for i in range(w)] d={} for i in range(m): h1,w1=[int(j)-1 for j in input().split()] r[h1]+=1 c[w1]+=1 x=str(h1)+'#'+str(w1) d[x]=d.get(x,0)+1 maxx=max(r) r1=[] for i in range(len(r)): if maxx==r[i]: r1.append(i) maxx=max(c) c1=[] for i in range(len(c)): if maxx==c[i]: c1.append(i) maxx1=0;flag=0 for i in r1: for j in c1: x=str(i)+'#'+str(j) if(d.get(x,0)==0): maxx1=max(maxx1,r[i]+c[j]) flag=1 else: maxx1=max(maxx1,r[i]+c[j]-d[x]) if flag: break print(maxx1)
p02580
h, w, m = list(map(int, input().split())) a = [[0 for _ in range(w)] for _ in range(h)] for i in range(m): hi, wi = list(map(int, input().split())) a[hi-1][wi-1] = 1 mh = [sum(a[i][:]) for i in range(h)] mw = [sum([r[i] for r in a]) for i in range(w)] ans = max(mh) + max(mw) mh = [i for i, v in enumerate(mh) if v == max(mh)] mw = [i for i, v in enumerate(mw) if v == max(mw)] flag = 0 for i in mh: for j in mw: if a[i][j] == 0: print(ans) exit() print((ans - 1))
h, w, m = list(map(int, input().split())) a = [list([int(x) - 1 for x in input().split()]) for _ in range(m)] mh = [0 for i in range(h)] mw = [0 for j in range(w)] for i, j in a: mh[i] += 1 mw[j] += 1 hmax = max(mh) wmax = max(mw) ans = hmax + wmax flag = mh.count(hmax) * mw.count(wmax) for i,j in a: if mh[i] == hmax and mw[j] == wmax: flag -= 1 if flag == 0: print((ans - 1)) else: print(ans)
p02580
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): h, w, m = MI() targets = [[] for i in range(h)] tate = [[] for i in range(w)] tate_length = [0] * w original = [] lengths = [0] * h for i in range(m): target = LI() original.append(target) targets[target[0] - 1].append(target[1] - 1) tate[target[1] - 1].append(target[0] - 1) lengths[target[0] - 1] += 1 tate_length[target[1] - 1] += 1 max_length = max(lengths) max_h_indexes = [i for i, x in enumerate(lengths) if x == max_length] semi_max_h_indexes = [i for i, x in enumerate( lengths) if x == max_length - 1] for j in range(len(tate)): tate[j] = set(tate[j]) ans = 0 for index in max_h_indexes: for j in range(w): if index in tate[j]: ans = max(ans, tate_length[j] + lengths[index] - 1) else: ans = max(ans, tate_length[j] + lengths[index]) for index in semi_max_h_indexes: for j in range(w): if index in tate[j]: ans = max(ans, tate_length[j] + lengths[index] - 1) else: ans = max(ans, tate_length[j] + lengths[index]) print(ans) main()
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): h, w, m = MI() targets = [[] for i in range(h)] tate = [[] for i in range(w)] tate_length = [0] * w original = [] lengths = [0] * h for i in range(m): target = LI() original.append(target) targets[target[0] - 1].append(target[1] - 1) tate[target[1] - 1].append(target[0] - 1) lengths[target[0] - 1] += 1 tate_length[target[1] - 1] += 1 max_length = max(lengths) max_length_tate = max(tate_length) max_w_indexes = [i for i, x in enumerate( tate_length) if x == max_length_tate] max_h_indexes = [i for i, x in enumerate( lengths) if x == max_length] max_h_indexes = set(max_h_indexes) max_w_indexes = set(max_w_indexes) ttl = len(max_h_indexes) * len(max_w_indexes) for target in original: if target[0] - 1 in max_h_indexes and target[1] - 1 in max_w_indexes: ttl -= 1 if ttl > 0: print((max_length + max_length_tate)) else: print((max_length+max_length_tate - 1)) main()
p02580
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 19 + 7 EPS = 10 ** -10 class BIT: """ BIT汎用版 """ def __init__(self, n, func, init): # 0-indexed n += 1 nv = 1 while nv < n: nv *= 2 self.size = nv self.func = func self.init = init self.tree = [init] * nv def query(self, i): """ [0, i]の値を取得 """ s = self.init i += 1 while i > 0: s = self.func(s, self.tree[i-1]) i -= i & -i return s def update(self, i, x): """ 値の更新:添字i, 値x """ i += 1 while i <= self.size: self.tree[i-1] = self.func(self.tree[i-1], x) i += i & -i class SegTree: """ セグメント木 1.update: i番目の値をxに更新する 2.query: 区間[l, r)の値を得る """ def __init__(self, n, func, intv, A=[]): """ :param n: 要素数(0-indexed) :param func: 値の操作に使う関数(min, max, add, gcdなど) :param intv: 要素の初期値(単位元) :param A: 初期化に使うリスト(オプション) """ self.n = n self.func = func self.intv = intv n2 = 1 while n2 < n: n2 <<= 1 self.n2 = n2 self.tree = [self.intv] * (n2 << 1) if A: for i in range(n): self.tree[n2+i] = A[i] for i in range(n2-1, -1, -1): self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1]) def update(self, i, x): """ i番目の値をxに更新 :param i: index(0-indexed) :param x: update value """ i += self.n2 self.tree[i] = x while i > 0: i >>= 1 self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1]) def add(self, i, x): self.update(i, self.get(i) + x) def query(self, a, b): """ [a, b)の値を得る :param a: index(0-indexed) :param b: index(0-indexed) """ l = a + self.n2 r = b + self.n2 s = self.intv while l < r: if r & 1: r -= 1 s = self.func(s, self.tree[r]) if l & 1: s = self.func(s, self.tree[l]) l += 1 l >>= 1 r >>= 1 return s def get(self, i): """ 一点取得 """ return self.tree[i+self.n2] def all(self): """ 全区間[0, n)の取得 """ return self.tree[1] def print(self): for i in range(self.n): print(self.get(i), end=' ') print() H, W, M = MAP() seg = SegTree(W+1, max, -INF, [0]*(W+1)) adjli = [[] for i in range(H+1)] C = [0] * (W+1) for i in range(M): h, w = MAP() seg.add(w, 1) adjli[h].append(w) ans = 0 for h in range(1, H+1): rowcnt = len(adjli[h]) for w in adjli[h]: seg.add(w, -1) ans = max(ans, rowcnt+seg.all()) for w in adjli[h]: seg.add(w, 1) print(ans)
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 19 + 7 EPS = 10 ** -10 H, W, M = MAP() row = [0] * (H+1) col = [0] * (W+1) se = set() for i in range(M): h, w = MAP() row[h] += 1 col[w] += 1 se.add((h, w)) mxh = max(row) hli = [] for h, cnt in enumerate(row): if cnt == mxh: hli.append(h) mxw = max(col) wli = [] for w, cnt in enumerate(col): if cnt == mxw: wli.append(w) ok = 0 for h in hli: for w in wli: if (h, w) not in se: ok = 1 break if ok: break ans = mxh + mxw - 1 + ok print(ans)
p02580
def resolve(): ''' code here ''' H, W, M = [int(item) for item in input().split()] targets = [[int(item) -1 for item in input().split()] for _ in range(M)] col = [0 for _ in range(H)] row = [0 for _ in range(W)] bomb_set = set() # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく for i,j in targets: col[i] += 1 row[j] += 1 bomb_set.add((i,j)) max_col = max(col) max_row = max(row) max_col_index = [] max_row_index = [] for i in range(H): if col[i] == max_col: max_col_index.append(i) for i in range(W): if row[i] == max_row: max_row_index.append(i) res = 0 for item in max_col_index: for jtem in max_row_index: if (item,jtem) in bomb_set: res = max(res, max_col + max_row -1) else: res = max(res, max_col + max_row) print(res) if __name__ == "__main__": resolve()
def resolve(): ''' code here ''' H, W, M = [int(item) for item in input().split()] targets = [[int(item) -1 for item in input().split()] for _ in range(M)] col = [0 for _ in range(H)] row = [0 for _ in range(W)] bomb_set = set() # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく for i,j in targets: col[i] += 1 row[j] += 1 bomb_set.add((i,j)) max_col = max(col) max_row = max(row) max_col_index = [] max_row_index = [] for i in range(H): if col[i] == max_col: max_col_index.append(i) for i in range(W): if row[i] == max_row: max_row_index.append(i) res = 0 for item in max_col_index: for jtem in max_row_index: if (item,jtem) not in bomb_set: res =max_col + max_row break else: res = max(res, max_col + max_row -1 ) print(res) if __name__ == "__main__": resolve()
p02580
h, w, m = list(map(int, input().split())) count_h = [0 for i in range(h)] count_w = [0 for i in range(w)] points = set() for i in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 points.add((y, x)) count_h[y] += 1 count_w[x] += 1 ch_max, cw_max = max(count_h), max(count_w) ys = [y for y in range(len(count_h)) if count_h[y] == ch_max] xs = [x for x in range(len(count_w)) if count_w[x] == cw_max] ans = 0 for x in xs: for y in ys: if (y, x) in points: ans = max(ans, count_h[y] + count_w[x] - 1) else: ans = max(ans, count_h[y] + count_w[x]) print(ans)
h, w, m = list(map(int, input().split())) count_h = [0 for i in range(h)] count_w = [0 for i in range(w)] points = set() for i in range(m): y, x = list(map(int, input().split())) y -= 1 x -= 1 points.add((y, x)) count_h[y] += 1 count_w[x] += 1 ch_max, cw_max = max(count_h), max(count_w) ys = [y for y in range(len(count_h)) if count_h[y] == ch_max] xs = [x for x in range(len(count_w)) if count_w[x] == cw_max] ans = ch_max + cw_max if len(ys) * len(xs) <= m: def _find(): for x in xs: for y in ys: if (y, x) not in points: return True return False if not _find(): ans -= 1 print(ans)
p02580
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline input = readline mod = 10 ** 9 + 7 H, W, M = list(map(int, input().split())) Hlist = [0] * H Wlist = [0] * W hwmatrix = [[0 for _ in range(W)] for _ in range(H)] for _ in range(M): h, w = list(map(int, input().split())) Hlist[h-1] += 1 Wlist[w-1] += 1 hwmatrix[h-1][w-1] = 1 hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)] wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)] flag = False for h in hmax: for w in wmax: if hwmatrix[h][w] == 0: flag = True break if flag: print((Hlist[h] + Wlist[w])) else: print((Hlist[h] + Wlist[w] - 1)) if __name__ == '__main__': solve()
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline input = readline mod = 10 ** 9 + 7 H, W, M = list(map(int, input().split())) Hlist = [0] * H Wlist = [0] * W hwset = [set() for _ in range(H)] for _ in range(M): h, w = list(map(int, input().split())) Hlist[h-1] += 1 Wlist[w-1] += 1 hwset[h-1].add(w) hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)] wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)] flag = False for h in hmax: for w in wmax: if w+1 not in hwset[h]: flag = True break if flag: print((Hlist[h] + Wlist[w])) else: print((Hlist[h] + Wlist[w] - 1)) if __name__ == '__main__': solve()
p02580
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline input = readline mod = 10 ** 9 + 7 H, W, M = list(map(int, input().split())) Hlist = [0] * H Wlist = [0] * W hw = [] for _ in range(M): h, w = list(map(int, input().split())) Hlist[h-1] += 1 Wlist[w-1] += 1 hw.append([h, w]) hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)] wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)] hmaxset = set(hmax) wmaxset = set(wmax) flag = False count = 0 for hh in hw: h = hh[0] - 1 w = hh[1] - 1 if h in hmaxset and w in wmaxset: count += 1 if count != len(hmax) * len(wmax): flag = True if flag: print((Hlist[hmax[0]] + Wlist[wmax[0]])) else: print((Hlist[hmax[0]] + Wlist[wmax[0]] - 1)) if __name__ == '__main__': solve()
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline input = readline mod = 10 ** 9 + 7 H, W, M = list(map(int, input().split())) Hlist = collections.defaultdict(int) Wlist = collections.defaultdict(int) hw = [] for _ in range(M): h, w = list(map(int, input().split())) Hlist[h-1] += 1 Wlist[w-1] += 1 hw.append([h, w]) #hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)] #wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)] Hlist = sorted(list(Hlist.items()), key=lambda x: x[1], reverse=True) Wlist = sorted(list(Wlist.items()), key=lambda x: x[1], reverse=True) hmaxset = set() wmaxset = set() maxH = Hlist[0][1] for k, v in Hlist: if v != maxH: break else: hmaxset.add(k) maxW = Wlist[0][1] for k, v in Wlist: if v != maxW: break else: wmaxset.add(k) flag = False count = 0 for hh in hw: h = hh[0] - 1 w = hh[1] - 1 if h in hmaxset and w in wmaxset: count += 1 lenhmax = len(hmaxset) lenwmax = len(wmaxset) if count != lenhmax * lenwmax: flag = True if flag: print((maxH + maxW)) else: print((maxH + maxW - 1)) if __name__ == '__main__': solve()
p02580
import sys h, w, m = list(map(int, input().split())) row = [0]*h col = [0]*w bomb = [] for x in sys.stdin.readlines(): H, W = list(map(int, x.split())) bomb.append([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 h, w, m = list(map(int, input().split())) row = [0]*h col = [0]*w bomb = set() for x in range(m): H, W = list(map(int, input().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)
p02580
import sys h, w, m = list(map(int, input().split())) row = [0]*h col = [0]*w bomb = [] for x in range(m): H, W = list(map(int, input().split())) bomb.append((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 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)
p02580