input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
#134 Dodecagon print((3*(int(eval(input()))**2)))
#134 Dodecagon print((3*int(eval(input()))**2))
p02969
import itertools import fractions def main(): r = int(eval(input())) print((3 * (r**2))) if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from fractions import gcd #from itertools import combinations # (string,3) 3回 #from collections import deque from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) r = I() print((3*r**2))
p02969
i = int(eval(input())) print((3*i**2))
print((3*int(eval(input()))**2))
p02969
print((3 * int(eval(input()))**2))
r=int(eval(input())) print((3*r*r))
p02969
n = int(eval(input())) print((3*n*n))
r = int(eval(input())) print((3*r*r))
p02969
r = int(eval(input())) print((3*r**2))
N=int(eval(input())) print((3*N**2))
p02969
print((3*int(eval(input()))**2))
a = int(eval(input())) print((3*a**2))
p02969
r = int(eval(input())) print((3*r*r))
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): r = int(eval(input())) res = 3 * pow(r, 2) print(res) if __name__ == '__main__': resolve()
p02969
a = int(eval(input())) print((3 * a**2))
print((int(eval(input())) ** 2 * 3))
p02969
print((3 * int(eval(input())) ** 2))
R = int(eval(input())) print((3 * R ** 2))
p02969
import sys # input = sys.stdin.readline inf = 10 ** 18 P = 10 ** 9 + 7 print(( 3 * (int(eval(input())) ** 2) ))
r = int(eval(input())) print((3 * r * r))
p02969
a = int(eval(input())) print((3 * (a ** 2)))
r = int(eval(input())) print((3*r*r))
p02969
r = int(eval(input())) print((3 * r ** 2))
r = int(eval(input())) ans = 3 * r ** 2 print(ans)
p02969
r=int(eval(input())) print((3*r*r))
a=int(eval(input())) print((3*a*a))
p02969
r = int(eval(input())) print((3 * r ** 2))
r = int(eval(input())) print((3 * (r ** 2)))
p02969
n=int(eval(input())) print((3*n**2))
print((3*int(eval(input()))**2))
p02969
import sys def input(): return sys.stdin.readline().strip() def resolve(): x,y=list(map(int, input().split())) cnt=0 while x<=y: x=x*2 cnt+=1 print(cnt) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): x,y=list(map(int, input().split())) cnt=1 while x<=y: x*=2 cnt+=1 print((cnt-1)) resolve()
p03481
x, y = list(map(int, input().split())) ans = 1 while x*2 <= y: ans += 1 x *= 2 print(ans)
x, y = list(map(int, input().split())) if y < 2*x: print((1)) exit() ans = 1 while x*2 <= y: ans += 1 x = 2*x print(ans)
p03481
X, Y = list(map(int, input().split())) x = X ans = 0 while x < Y: x *= 2 ans += 1 print((ans if x > Y else ans + 1))
x,y = list(map(int, input().split())) n = [x] while n[-1] < y: n.append(n[-1]*2) if n[-1] > y: n.pop(-1) print((len(n)))
p03481
from collections import defaultdict def readInt(): return int(eval(input())) def readInts(): return list(map(int, input().split())) def readChar(): return eval(input()) def readChars(): return input().split() from math import log2 x,y = readInts() ans = 0 i = 1 while 1: if x*2**(i-1)<=y: ans+=1 i+=1 else: print(ans) break
from collections import defaultdict def readInt(): return int(eval(input())) def readInts(): return list(map(int, input().split())) def readChar(): return eval(input()) def readChars(): return input().split() from math import log2 x,y = readInts() kouho = int(log2(y)-log2(x)+1)-1 ans = kouho-1 for i in range(kouho,kouho+3): if x*2**(i-1)<=y: ans+=1 else: print(ans) break
p03481
import sys input = sys.stdin.readline x, y = [int(x) for x in input().split()] ans = 0 while x <= y: x *= 2 ans += 1 print(ans)
import sys input = lambda: sys.stdin.readline().rstrip() x, y = list(map(int, input().split())) cnt = 1 while True: if x*2 <= y: cnt += 1 x *= 2 else: break print(cnt)
p03481
def slove(): import sys input = sys.stdin.readline n, m = list(map(int, input().rstrip('\n').split())) cnt = 1 t = n while True: t *= 2 if t <= m: cnt += 1 else: print(cnt) exit() if __name__ == '__main__': slove()
def slove(): import sys input = sys.stdin.readline x, y = list(map(int, input().rstrip('\n').split())) t = x cnt = 1 while True: t *= 2 if t <= y: cnt += 1 else: print(cnt) exit() if __name__ == '__main__': slove()
p03481
x, y = list(map(int, input().split())) ans = 0 while x <= y: x *= 2 ans += 1 print(ans)
x, y = list(map(int, input().split())) ans = 0 while x <= y: ans += 1 x *= 2 print(ans)
p03481
X, Y = list(map(int, input().split())) A = X ans = 1 while 2*A <= Y: A *= 2 ans += 1 print(ans)
X, Y = list(map(int, input().split())) # A[i+1] = 2 * A[i] と構成すればよさげ # このとき A[0] = X とすれば A[n] = X * pow(2, n-1) for i in range(100): X *= 2 if X > Y: print((i+1)) exit()
p03481
x, y = list(map(int, input().split())) ans = 1 while True: x *= 2 if x > y: break ans += 1 print(ans)
x, y = list(map(int, input().split())) cnt = 0 tmp = x while tmp <= y: tmp *= 2 cnt += 1 print(cnt)
p03481
h,w,m = list(map(int,input().split())) bombDict = dict() bombDictH = dict() bombDictW = dict() for i in range(h+1): bombDict[i] = set() bombDictH[i] = 0 for i in range(w+1): bombDictW[i] = 0 for i in range(m): bombH,bombW = list(map(int,input().split())) bombDictH[bombH] += 1 bombDictW[bombW] += 1 bombDict[bombH].add(bombW) maxH = max(bombDictH,key = bombDictH.get) maxW = max(bombDictW,key = bombDictW.get) maxHV = max(bombDictH.values()) maxWV = max(bombDictW.values()) hList = list(bombDictH.values()) wList = list(bombDictW.values()) maxHList = [] maxWList = [] if hList.count(maxHV) > 1: for i in range(h+1): if hList[i] == maxHV: maxHList.append(i) else: maxHList.append(maxH) if wList.count(maxWV) > 1: for i in range(w+1): if wList[i] == maxWV: maxWList.append(i) else: maxWList.append(maxW) ans = 0 for i in maxHList: for j in maxWList: if j in bombDict[i]: ans = max(ans,bombDictH[i] + bombDictW[j] - 1) else: ans = max(ans,bombDictH[i] + bombDictW[j]) print(ans)
h,w,m = list(map(int,input().split())) bombDict = dict() bombDictH = dict() bombDictW = dict() for i in range(h+1): bombDict[i] = set() bombDictH[i] = 0 for i in range(w+1): bombDictW[i] = 0 for i in range(m): bombH,bombW = list(map(int,input().split())) bombDictH[bombH] += 1 bombDictW[bombW] += 1 bombDict[bombH].add(bombW) maxH = max(bombDictH,key = bombDictH.get) maxW = max(bombDictW,key = bombDictW.get) maxHV = max(bombDictH.values()) maxWV = max(bombDictW.values()) hList = list(bombDictH.values()) wList = list(bombDictW.values()) maxHList = [] maxWList = [] if hList.count(maxHV) > 1: for i in range(h+1): if hList[i] == maxHV: maxHList.append(i) else: maxHList.append(maxH) if wList.count(maxWV) > 1: for i in range(w+1): if wList[i] == maxWV: maxWList.append(i) else: maxWList.append(maxW) ans = 0 for i in maxHList: for j in maxWList: if j in bombDict[i]: ans = max(ans,bombDictH[i] + bombDictW[j] - 1) else: ans = max(ans,bombDictH[i] + bombDictW[j]) break print(ans)
p02580
h,w,m = list(map(int,input().split())) b = [] x = [0 for _ in range(w)] y = [0 for _ in range(h)] for i in range(m): bh,bw = list(map(int,input().split())) bh -= 1 bw -= 1 b.append((bh,bw)) x[bw] += 1 y[bh] += 1 #print(b,x,y) mxx = max(x) mxy = max(y) xb = [] for i in range(w): xb.append((x[i],i)) xb.sort(reverse = True) yb = [] for i in range(h): yb.append((y[i],i)) yb.sort(reverse = True) #print(xb,yb) for xbi,i in xb: if xbi < mxx: break for ybi,j in yb: if ybi < mxy: continue else: if (j,i) not in b: print((xbi+ybi)) exit() print((mxx+mxy-1))
h,w,m = list(map(int,input().split())) b = [] x = [0 for _ in range(w)] y = [0 for _ in range(h)] for i in range(m): bh,bw = list(map(int,input().split())) bh -= 1 bw -= 1 b.append((bh,bw)) x[bw] += 1 y[bh] += 1 #print(b,x,y) mxx = max(x) mxy = max(y) cmxb = 0 for by,bx in b: if y[by]+x[bx] == mxx+mxy: cmxb += 1 cmxx = 0 for xi in x: if xi == mxx: cmxx += 1 cmxy = 0 for yi in y: if yi == mxy: cmxy += 1 #print(cmxb,cmxx,cmxy) if cmxb == cmxx*cmxy: print((mxx+mxy-1)) else: print((mxx+mxy))
p02580
h,w,m=list(map(int,input().split())) d_h=[0]*(h+1) d_w=[0]*(w+1) d=set() for i in range(m): nh,nw=list(map(int,input().split())) d_h[nh]+=1 d_w[nw]+=1 d.add((nh,nw)) ans=0 hantei=0 for i in range(1,h+1): hantei=0 for j in range(1,w+1): if (i,j) in d: hantei=(d_h[i]+d_w[j]-1) else: hantei=(d_h[i]+d_w[j]) if ans < hantei: ans=hantei print(ans)
h,w,m=list(map(int,input().split())) d_h=[0]*(h+1) d_w=[0]*(w+1) d=[] for i in range(m): nh,nw=list(map(int,input().split())) d_h[nh]+=1 d_w[nw]+=1 d.append([nh,nw]) #print(d_h) #print(d_w) hantei=0 ans1=max(d_h) memoh=set() for i in range(1,h+1): hantei=d_h[i] if ans1==hantei: memoh.add(i) hantei=0 ans2=max(d_w) memow=set() for j in range(1,w+1): hantei=d_w[j] if ans2 == hantei: memow.add(j) ans = ans2+ans1-1 #print(memoh,memow) count = len(memoh)*len(memow) for hw in d: if hw[0] in memoh and hw[1] in memow: count-=1 if count>0: 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 hmax=max(H) wmax=max(W) cthmax=0 ctwmax=0 for i in range(h): if H[i]==hmax: cthmax+=1 for i in range(w): if W[i]==wmax: ctwmax+=1 ct=0 for i in range(m): if H[l[i][0]-1]==max(H) and W[l[i][1]-1]==max(W): ct+=1 if cthmax*ctwmax>ct: print((hmax+wmax)) else: print((hmax+wmax-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 hmax=max(H) wmax=max(W) cthmax=0 ctwmax=0 for i in range(h): if H[i]==hmax: cthmax+=1 for i in range(w): if W[i]==wmax: ctwmax+=1 ct=0 for i in range(m): if H[l[i][0]-1]==hmax and W[l[i][1]-1]==wmax: ct+=1 if cthmax*ctwmax>ct: print((hmax+wmax)) else: print((hmax+wmax-1))
p02580
import sys from copy import deepcopy as copy input = sys.stdin.readline def main(): h, w, m = list(map(int, input().split())) bomb_h = [0]*h bomb_w = [0]*w bomb_w_place = [set() for _ in range(w)] for i in range(m): x, y = list(map(int, input().split())) bomb_h[x-1] += 1 bomb_w[y-1] += 1 bomb_w_place[y-1].add(x-1) bomb_h2 = [0]*h for i in range(h): bomb_h2[i] = [bomb_h[i], i] bomb_h2.sort(reverse=True) ans = 0 for i in range(w): index = 0 key = bomb_w[i] k1, k2 = True, True ma = -1 while index < len(bomb_h2): key2 = bomb_h2[index] if key2[1] in bomb_w_place[i]: if ma == -1: ma = key2[0]-1 index += 1 continue elif ma == key2[0]-1: index += 1 continue else: break else: ma = max(ma, key2[0]) break index += 1 ans = max(ans, key+ma) print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): h, w, m = list(map(int, input().split())) bomb = [tuple(map(int, input().split())) for _ in range(m)] bom_h = [0]*h bom_w = [0]*w for i in range(m): x, y = bomb[i] bom_h[x-1] += 1 bom_w[y-1] += 1 max_h = max(bom_h) max_w = max(bom_w) ans = bom_h.count(max_h)*bom_w.count(max_w) for i in range(m): x, y = bomb[i] if bom_h[x-1] == max_h and bom_w[y-1] == max_w: ans -= 1 print((max_h+max_w+bool(ans)-1)) if __name__ == "__main__": main()
p02580
h,w,m=list(map(int,input().split())) A=[0]*h ; B=[0]*w ;G=[] for i in range(m): x,y=list(map(int,input().split())) A[x-1]+=1 ; B[y-1]+=1 G.append([x-1,y-1]) q=max(A) ; e=max(B) Q=[i for i in range(h) if A[i]==q] W=[j for j in range(w) if B[j]==e];#print(A,B,Q,W) grid={} for i in Q: for j in W: grid[ (i,j) ]=0 for i in range(m): x,y=G[i] if A[x]==q and B[y]==e: grid[(x,y)]=1 #print(grid) if 0 in list(grid.values()): print((q+e)) else: print((q+e-1))
h,w,m=list(map(int,input().split())) A=[0]*h ; B=[0]*w ;G=[] for i in range(m): x,y=list(map(int,input().split())) A[x-1]+=1 ; B[y-1]+=1 G.append([x-1,y-1]) q=max(A) ; e=max(B) Q=[i for i in range(h) if A[i]==q] W=[j for j in range(w) if B[j]==e];#print(A,B,Q,W) cnt=len(Q)*len(W) for i in range(m): x,y=G[i] if A[x]==q and B[y]==e: cnt-=1 #print(grid) if cnt==0: print((q+e-1)) else: print((q+e))
p02580
H, W, M = list(map(int, input().split())) X = [0] * W Y = [0] * H Map = [] for _ in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 Y[h] += 1 X[w] += 1 Map.append((h, w)) MX = max(X) MY = max(Y) ans = MX + MY Xans = [] Yans = [] for i, x in enumerate(X): if x == MX: Xans.append(i) for i, y in enumerate(Y): if y == MY: Yans.append(i) flag = False cnt = 0 for h, w in Map: if h in Yans and w in Xans: cnt += 1 if cnt == len(Xans) * len(Yans): ans -= 1 print(ans)
import sys input = sys.stdin.buffer.readline H, W, M = list(map(int, input().split())) X = [0] * W Y = [0] * H Map = [] for _ in range(M): h, w = list(map(int, input().split())) h -= 1 w -= 1 Y[h] += 1 X[w] += 1 Map.append((h, w)) MX = max(X) MY = max(Y) ans = MX + MY Xans = set() Yans = set() for i, x in enumerate(X): if x == MX: Xans.add(i) for i, y in enumerate(Y): if y == MY: Yans.add(i) cnt = 0 for h, w in Map: if h in Yans and w in Xans: cnt += 1 if cnt == len(Xans) * len(Yans): ans -= 1 print(ans)
p02580
from collections import Counter H, W, M = list(map(int, input().split())) counterH = [0] * H counterW = [0] * W setHW = set({}) for _ in range(M): hi, wi = [int(x) - 1 for x in input().split()] setHW.add((hi, wi)) counterH[hi] += 1 counterW[wi] += 1 set_max_h, set_max_w = set(), set() max_h, max_w = -1, -1 for h in range(H): if counterH[h] > max_h: max_h = counterH[h] set_max_h = set({h}) elif counterH[h] == max_h: set_max_h.add(h) for w in range(W): if counterW[w] > max_w: max_w = counterW[w] set_max_w = set({w}) elif counterW[w] == max_w: set_max_w.add(w) def count(h, w): bomb = 0 if (h, w) not in setHW else -1 bomb += counterH[h] bomb += counterW[w] return bomb m = -1 for h in set_max_h: for w in range(W): m = max(m, count(h, w)) for w in set_max_w: for h in range(H): m = max(m, count(h, w)) print(m)
H, W, M = list(map(int,input().split())) Bomb = [] for _ in range(M): hi, wi = [int(x) - 1 for x in input().split()] Bomb.append((hi, wi)) counterH = [0] * H counterW = [0] * W for (hi, wi) in Bomb: counterH[hi] += 1 counterW[wi] += 1 # 最大のところを選ぶ max_h = max(counterH) max_w = max(counterW) count = 0 for (hi, wi) in Bomb: if counterH[hi] == max_h and counterW[wi] == max_w: count += 1 # 共通部分を確認 (-1) ans = max_h + max_w if count == counterH.count(max_h) * counterW.count(max_w): ans -= 1 print(ans)
p02580
H,W,M = list(map(int, input().split())) mx=[0] * W my=[0] * H bs =[[] for i in range(H)] mxx = 0 myy = 0 for i in range(M): y,x = list(map(int, input().split())) mx[x-1] += 1 my[y-1] += 1 mxx = max(mx[x-1], mxx) myy = max(my[y-1], myy) bs[y-1].append(x-1) vx = [] vy = [] for i,x in enumerate(mx): if x == mxx: vx.append(i) for i,y in enumerate(my): if y == myy: vy.append(i) a = 1 for i in vx: for j in vy: if i not in bs[j]: a = 0 break else: continue break ans = mxx + myy - a print(ans)
H,W,M = list(map(int, input().split())) mx=[0] * W my=[0] * H bs ={} mxx = 0 myy = 0 for i in range(M): y,x = list(map(int, input().split())) mx[x-1] += 1 my[y-1] += 1 mxx = max(mx[x-1], mxx) myy = max(my[y-1], myy) if y-1 in bs: bs[y-1].add(x-1) else: bs[y-1] = set([x-1]) vx = [] vy = [] for i,x in enumerate(mx): if x == mxx: vx.append(i) for i,y in enumerate(my): if y == myy: vy.append(i) a = 1 for i in vx: for j in vy: if i not in bs[j]: a = 0 break else: continue break ans = mxx + myy - a print(ans)
p02580
from collections import defaultdict h, w, m = list(map(int, input().split())) row_dict = defaultdict(int) col_dict = defaultdict(int) row_col_dict = defaultdict(list) for _ in range(m): row, col = list(map(int, input().split())) row_dict[row] += 1 col_dict[col] += 1 row_col_dict[row].append(col) max_row = max(row_dict.values()) max_col = max(col_dict.values()) max_rows = [k for k, v in list(row_dict.items()) if v == max_row] max_cols = [k for k, v in list(col_dict.items()) if v == max_col] ans = max_row + max_col - 1 flg = False if ans < m: for row in max_rows: for col in max_cols: if not col in row_col_dict[row]: ans += 1 flg = True break if flg: break print(ans)
from collections import defaultdict h, w, m = list(map(int, input().split())) row_dict = defaultdict(int) col_dict = defaultdict(int) row_col_dict = defaultdict(set) for _ in range(m): row, col = list(map(int, input().split())) row_dict[row] += 1 col_dict[col] += 1 row_col_dict[row].add(col) max_row = max(row_dict.values()) max_col = max(col_dict.values()) max_rows = [k for k, v in list(row_dict.items()) if v == max_row] max_cols = [k for k, v in list(col_dict.items()) if v == max_col] ans = max_row + max_col - 1 flg = False if ans < m: for row in max_rows: for col in max_cols: if not col in row_col_dict[row]: ans += 1 flg = True break if flg: break print(ans)
p02580
from collections import defaultdict h, w, m = list(map(int, input().split())) row_dict = defaultdict(int) col_dict = defaultdict(int) row_col_dict = defaultdict(set) for _ in range(m): row, col = list(map(int, input().split())) row_dict[row] += 1 col_dict[col] += 1 row_col_dict[row].add(col) max_row = max(row_dict.values()) max_col = max(col_dict.values()) max_rows = [k for k, v in list(row_dict.items()) if v == max_row] max_cols = [k for k, v in list(col_dict.items()) if v == max_col] ans = max_row + max_col - 1 flg = False if ans < m: for row in max_rows: for col in max_cols: if not col in row_col_dict[row]: ans += 1 flg = True break if flg: break print(ans)
from collections import defaultdict h, w, m = list(map(int, input().split())) row_dict = defaultdict(int) col_dict = defaultdict(int) row_col_dict = defaultdict(set) for _ in range(m): row, col = list(map(int, input().split())) row_dict[row] += 1 col_dict[col] += 1 row_col_dict[row].add(col) max_row = max(row_dict.values()) max_col = max(col_dict.values()) max_rows = {k for k, v in list(row_dict.items()) if v == max_row} max_cols = {k for k, v in list(col_dict.items()) if v == max_col} ans = max_row + max_col - 1 flg = False if ans < m: for row in max_rows: for col in max_cols: if not col in row_col_dict[row]: ans += 1 flg = True break if flg: break print(ans)
p02580
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter import heapq #from fractions import gcd #input=sys.stdin.readline import bisect h,w,m=list(map(int,input().split())) l={} u={} hw=[list(map(int,input().split())) for _ in range(m)] sl=set() for i in range(m): hr,wr=hw[i] if hr-1 in u: u[hr-1]+=1 else: u[hr-1]=1 if wr-1 in l: l[wr-1]+=1 else: l[wr-1]=1 sl.add((hr-1)*w+(wr-1)) resl=0 resu=0 cl=[] cu=[] for i in l: if resl<l[i]: resl=l[i] cl=[i] elif resl==l[i]: cl.append(i) for i in u: if resu<u[i]: resu=u[i] cu=[i] elif resu==u[i]: cu.append(i) ans=0 for i in cu: for j in cl: if (i*w+j) in sl: res=l[j]+u[i]-1 else: res=l[j]+u[i] ans=max(res,ans) print(ans)
#import sys #import numpy as np import math #from fractions import Fraction import itertools from collections import deque from collections import Counter import heapq #from fractions import gcd #input=sys.stdin.readline import bisect h,w,m=list(map(int,input().split())) l={} u={} hw=[list(map(int,input().split())) for _ in range(m)] s=set() for i in range(m): hr,wr=hw[i] if hr-1 in u: u[hr-1]+=1 else: u[hr-1]=1 if wr-1 in l: l[wr-1]+=1 else: l[wr-1]=1 s.add((hr-1)*w+wr-1) resl=0 resu=0 cl=[] cu=[] for i in l: if resl<l[i]: resl=l[i] cl=[i] elif resl==l[i]: cl.append(i) for i in u: if resu<u[i]: resu=u[i] cu=[i] elif resu==u[i]: cu.append(i) ans=0 if resu==m or resl==m : print(m) exit() if len(cu)*len(cl)>m: ans=resl+resu else: for i in cu: for j in cl: if i*w+j in s: res=resl+resu-1 else: res=resl+resu ans=max(res,ans) print(ans)
p02580
H,W,M=list(map(int,input().split())) height=[0]*H width=[0]*W #bomb=[0]*M bset=set() #for k in range(M): #bomb[k]=[0]*2 for j in range(M): h,w=list(map(int,input().split())) bset.add((h-1,w-1)) #bomb[j][0]=h-1 #bomb[j][1]=w-1 height[h-1]+=1 width[w-1]+=1 #print(bomb) #print(height) #print(width) hmax=max(height) wmax=max(width) flag=0 for i in range(H): if height[i]==hmax: for h in range(W): if width[h]==wmax: if (i,h) not in bset: flag=1 break if flag==1: print((hmax+wmax)) else: print((hmax+wmax-1))
H,W,M=list(map(int,input().split())) height=[0]*H width=[0]*W #bomb=[0]*M bset=set() #for k in range(M): #bomb[k]=[0]*2 for j in range(M): h,w=list(map(int,input().split())) bset.add((h-1,w-1)) #bomb[j][0]=h-1 #bomb[j][1]=w-1 height[h-1]+=1 width[w-1]+=1 #print(bomb) #print(height) #print(width) hmax=max(height) wmax=max(width) hindex=0 windex=0 for i in range(H): if height[i]==hmax: #print(i) hindex+=1 for h in range(W): if width[h]==wmax: #print(h) windex+=1 kouho=hindex*windex equalbomb=0 for p in bset: if height[p[0]]==hmax and width[p[1]]==wmax: #print(p) equalbomb+=1 if kouho==equalbomb: print((hmax+wmax-1)) else: print((hmax+wmax))
p02580
H, W, M = list(map(int, input().split())) targets = [] n_target_h = [0] * H n_target_w = [0] * W h_max = 0 w_max = 0 for i in range(M): h, w = list(map(int, input().split())) targets.append((h, w)) n_target_h[h - 1] += 1 n_target_w[w - 1] += 1 h_max = max(h_max, n_target_h[h - 1]) w_max = max(w_max, n_target_w[w - 1]) bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max] bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max] ans = h_max + w_max - 1 for h in bomb_h: for w in bomb_w: if not (h, w) in targets: ans = h_max + w_max break else: continue break print(ans)
H, W, M = list(map(int, input().split())) targets = [] n_target_h = [0] * H n_target_w = [0] * W for i in range(M): h, w = list(map(int, input().split())) targets.append((h, w)) n_target_h[h - 1] += 1 n_target_w[w - 1] += 1 h_max = max(n_target_h) w_max = max(n_target_w) bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max] bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max] count = len(bomb_h) * len(bomb_w) for target in targets: if (n_target_h[target[0] - 1] == h_max) and (n_target_w[target[1] - 1] == w_max): count -= 1 if count > 0: ans = h_max + w_max else: ans = h_max + w_max - 1 print(ans)
p02580
from bisect import bisect_left def main(): h, w, m = list(map(int, input().split())) bombs = set() cnt_row, cnt_col = [0]*(h+1), [0]*(w+1) for _ in range(m): y, x = list(map(int, input().split())) cnt_row[y] += 1 cnt_col[x] += 1 bombs.add((y, x)) ans = 0 for y, x in bombs: ans = max(ans, cnt_row[y]+cnt_col[x]-1) col_indexs = [i for i in range(w+1)] col_indexs.sort(key=lambda x: cnt_col[x]) cnt_col.sort() row_indexs = [i for i in range(h+1)] row_indexs.sort(key=lambda x: cnt_row[x]) cnt_row.sort() for i, row_val in zip(reversed(row_indexs), reversed(cnt_row)): p = ans - row_val idx = bisect_left(cnt_col, p) for k in reversed(list(range(idx, w+1))): j = col_indexs[k] if (i, j) in bombs: continue if ans < row_val + cnt_col[k]: ans = row_val + cnt_col[k] break print(ans) if __name__ == "__main__": main()
from bisect import bisect_left def main(): h, w, m = list(map(int, input().split())) bombs = set() cnt_row, cnt_col = [0]*(h+1), [0]*(w+1) for _ in range(m): y, x = list(map(int, input().split())) cnt_row[y] += 1 cnt_col[x] += 1 bombs.add((y, x)) max_cnt_row = max(cnt_row) max_cnt_col = max(cnt_col) idx_row = [] idx_col = [] for i in range(h+1): if cnt_row[i] == max_cnt_row: idx_row.append(i) for j in range(w+1): if cnt_col[j] == max_cnt_col: idx_col.append(j) ans = max_cnt_row + max_cnt_col - 1 for i in idx_row: for j in idx_col: if not (i, j) in bombs: ans = max_cnt_row + max_cnt_col break print(ans) if __name__ == "__main__": main()
p02580
#!/usr/bin/env python3 import sys from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right from itertools import accumulate sys.setrecursionlimit(10**6) INF = 10**12 m = 10**9 + 7 def main(): H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W hw = set() for i in range(M): tmph, tmpw = [int(x)-1 for x in input().split()] h[tmph] += 1 w[tmpw] += 1 hw.add((tmph,tmpw)) # 最大値より1だけ小さくなる物が候補 HMAX = max(h) hcandidate = [] for i in range(H): if h[i] >= HMAX-1: hcandidate.append(i) WMAX = max(w) wcandidate = [] for i in range(W): if w[i] >= WMAX-1: wcandidate.append(i) ans = 0 for i in hcandidate: for j in wcandidate: res = h[i]+w[j] if (i,j) in hw: res -= 1 ans = max(ans, res) print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right from itertools import accumulate sys.setrecursionlimit(10**6) INF = 10**12 m = 10**9 + 7 def main(): H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W hw = set() for i in range(M): tmph, tmpw = [int(x)-1 for x in input().split()] h[tmph] += 1 w[tmpw] += 1 hw.add((tmph,tmpw)) # 最大値より1だけ小さくなる物が候補 HMAX = max(h) h0 = [] for i in range(H): if h[i] == HMAX: h0.append(i) WMAX = max(w) w0 = [] for i in range(W): if w[i] == WMAX: w0.append(i) ans = 0 for i in h0: for j in w0: if (i,j) not in hw: print((HMAX+WMAX)) exit() print((HMAX+WMAX-1)) if __name__ == "__main__": main()
p02580
## coding: UTF-8 #memo:重なっている位置に爆弾があるかないかで、1こ増減することが考えられる #import numpy as np H, W, M = list(map(int,input().split())) tate = [0] * H yoko = [0] * W bomb = set() for i in range(M): hi, wi = list(map(int,input().split())) tate[hi-1] += 1 yoko[wi-1] += 1 bomb.add((hi,wi)) #print(tate) #print(yoko) #print(bomb) ''' tate_max = max(tate) yoko_max = max(yoko) index_tate = [i for i, v in enumerate(tate) if v == tate_max] index_yoko = [i for i, v in enumerate(yoko) if v == yoko_max] ''' tate_max = 0 index_tate = [] for i, v in enumerate(tate): if(tate_max < v): tate_max = v index_tate = [i] elif(tate_max == v): index_tate.append(i) #print(tate_max, index_tate) yoko_max = 0 index_yoko = [] for i, v in enumerate(yoko): if(yoko_max < v): yoko_max = v index_yoko = [i] elif(yoko_max == v): index_yoko.append(i) #print(yoko_max, index_yoko) #print(index_tate, index_yoko) dammy = True #1子でも「そこにない」ものがあれば、そのまま加算、そうでなければ、1こ引く there_is = True for i in index_tate: for j in index_yoko: #print(i+1, j+1) if((i+1, j+1) in bomb): dammy = True else: there_is = False if(there_is): print((tate_max + yoko_max - 1)) else: print((tate_max + yoko_max)) ''' #tate_max = [i for i, v in enumerate(tate) if v == max(tate)] np_list_tate = np.array(tate) np_list_yoko = np.array(yoko) tate_max = np_list_tate.argmax() yoko_max = np_list_yoko.argmax() print(tate_max, yoko_max) '''
## coding: UTF-8 #memo:重なっている位置に爆弾があるかないかで、1こ増減することが考えられる #import numpy as np H, W, M = list(map(int,input().split())) tate = [0] * H yoko = [0] * W bomb = set() for i in range(M): hi, wi = list(map(int,input().split())) tate[hi-1] += 1 yoko[wi-1] += 1 bomb.add((hi,wi)) #print(tate) #print(yoko) #print(bomb) ''' tate_max = max(tate) yoko_max = max(yoko) index_tate = [i for i, v in enumerate(tate) if v == tate_max] index_yoko = [i for i, v in enumerate(yoko) if v == yoko_max] ''' tate_max = 0 index_tate = [] for i, v in enumerate(tate): if(tate_max < v): tate_max = v index_tate = [i] elif(tate_max == v): index_tate.append(i) #print(tate_max, index_tate) yoko_max = 0 index_yoko = [] for i, v in enumerate(yoko): if(yoko_max < v): yoko_max = v index_yoko = [i] elif(yoko_max == v): index_yoko.append(i) #print(yoko_max, index_yoko) #print(index_tate, index_yoko) dammy = True #1子でも「そこにない」ものがあれば、そのまま加算、そうでなければ、1こ引く there_is = True flg = False for i in index_tate: for j in index_yoko: #print(i+1, j+1) if((i+1, j+1) in bomb): dammy = True else: there_is = False flg = True break if flg: break if(there_is): print((tate_max + yoko_max - 1)) else: print((tate_max + yoko_max)) ''' #tate_max = [i for i, v in enumerate(tate) if v == max(tate)] np_list_tate = np.array(tate) np_list_yoko = np.array(yoko) tate_max = np_list_tate.argmax() yoko_max = np_list_yoko.argmax() print(tate_max, yoko_max) '''
p02580
H, W, M = list(map(int, input().split())) h_list = [0 for _ in range(H + 1)] w_list = [0 for _ in range(W + 1)] bomb = [] for _ in range(M): h, w = list(map(int, input().split())) h_list[h] += 1 w_list[w] += 1 bomb.append([h, w]) h_max = max(h_list) w_max = max(w_list) h_index = [] w_index = [] for i in range(H + 1): if h_list[i] == h_max: h_index.append(i) for i in range(W + 1): if w_list[i] == w_max: w_index.append(i) tmp = -1 for h in h_index: for w in w_index: if [h, w] not in bomb: tmp = 0 break print((h_max + w_max + tmp))
H, W, M = list(map(int, input().split())) h_list = [0 for _ in range(H + 1)] w_list = [0 for _ in range(W + 1)] bomb = set([]) for _ in range(M): h, w = list(map(int, input().split())) h_list[h] += 1 w_list[w] += 1 bomb.add((h, w)) h_max = max(h_list) w_max = max(w_list) h_index = [] w_index = [] for i in range(H + 1): if h_list[i] == h_max: h_index.append(i) for i in range(W + 1): if w_list[i] == w_max: w_index.append(i) tmp = -1 for h in h_index: for w in w_index: if (h, w) not in bomb: tmp = 0 break print((h_max + w_max + tmp))
p02580
(h,w,m),*s=[[*list(map(int,i.split()))]for i in open(0)] r,c=[0]*-~h,[0]*-~w for x,y in s: r[x]+=1 c[y]+=1 print(((R:=max(r))+(C:=max(c))-(r.count(R)*c.count(C)==sum(r[x]+c[y]==R+C for x,y in s))))
(h,w,m),*s=[[*list(map(int,i.split()))]for i in open(0)] r,c=[0]*-~h,[0]*-~w for x,y in s: r[x]+=1 c[y]+=1 R,C=max(r),max(c) print((R+C-(r.count(R)*c.count(C)==sum(r[x]+c[y]==R+C for x,y in s))))
p02580
import base64 exec(base64.b64decode(b'aW1wb3J0IHN1YnByb2Nlc3MKaW1wb3J0IHN5cwoKY29kZSA9IHIiIiIjaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNjdHlwZT4KI2luY2x1ZGUgPGNocm9ubz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y29tcGxleD4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHJhbmRvbT4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnVzaW5nIGludDY0ID0gbG9uZyBsb25nOwoKI2RlZmluZSBhbGwoXykgYmVnaW4oXyksIGVuZChfKQojZGVmaW5lIHJhbGwoXykgcmJlZ2luKF8pLCByZW5kKF8pCgppbnQgbWFpbigpIHsKICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICBjaW4udGllKG51bGxwdHIpOwoKICBpbnQgaCwgdywgbTsgY2luID4+IGggPj4gdyA+PiBtOwogIHZlY3RvcjxwYWlyPGludCwgaW50Pj4gaW47CgogIHZlY3RvcjxpbnQ+IGNudF9yb3coaCwgMCksIGNudF9jb2wodywgMCk7CgogIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgKytpKSB7CiAgICBpbnQgaGgsIHd3OyBjaW4gPj4gaGggPj4gd3c7CiAgICAtLWhoOyAtLXd3OwogICAgaW4uZW1wbGFjZV9iYWNrKGhoLCB3dyk7CiAgICArK2NudF9yb3dbaGhdOyArK2NudF9jb2xbd3ddOwogIH0KCiAgaW50IG14X3JvdyA9ICptYXhfZWxlbWVudChhbGwoY250X3JvdykpOwogIGludCBteF9jb2wgPSAqbWF4X2VsZW1lbnQoYWxsKGNudF9jb2wpKTsKICBpbnQgYW5zID0gbXhfcm93ICsgbXhfY29sOwogIGludDY0IGNhbiA9IGNvdW50KGFsbChjbnRfcm93KSwgbXhfcm93KSAqIGNvdW50KGFsbChjbnRfY29sKSwgbXhfY29sKTsKICBpZiAoY2FuID4gbSkgewogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICB9IGVsc2UgewogICAgaW50IGJhZCA9IDA7CiAgICBmb3IgKGF1dG8gZSA6IGluKSBiYWQgKz0gKGNudF9yb3dbZS5maXJzdF0gKyBjbnRfY29sW2Uuc2Vjb25kXSA9PSBhbnMpOwogICAgaWYgKGNhbiA+IGJhZCkgewogICAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgfSBlbHNlIHsKICAgICAgY291dCA8PCBhbnMgLSAxIDw8IGVuZGw7CiAgICB9CiAgfQoKICByZXR1cm4gMDsKfQoiIiIKCndpdGggb3Blbignc29sLmNwcCcsICd3JykgYXMgZjoKICAgIGYud3JpdGUoY29kZSkKCnN1YnByb2Nlc3MuUG9wZW4oWydnKysnLCAnLXN0ZD1jKysxNycsICctTzInLCAnc29sLmNwcCddKS5jb21tdW5pY2F0ZSgpCnN1YnByb2Nlc3MuUG9wZW4oWycuL2Eub3V0J10sIHN0ZGluPXN5cy5zdGRpbiwgc3Rkb3V0PXN5cy5zdGRvdXQpLmNvbW11bmljYXRlKCk='))
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) # Original source code : """ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using int64 = long long; #define all(_) begin(_), end(_) #define rall(_) rbegin(_), rend(_) int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int h, w, m; cin >> h >> w >> m; vector<pair<int, int>> in; vector<int> cnt_row(h, 0), cnt_col(w, 0); for (int i = 0; i < m; ++i) { int hh, ww; cin >> hh >> ww; --hh; --ww; in.emplace_back(hh, ww); ++cnt_row[hh]; ++cnt_col[ww]; } int mx_row = *max_element(all(cnt_row)); int mx_col = *max_element(all(cnt_col)); int ans = mx_row + mx_col; int64 can = count(all(cnt_row), mx_row) * count(all(cnt_col), mx_col); if (can > m) { cout << ans << endl; } else { int bad = 0; for (auto e : in) bad += (cnt_row[e.first] + cnt_col[e.second] == ans); if (can > bad) { cout << ans << endl; } else { cout << ans - 1 << endl; } } return 0; } """ import base64 import subprocess import zlib exe_bin = "c%1E9eQ+Dcb>9O(5t1kX`mjt%mI*tQL&XwINR&jxkwuUMd5DiP!w*|+EuBCB6k&q^0~{n$Bd1JBy1CGB7>|>vjWSi;W~N``DCsnHKRh8#SszW>krOp`B|Fxnk^_XMEk}te*%r~ad%M8h@y<>&{gcZ9-o4+x_xA1Ey}jGT;~xfu77NEAR;=g&gt-$Ag>RsE-{ztSVD)G*eBX)IqeZ~mRC0QHgVR!bu^mOP-lFh&dI!={PDRU*d3kq*mLlXX>S15&*VA^^yEXI@ZI>_8>RG5>JJoBa@{GEu9;2*(Hu~wJxSlp6EwxeFenpDl>+>#!*HZy$DbxEL=q*COeWB)12W`(RE@!B}jIwdKFCOdJUUy$SvN;}0WCk}6)^Fduz0Q+PdbSXsTvWDocQ=v8<84v-yozGDzIE{f7cLG(clEz6)Of!6+$)dFe(eD)yAqYg4M&&*&6U)~s-qQ6>93bFlk>_c_^dF%-!j3!3=Q3FfIns;-)(|F!5QOkn#iv=k&m0;pD@AgCis4ncB>GZ;o8z^V&_jxaF>al`%UoYP5ikZ>@P=aP=j01a?y$QZKUA)?^5teHUVM&rKL#t-h1(!+m1x>Kz}kJrln9y5=A5iyV}G^G!;D%OH0vIS6fp&nTU3Udg4)~&ba3HcX!58=|D$}Tqfh`0KV#!>Y|BAJQ(hjyxwqMC?!g%P)te(!+}5tU|V}a=~!4yrlnLg)F12;yK2Qi=XQ~(ZVks0#F|teOQuB-jn)MdF{#-bI7kG%J48|HOC=9MT|^AU<H<0th{W3u>h!$Z(nE=`cqk_IK}RF8WS|H4dvH)3h^ErXL?|AUhQx!lpq4n)Z`5cLYqTz$%t$zf2f|@7jYH@~Vt3+DED;eqqUlV36jz2>Y$2@S$Hj2p<6>_p76%|a7!pHLbTB4SrZ<M0KMXMxu_7Ia{t$G&wW&$m>ZwJoLa?z(+~TP#UTyJgLrr`3_#1<w*RxfD_v``TI)qmX3#<^OZyS8d=z44=Q@}$0l)}MZfGf?%_IrkwV#&YdSiJ@H(E3{Vtct~!;g#s`DVA9qTZ~tv7gh2cDy@@0`Of2I_{npY%1axcv11R;Q+c*tvi1LjQ=ttye3(90c^y7L<?U`Q&iHdx3dL)oRdwIIroxx0@JlM(slszA+@->=s_^A1{Dulw-?uL67w-O270&Ko{1{!S!rA?c@l`5(klHUtrDqE+!zx_8$bU(N+f?|33Rk}$997}!=i_k|UarFbN`>21_z4xhScSi!!k4J<Nfln9!q2F1hYIIM-nR4OW!<aYh##AjEQNFY$VvM&Dr|e{Ha9A4I0@g*ss^~id>>ZHUn)S^@XwgXq065m{P!@ALzbT;{NG?6PnrA)!as+39J>5*!v87eamex$gntI}I8^yz!had_*xmd9;r|HpI5heFgg=aV9FlxH;ZvB$p~yE7{xRTtCs;rIkN6+<7X01*uI^6g^I(J@w{57w0g#)k`@EC6dqIcKO4WDp*_}VY(Kuap>~<w)0>GR2?4#A~xeZjx&C92Am6WN*%u>vRiT;u5T0wq~moJ=du5QN$a{mGS#+7aXDr*G!SG@ctRBj^H<(s+Zp<W0J)zyKqv(BeI5Y>Qp)_XDFz3iQxsmJk`SISK`eq<U3OQ^2p!$0Q7!T89_+=%U~93Sqg-ZWyH;D`;sFYkQ%L)^9O&fh=~1bHskKUXLS@^$QJ4_tz7O|~7AO>$Rt%}9<5`rd#*Y|4CtmtPY$Ucyna^HVphFe#j)oCODA6B2wm=acx2Gx%abDOJI#D^@{%H}@H^ie0mhgS~MaFK$Zk{kOba{=CgOx)$qXp_bqHLw;(;%4h4|z(eW1=&TwgF%FJb+`-Egm86TlYngX>ZW>>=ja`;j3-T|BL%CD8z;|c>citZ4UJlA9^E0Gn2nLA^37WGC3FD7e*N^*xz8^YAzsTWX{<oPWfRAtS{f|?a<40by3BC)Ns{)wYBlylaN5244&Ep{W(#+D{iSaFd-_>TPa7vN<apoN`)tId-caDBnG3TAd;{xO4`?TNr?8`)sn+^JYl9?g)s)*Q2-h#8L8IR}1W}gKFrxn3BgJAQQyz@J^g1(zac0s6|qxfA)kbfTVp6#6w!YhPuqpfA!Hr!&heHEMm-AT~32b|xZ3~*CCG<2aYd=}K7NWw_ZtZ<{;TOUF!V2l%(jvs-Tj1{D^+*c@DtFXhs;<(x&uDLWY-boz0z6igyg4`3%u`#kVoE-dvz5Yl2d;R<T;<TSUqVh{|xU)NtKyxGSa5)LoXP)9;D9#7p%g#T3;}*8rHa6=V&B0~<Rro3fdh8ou!CLQ~mFK*L{QKCPJe_v|h3NaUb@ll_gKG#v{!TEMyY>O=iaf2jKlOp8H{bg})thhQI{D4qETPjd7iP`_otg2@=96Hym(4fm!mn1k$?}&wP7Ll0EeAe(+hc@mJ5Op)+VhQ2+dJW%4a%?V<K>_8BbTqXcL~|D_wo2<myHmz^B71KZd(Mpzb4}ikQbP4K3ldC8}!}a<tx$}SZXi0l%;mr-om9`5A$d5G@eZ*9`xUH5l4RM!e%zkfj&PqXXWLq{8Vli&z<65nUgBP;Ga{271*Gez2Ti4bO>ec<41Nr1PWjh{HcI$9|kV>@9#sXdFaBavj2jS<*@oN*1I;{OZtPw_vU*GB!s}zl~le(9w1}a`P1ZS#-DDrQ%aul(j&#Gv5S|l@xD`sf<m_XAIL2)|0f<Y3pDK???#`^eg;<60NgWAxOyjK7e6uy3*HQu`86PRJQT`goF?si3p2Ugft!T_^%Jk}LHSkemXO`>(+U#$%|8R$>6dQ><?F)6E5y~QTh?4T=<#E-lDoA22=e=|J~qqm`U|UGhlPjZeQ&`1S!|Wu0u!ZpUYn-RPV%&*?``X>_wz`3e*fr3q3|rwr=Y2S1$qo<ElicagIi$~=<7fufWHls@;uNZ5TRp$zYX*<S9(|B4tF4K(8aB*D7Q~=<t~ilvxx!FzgP7fH<m}Jn#$LLKa*I%;c9VIe%874kbM~KT6_PewpQQG^zoU%8IV)If7HY0QTX8dQ^r7}!<Dr(Ix3&C`W@~kZGK11NLj0+)^cEpqXrPaqY@+<9rl)`r8AVn?E>+t{F`eWZnTd1hM$etzX-Hh4o^VazbN*<g6%(TZFab`wnj(IQ)PZf?URfAj{1@EX2%K6`bp~&M?GNBcB8}H$XfI-rTwS?+iqBwJh<@(9j<*2JLy|B;IBd4qDa$Dpx6$N+u?CLZH|VNQ5)pl74MM|#6$glSSWDo+yU5!mwix<zQvVYD@SwO&ulN2qj$<b>fC6dER=<^P!`HUSttu-p)8b-D(rlho#(RiTlMdhY8v3Qd=I@~XM<m&hl=bB_ar@>T|;?xzPyg|?Cf?erR+SJz3a2R!*AvaNlcH@mt^)1`~p2ZWoM$3w4R+|UZVc7v)xKcZ$sL`&Z76zb4~UxZm0TeKg7;hZ>MzFuEqIst>5)jpPjX`_U}YmIoR%#{&5tVqx>1#u>$3ppI0e=l-A#*y!tHp|Ff{)iS_0Cv}30z{VAnyQF@)yMRY(`Q+f}j+bM0K^kMbk^Y2jD?+mQ8HZ^_PUDMr@Nk|#@4$n4E?dGi+!g;^ot@qT{ZB)?T#<mqkr{3U~TKv0CmmzLNk|Ay@&SNcJR-C_Dd{J?pYw_~p_-k={ao%Y0#l`ul#g`Q4u@+xiyq~pr1v+ksFGKqc#?OizXuuG67S{(Y?n37b@#V$*0WH1)xtAN^E73WFA8D;{H`g1?XDh4<ydl2YaQ<6i6=3Uy7KgjsZG@M87uMoy=V5r+u%Y(~dK`z{0`X+)wTI&CiOw1{bho>xkIN<#J3FYIOAamWqqy6t#RZBF=<pue?x3#S&y(x<@jOcHoY2|%OCmpiT+IAe&d64v9~q3Vk^C#<d;a{nOzg}b-&yj#YM%dd6xaK?oWpkJ&xcQv-&reBrEc8+$%231oj*@JB!8eZ|JiN7(<E;pY=S>yk_UpHKPy!CV>xZ$c@sO=u|Jl|dF!gxVl2N7@Vh{s{jSQEm19;cKmUH;VPfZVCisgM#ebI9#m+3FCh~(OxSRMhe|>w_qV!ikUdJuQc^&^~QN~w4jyJIk$PeGG#ZOxBxH!-xo&Pe$uUHg$eY@|O_`lk!#G#$WGfMG$tj6-KCip(9aem8T6ZvOoyOXqC_PBb^YMkHlf{C41t;TV<Vd4*-r$+c)He>q;r)+q_VI;N+4>kG)QA}rg#GsPNfip*hdQpreV~LoA!YL^&WqNx(VN^=B5v6`Hj8kgTNE9PU@jyJ;6N-xwDVa)(q0Ar(C;JEDQ7Ibn?AY$BHx|O_Br!3RN`;2RXhKR2q25%eKPpBt{ry9rqT)pCibhlvTRQx00Wq+<8D|2Ct-HI$08c@_xdVyKzqi}p7Hon#jdDZ_kQA0;93E<E=?rv<UH(QP09K=skQ72<@F9|klMplMXv8#~r=dZe+VZhUJvwnsehsao$uqxuZj!!@NIEI@g}{<J3rZ{0{D>zN?e!RE9H}yb^e*B|CVd1Fhx+v%XmgB8MsQtMTN4{jmb^5t127(J$Z&wSAB=`!It62$p<pZ!Xz~X7J06U6JlI)_=R{9Btrni2C8ak{lA6Nl44EK?Syv4Ws#K<8`k2nnN2R4{(yu^|rcJ5Z#&<<Asm##BQreY%6bwSLMH7<w`E#Z@at5hvT5pgiJ=8CSdVoqPh4!(lSOQEAAWtGGMLiI&%~I$9<qjk=o}NrB9@!j=Aj0*9(tXGi8A^aXg-R)<<{$(=mP}|E5$aOWcnAy9tAV(Ln}jjLm!1PjxPVy--z1oxRFd4to@gIkRQe*R5(n19VKF)wjt)qoMEdV3tq_V0b`5QY`eR|ZAO>NEArGu|{jew*t+W5fg7^LS(ZHS?X8F>ra60}INSjNg&qsFa<n`MouTG!s&ls)#7=8S^-*wn)Gkvy?W3-0i?0iDMt=f&0vk0co_Ir%7{Bpc~<5c?W+~8rP%|T}SLPjs?0;Z4OKBSx_6#ZYMrJvIIZ_&}mk#aV{c(%`EbQqQVx1#y|Ka7-^GJUomWt5$l=;O!wKT7o*DbMz;jM`QDw;Sj`jnui=rSmFA*|`oY`tg@_`fMM}=%h~GrK8X4^x1xyQGLAZI{Gc0K6{U6v_rS=*Ke2qLZ{E(#~Iac>-GKrYpT!Qx!68MzhBYoGx}Ymz5mVrFTkw*AL#VizMs((x(Tn3=UJUTJ0D=QN+++se=Z^=-;tfemHy8_;q~#>kKZqllE=#Q+5VDWZ|tvL{~FTf&X)d<gSJmQwn(SP{5neeq(AT6Pdk46W7_{vr(fLnP{Qsry*?`zdceu_*?y{$>Nn`lzZ!J<<($&K{=kmuZ`9#N=h#O7Y{66gGjtuo&mj+*zkV!M`K~T5y70H?Caiw`EH}}AcoVhrG3)pL0-|UQSp" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
p02580
import sys import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): H, W, M = [int(x) for x in input().split()] HW = [[int(x) for x in input().split()] for _ in range(M)] x = set() hc = collections.Counter() wc = collections.Counter() for h, w in HW: hc[h] += 1 wc[w] += 1 x.add((h, w)) ans = 0 hcma = hc.most_common()[0][1] wcma = wc.most_common()[0][1] f = False for a in hc.most_common(): if a[1] != hcma: break for b in wc.most_common(): if b[1] != wcma: break if (a[0], b[0]) in x: ans = max(ans, hcma + wcma - 1) else: ans = max(ans, hcma + wcma) f = True break if f: break print(ans) if __name__ == '__main__': main()
import sys import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): H, W, M = [int(x) for x in input().split()] HW = [[int(x) for x in input().split()] for _ in range(M)] x = set() hc = collections.Counter() wc = collections.Counter() for h, w in HW: hc[h] += 1 wc[w] += 1 x.add((h, w)) ans = 0 hcma = hc.most_common()[0][1] wcma = wc.most_common()[0][1] f = False bost_common = wc.most_common() for a in hc.most_common(): if a[1] != hcma: break for b in bost_common: if b[1] != wcma: break if (a[0], b[0]) in x: ans = max(ans, hcma + wcma - 1) else: ans = max(ans, hcma + wcma) f = True break if f: break print(ans) if __name__ == '__main__': main()
p02580
import sys def input(): return sys.stdin.readline().strip() def main(): H, W, M = list(map(int, input().split())) bomb = set() yoko = [0] * W tate = [0] * H for _ in range(M): h, w = list(map(int, input().split())) bomb.add((h-1, w-1)) yoko[w - 1] += 1 tate[h - 1] += 1 idx_yoko = [(yoko[i], i) for i in range(W)] idx_tate = [(tate[i], i) for i in range(H)] idx_yoko.sort(reverse=True, key=lambda x: (x[0], x[1])) idx_tate.sort(reverse=True, key=lambda x: (x[0], x[1])) ans = 0 for p in range(min(5000, W)): for q in range(min(5000, H)): yoko_bomb, idx_w = idx_yoko[p] tate_bomb, idx_h = idx_tate[q] get_bomb = yoko_bomb + tate_bomb if (idx_h, idx_w) in bomb: get_bomb -= 1 ans = max(ans, get_bomb) print(ans) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().strip() def main(): H, W, M = list(map(int, input().split())) bomb = set() yoko = [0] * W tate = [0] * H for _ in range(M): h, w = list(map(int, input().split())) bomb.add((h-1, w-1)) yoko[w - 1] += 1 tate[h - 1] += 1 idx_yoko = [(yoko[i], i) for i in range(W)] idx_tate = [(tate[i], i) for i in range(H)] idx_yoko.sort(reverse=True, key=lambda x: (x[0], x[1])) idx_tate.sort(reverse=True, key=lambda x: (x[0], x[1])) ans = 0 yoko_bomb, idx_w = idx_yoko[0] tate_bomb_max = idx_tate[0][0] for tate_bomb, idx_h in idx_tate: if tate_bomb != tate_bomb_max: break if (idx_h, idx_w) not in bomb: print((yoko_bomb + tate_bomb)) return tate_bomb, idx_h = idx_tate[0] yoko_bomb_max = idx_yoko[0][0] for yoko_bomb, idx_w in idx_yoko: if yoko_bomb != yoko_bomb_max: break if (idx_h, idx_w) not in bomb: print((yoko_bomb + tate_bomb)) return print((yoko_bomb_max + tate_bomb_max - 1)) if __name__ == "__main__": main()
p02580
from collections import Counter H, W, M = list(map(int, input().split())) count_row = Counter() count_col = Counter() count_point = Counter() for i in range(M): h, w = list(map(int, input().split())) count_row[h] += 1 count_col[w] += 1 count_point[(h, w)] += 1 max_h, max_count_row = count_row.most_common()[0] max_w, max_count_col = count_col.most_common()[0] row_iter = [(h, c) for h, c in count_row.most_common() if c == max_count_row] col_iter = [(w, c) for w, c in count_col.most_common() if c == max_count_col] ans = 0 for h, row_c in row_iter: for w, col_c in col_iter: ans = max(ans, row_c+col_c-count_point[(h, w)]) print(ans)
from collections import Counter H, W, M = list(map(int, input().split())) count_row = Counter() count_col = Counter() count_point = Counter() for i in range(M): h, w = list(map(int, input().split())) count_row[h] += 1 count_col[w] += 1 count_point[(h, w)] += 1 max_h, max_count_row = count_row.most_common()[0] max_w, max_count_col = count_col.most_common()[0] row_iter = [h for h, c in count_row.most_common() if c == max_count_row] col_iter = [w for w, c in count_col.most_common() if c == max_count_col] ans = max_count_row + max_count_col - 1 flag = False for h in row_iter: for w in col_iter: if count_point[(h, w)] == 1: continue ans += 1 flag = True break if flag: break print(ans)
p02580
import sys H,W,M = list(map(int, input().split())) grid = [[0 for _ in range(W)] for _ in range(H)] hc = [0 for h in range(H)] wc = [0 for w in range(W)] for _ in range(M): h,w = list(map(int, input().split())) h-=1 w-=1 grid[h][w] = 1 hc[h] += 1 wc[w] += 1 hmax = max(hc) wmax = max(wc) htable = [] for h in range(H): if hc[h] == hmax: htable.append(h) wtable = [] for w in range(W): if wc[w] == wmax: wtable.append(w) # print(uw, uh) #print(grid) #print(wc, uw) #print(hc, uh) found = False for h in htable: for w in wtable: if grid[h][w] == 0: print((hmax + wmax)) sys.exit(0) print((hmax + wmax - 1))
H,W,M = list(map(int, input().split())) # grid = [[0 for _ in range(W)] for _ in range(H)] bombs = set() hc = [0 for h in range(H)] wc = [0 for w in range(W)] for _ in range(M): h,w = list(map(int, input().split())) h-=1 w-=1 bombs.add((h, w)) hc[h] += 1 wc[w] += 1 hmax = max(hc) wmax = max(wc) htable = [] for h in range(H): if hc[h] == hmax: htable.append(h) wtable = [] for w in range(W): if wc[w] == wmax: wtable.append(w) # print(uw, uh) #print(grid) #print(wc, uw) #print(hc, uh) found = False for h in htable: for w in wtable: if (h,w) not in bombs: print((hmax + wmax)) exit(0) print((hmax + wmax - 1))
p02580
# 初期入力 import sys from collections import defaultdict input = sys.stdin.readline #文字列では使わない H,W,M = list(map(int, input().split())) bom_H ={i:0 for i in range(1,H+1)} bom_W ={i:0 for i in range(1,W+1)} posision =defaultdict(int) for i in range(M): h,w = list(map(int, input().split())) bom_H[h] +=1 bom_W[w] +=1 posision[(h,w)] =1 max_H = [kv for kv in list(bom_H.items()) if kv[1] == max(bom_H.values())] max_W = [kv for kv in list(bom_W.items()) if kv[1] == max(bom_W.values())] ans =0 for p_h,v_h in max_H: for p_w,v_w in max_W: if posision[(p_h,p_w)] ==1: ans =max(ans,v_h +v_w -1) else: ans =max(ans,v_h +v_w ) break print(ans)
import sys H, W, M = list(map(int, input().split())) bomb = [tuple([int(x) - 1 for x in s.split()]) for s in sys.stdin.readlines()] X = [0] * H # 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: # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため, # 即座に探索を終了する. if (r, c) not in bomb: print((maxX + maxY)) exit() print((maxX + maxY - 1))
p02580
# 初期入力 import sys from collections import defaultdict input = sys.stdin.readline #文字列では使わない H,W,M = list(map(int, input().split())) bom_H =defaultdict(int) bom_W =defaultdict(int) posision =set() for i in range(M): h,w = list(map(int, input().split())) bom_H[h] +=1 bom_W[w] +=1 posision.add((h,w)) indx_H = [k for k,v in list(bom_H.items()) if v == max(bom_H.values())] indx_W = [k for k,v in list(bom_W.items()) if v == max(bom_W.values())] set_max_H = set(indx_H) set_max_W = set(indx_W) temp_H =max(bom_H.values()) temp_W =max(bom_W.values()) flag =False for h in set_max_H: for w in set_max_W: if (h,w) not in posision: flag =True break if flag==True: break if flag ==True: print((temp_H +temp_W )) else: print((temp_H +temp_W -1))
# 初期入力 import sys from collections import defaultdict input = sys.stdin.readline #文字列では使わない H,W,M = list(map(int, input().split())) bom_H =defaultdict(int) bom_W =defaultdict(int) posision =set() for i in range(M): h,w = list(map(int, input().split())) bom_H[h] +=1 bom_W[w] +=1 posision.add((h,w)) temp_H =max(bom_H.values()) temp_W =max(bom_W.values()) indx_H = [k for k,v in list(bom_H.items()) if v == temp_H] indx_W = [k for k,v in list(bom_W.items()) if v == temp_W] set_max_H = set(indx_H) set_max_W = set(indx_W) flag =False for h in set_max_H: for w in set_max_W: if (h,w) not in posision: flag =True break if flag==True: break if flag ==True: print((temp_H +temp_W )) else: print((temp_H +temp_W -1))
p02580
import sys sys.setrecursionlimit(10**7) 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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし H,W,M = MI() hw = [tuple(MI()) for _ in range(M)] A = [0]*(H+1) B = [0]*(W+1) from collections import defaultdict d = defaultdict(int) for h,w in hw: A[h] += 1 B[w] += 1 d[(h,w)] = 1 ma = max(A) mb = max(B) ans = ma+mb C,D = [],[] for i in range(1,H+1): if A[i] == ma: C.append(i) for i in range(1,W+1): if B[i] == mb: D.append(i) if len(C)*len(D) > M: print(ans) else: for i in C: for j in D: if d[(i,j)] == 0: print(ans) exit() print((ans-1))
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) H,W,M = MI() X = [0]*(H+1) # X[i] = x座標がiである爆破対象はいくつあるか Y = [0]*(W+1) # Y[i] = y座標がiである爆破対象はいくつあるか from collections import defaultdict d = defaultdict(int) # d[(h,w)] == 1 ⇔ 座標(h,w)に爆破対象が存在する for i in range(M): h,w = MI() X[h] += 1 Y[w] += 1 d[(h,w)] = 1 mx = max(X) my = max(Y) ans = mx+my A = [i for i in range(1,H+1) if X[i] == mx] B = [i for i in range(1,W+1) if Y[i] == my] if len(A)*len(B) > M: print(ans) else: for i in A: for j in B: if d[(i,j)] == 0: print(ans) exit() print((ans-1))
p02580
import collections import sys *data, = list(map(int, sys.stdin.read().split()[::-1])) def inp(): return data.pop() h, w, m = inp(), inp(), inp() targets = set() xs = [] ys = [] for _ in range(m): y, x = inp(), inp() # y -= 1 # x -= 1 ys.append(y) xs.append(x) targets.add((y, x)) x_stat = collections.Counter(xs) y_stat = collections.Counter(ys) xs = sorted(set(xs), key=lambda obj: x_stat[obj], reverse=True) ys = sorted(set(ys), key=lambda obj: y_stat[obj], reverse=True) mx_x = x_stat[xs[0]] mx_y = y_stat[ys[0]] while xs and x_stat[xs[-1]] < x_stat[xs[0]]: xs.pop() while ys and y_stat[ys[-1]] < y_stat[ys[0]]: ys.pop() best_res = 0 # print(xs, x_stat) # print(ys, y_stat) for x in xs: for y in ys: cur = x_stat[x] + y_stat[y] - ((y, x) in targets) best_res = max(cur, best_res) print(best_res)
import collections import sys *data, = list(map(int, sys.stdin.read().split()[::-1])) def inp(): return data.pop() h, w, m = inp(), inp(), inp() targets = set() xs = [] ys = [] for _ in range(m): y, x = inp(), inp() # y -= 1 # x -= 1 ys.append(y) xs.append(x) targets.add((y, x)) x_stat = collections.Counter(xs) y_stat = collections.Counter(ys) xs = sorted(set(xs), key=lambda obj: x_stat[obj], reverse=True) ys = sorted(set(ys), key=lambda obj: y_stat[obj], reverse=True) mx_x = x_stat[xs[0]] mx_y = y_stat[ys[0]] while xs and x_stat[xs[-1]] < x_stat[xs[0]]: xs.pop() while ys and y_stat[ys[-1]] < y_stat[ys[0]]: ys.pop() # print(xs, x_stat) # print(ys, y_stat) found = False for x in xs: for y in ys: if (y, x) not in targets: found = True break ans = mx_y + mx_x if not found: ans -= 1 print(ans)
p02580
h, w, m = list(map(int, input().split())) bomb = [[False for i in range(w)] for j in range(h)] cnth = [0 for i in range(h)] cntw = [0 for i in range(w)] for i in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 cnth[x] += 1 cntw[y] += 1 bomb[x][y] = True maxh = max(cnth) maxw = max(cntw) xx = [] yy = [] for i in range(h): if maxh == cnth[i]: xx.append(i) for i in range(w): if maxw == cntw[i]: yy.append(i) ans = maxh + maxw -1 for i in xx: for j in yy: if not bomb[i][j]: ans += 1 print (ans) exit() print (ans)
h, w, m = list(map(int, input().split())) bomb = [] cnth = [0 for i in range(h)] cntw = [0 for i in range(w)] bomh = [set() for i in range(h)] bomw = [set() for i in range(w)] for i in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 cnth[x] += 1 cntw[y] += 1 bomh[x].add(y) bomw[y].add(x) bomb.append([x,y]) maxh = max(cnth) maxw = max(cntw) ans = maxh + maxw - 1 xx = [] yy = [] for i in range(h): if maxh == cnth[i]: xx.append(i) for i in range(w): if maxw == cntw[i]: yy.append(i) for i in xx: for j in yy: if j not in bomh[i]: print((ans+1)) exit() print (ans)
p02580
H,W,M=list(map(int,input().split())) s=[list(map(int,input().split())) for _ in range(M)] Tr=[0 for _ in range(H+1)] Tc=[0 for _ in range(W+1)] for i in range(M): Tr[s[i][0]]+=1 Tc[s[i][1]]+=1 mr=max(Tr) mc=max(Tc) Mr=[i for i,x in enumerate(Tr) if x==mr] Mc=[i for i,x in enumerate(Tc) if x==mc] ans=0 for i in range(len(Mr)): for j in range(len(Mc)): if not ([Mr[i],Mc[j]] in s): ans=mr+mc break else: continue break if ans==0: ans=mr+mc-1 print(ans)
H,W,M=list(map(int,input().split())) s=[list(map(int,input().split())) for _ in range(M)] Tr=[0 for _ in range(H+1)] Tc=[0 for _ in range(W+1)] for i in range(M): Tr[s[i][0]]+=1 Tc[s[i][1]]+=1 mr=max(Tr) mc=max(Tc) Mr=[0 for _ in range(H+1)] Mc=[0 for _ in range(W+1)] Nmr=0 Nmc=0 for i in range(len(Tr)): if Tr[i]==mr: Mr[i]=1 Nmr+=1 for i in range(len(Tc)): if Tc[i]==mc: Mc[i]=1 Nmc+=1 cnt=0 for i in range(M): if Mr[s[i][0]]==1 and Mc[s[i][1]]==1: cnt+=1 if cnt<Nmr*Nmc: print((mr+mc)) else: print((mr+mc-1))
p02580
from collections import* h,w,m=list(map(int,input().split())) d=defaultdict(int) a=[0]*h b=[0]*w for _ in range(m): x,y=list(map(int,input().split())) x-=1 y-=1 a[x]+=1 b[y]+=1 d[x*10**6+y]+=1 ma=max(a) mb=max(b) ind_x=[i for i,j in enumerate(a) if j==ma] ind_y=[i for i,j in enumerate(b) if j==mb] for x in ind_x: for y in ind_y: if d[x*10**6+y]==0: print((ma+mb)) exit() print((ma+mb-1))
h,w,m=list(map(int,input().split())) d=dict() a=[0]*h b=[0]*w for _ in range(m): x,y=list(map(int,input().split())) x-=1 y-=1 a[x]+=1 b[y]+=1 d[x*10**6+y]=1 ma=max(a) mb=max(b) ind_x=[i for i,j in enumerate(a) if j==ma] ind_y=[i for i,j in enumerate(b) if j==mb] for x in ind_x: for y in ind_y: if not(x*10**6+y in d): print((ma+mb)) exit() print((ma+mb-1))
p02580
h,w,m=list(map(int,input().split())) d=dict() s=set() a=[0]*h b=[0]*w for _ in range(m): x,y=list(map(int,input().split())) x-=1 y-=1 a[x]+=1 b[y]+=1 d[x*10**6+y]=1 s.add(x*10**6+y) ma=max(a) mb=max(b) ind_x=[i for i,j in enumerate(a) if j==ma] ind_y=[i for i,j in enumerate(b) if j==mb] for x in ind_x: for y in ind_y: if not(x*10**6+y in s): print((ma+mb)) exit() print((ma+mb-1))
h,w,m=list(map(int,input().split())) a=[0]*h;b=[0]*w s=set() for _ in range(m): x,y=[int(x)-1 for x in input().split()] a[x]+=1;b[y]+=1 s.add(x*10**6+y) ma=max(a);mb=max(b) c=[i for i,v in enumerate(a) if v==ma] d=[i for i,v in enumerate(b) if v==mb] for x in c: for y in d: if not(x*10**6+y in s): print((ma+mb)) exit() print((ma+mb-1))
p02580
f=lambda:map(int,input().split()) H,W,M=f() g=[set() for _ in range(H)] ch=[0]*H cw=[0]*W for _ in range(M): h,w=f() g[h-1].add(w-1) ch[h-1]+=1 cw[w-1]+=1 mh=max(ch) mw=max(cw) lh=[i for i in range(H) if ch[i]==mh] lw=[i for i in range(W) if cw[i]==mw] c=mh+mw for i in lh: if len(g[i])<1: exit(print(c)) for j in lw: if j not in g[i]: exit(print(c)) print(c-1)
f=lambda:list(map(int,input().split())) h,w,m=f() l,H,W=[],[0]*-~h,[0]*-~w for _ in range(m): x,y=f() l+=[(x,y)] H[x]+=1 W[y]+=1 s,t=max(H),max(W) print((s+t-(H.count(s)*W.count(t)==sum(H[x]+W[y]==s+t for x,y in l))))
p02580
import sys from collections import deque H, W, M = list(map(int, input().split())) S = list(tuple(map(int, input().split())) for _ in range(M)) hh = dict() ww = dict() for i in range(M): h, w = S[i] if h in list(hh.keys()): hh[h] += 1 else: hh[h] = 1 if w in list(ww.keys()): ww[w] += 1 else: ww[w] = 1 hhh = sorted(list(hh.items()), key=lambda x:x[1], reverse=True) www = sorted(list(ww.items()), key=lambda x:x[1], reverse=True) ans = hhh[0][1] + www[0][1] if (hhh[0][0], www[0][0]) not in S: print(ans) sys.exit() h = hhh[0][0] for j in range(1, len(www)): if www[j][1] == www[j-1][1]: if (h, www[j][0]) not in S: print(ans) sys.exit() else: break for i in range(1, len(hhh)): if hhh[i][1] == hhh[i-1][1]: h = hhh[i][0] if (h, www[0][0]) not in S: print(ans) sys.exit() for j in range(1, len(www)): if www[j][1] == www[j-1][1]: if (h, www[j][0]) not in S: print(ans) sys.exit() else: break else: break print((ans-1))
import sys from collections import deque H, W, M = list(map(int, input().split())) S = list(tuple(map(int, input().split())) for _ in range(M)) hh = dict() ww = dict() for i in range(M): h, w = S[i] if h in list(hh.keys()): hh[h] += 1 else: hh[h] = 1 if w in list(ww.keys()): ww[w] += 1 else: ww[w] = 1 hhh = sorted(list(hh.items()), key=lambda x:x[1], reverse=True) www = sorted(list(ww.items()), key=lambda x:x[1], reverse=True) h = hhh[0][1] w = www[0][1] ans = h+w Nh = 0 Nw = 0 for i in range(len(hhh)): if h == hhh[i][1]: Nh += 1 else: break for i in range(len(www)): if w == www[i][1]: Nw += 1 else: break tt = Nh*Nw if tt > M: print(ans) sys.exit() for tmp in S: if hh[tmp[0]] == h and ww[tmp[1]] == w: tt -= 1 if tt > 0: print(ans) else: print((ans-1))
p02580
h, w, m = list(map(int, input().split())) h_l = [[] for i in range(h + 1)] w_l = [[] for i in range(w + 1)] max_h = 0 max_h_l = [] max_w = 0 max_w_l = [] inputs = [] for _ in range(m): h, w = list(map(int, input().split())) inputs.append([h,w]) if h_l[h] : h_l[h][1].append(w) h_l[h][0] += 1 else: h_l[h] = [1, [w]] if h_l[h][0] > max_h: max_h_l = [h] max_h = h_l[h][0] elif h_l[h][0] == max_h: max_h_l.append(h) if w_l[w]: w_l[w][1].append(h) w_l[w][0] += 1 else: w_l[w] = [1, [h]] if w_l[w][0] > max_w: max_w_l = [w] max_w = w_l[w][0] elif w_l[w][0] == max_w: max_w_l.append(w) flag = 0 ans = 0 for i in max_h_l: if flag == 1: break for j in max_w_l: if flag == 1: break if j in h_l[i][1]: ans = max_h + max_w - 1 else: ans = max_h + max_w flag = 1 print(ans)
h, w, m = list(map(int, input().split())) h_l = [[] for i in range(h + 1)] w_l = [[] for i in range(w + 1)] max_h = 0 max_h_l = [] max_w = 0 max_w_l = [] inputs = {} for _ in range(m): h, w = list(map(int, input().split())) inputs.setdefault(h, set([w])) inputs[h].add(w) if h_l[h] : h_l[h][1].add(w) h_l[h][0] += 1 else: h_l[h] = [1, set([w])] if h_l[h][0] > max_h: max_h_l = [h] max_h = h_l[h][0] elif h_l[h][0] == max_h: max_h_l.append(h) if w_l[w]: w_l[w][1].add(h) w_l[w][0] += 1 else: w_l[w] = [1, set([h])] if w_l[w][0] > max_w: max_w_l = [w] max_w = w_l[w][0] elif w_l[w][0] == max_w: max_w_l.append(w) ans = max_h + max_w -1 flag = 0 for i in max_h_l: if flag == 1: break for j in max_w_l: if j not in inputs[i]: ans = max_h + max_w flag = 1 break print(ans)
p02580
import sys H, W, M = list(map(int, sys.stdin.readline().strip().split())) h = [0] * H w = [0] * W g = [[False] * W for _ in range(H)] S = set() for _ in range(M): Th, Tw = list(map(int, sys.stdin.readline().strip().split())) h[Th - 1] += 1 w[Tw - 1] += 1 # g[Th - 1][Tw - 1] = True S.add((Th - 1, Tw - 1)) max_h = max(h) max_w = max(w) ans = max_h + max_w index_h = [n for n, v in enumerate(h) if v == max_h] index_w = [n for n, v in enumerate(w) if v == max_w] sub = 1 # for ih in index_h: # for iv in index_w: # if g[ih][iv] is False: # sub = 0 # break # else: # continue # break # ans -= sub # print(ans) for ih in index_h: for iv in index_w: if not (ih, iv) in S: print(ans) exit() print((ans - 1))
import sys H, W, M = list(map(int, sys.stdin.readline().strip().split())) h = [0] * H w = [0] * W # g = [[False] * W for _ in range(H)] S = set() for _ in range(M): Th, Tw = list(map(int, sys.stdin.readline().strip().split())) h[Th - 1] += 1 w[Tw - 1] += 1 # g[Th - 1][Tw - 1] = True S.add((Th - 1, Tw - 1)) max_h = max(h) max_w = max(w) ans = max_h + max_w index_h = [n for n, v in enumerate(h) if v == max_h] index_w = [n for n, v in enumerate(w) if v == max_w] sub = 1 # for ih in index_h: # for iv in index_w: # if g[ih][iv] is False: # sub = 0 # break # else: # continue # break # ans -= sub # print(ans) for ih in index_h: for iv in index_w: if not (ih, iv) in S: print(ans) exit() print((ans - 1))
p02580
h, w, m = list(map(int, input().split())) hw_map = [[0 for i in range(w)] for j in range(h)] h_bomb_list = [0 for i in range(h)] w_bomb_list = [0 for i in range(w)] for i in range(m): bh, bw = list(map(int, input().split())) hw_map[bh-1][bw-1] = 1 h_bomb_list[bh-1] += 1 w_bomb_list[bw-1] += 1 h_max = max(h_bomb_list) h_argmax = max(list(zip(h_bomb_list, list(range(len(h_bomb_list))))))[1] w_max = max([w_bomb_list[i] - hw_map[h_argmax][i] for i in range(w)]) print((int(h_max+w_max)))
h, w, m = list(map(int, input().split())) h_b_list = [0 for i in range(h)] w_b_list = [0 for i in range(w)] targets = [] for i in range(m): bh, bw = list(map(int, input().split())) targets.append([bh, bw]) h_b_list[bh-1] += 1 w_b_list[bw-1] += 1 h_max = max(h_b_list) w_max = max(w_b_list) h_cans = [] w_cans = [] for i in range(h): if h_b_list[i] == h_max: h_cans.append(i) for i in range(w): if w_b_list[i] == w_max: w_cans.append(i) for hi in h_cans: for wi in w_cans: if [hi+1, wi+1] not in targets: print((h_max+w_max)) exit() else: print((h_max+w_max-1))
p02580
import sys from bisect import bisect_left as bl input = sys.stdin.readline H, W, N = list(map(int, input().split())) ys = [0] * (H + 1) xs = [0] * (W + 1) a = [] base = 10 ** 6 for i in range(N): y, x = list(map(int, input().split())) ys[y] += 1 xs[x] += 1 a.append((y, x)) sy = sorted(ys[1: ]) sx = sorted(xs[1: ]) #print(sy, sx) def check(k): res = 0 for y, x in a: res -= (ys[y] + xs[x]) == k res += (ys[y] + xs[x]) > k #print(res, k) for y in sy: i = bl(sx, k - y) res += W - i #print(W - i, y, k, res) return res > 0 ok = 0 ng = N + 1 while ng - ok > 1: m = (ok + ng) // 2 if check(m): ok = m else: ng = m print(ok)
import sys input = sys.stdin.readline H, W, M = list(map(int, input().split())) s = set() ys = [0] * (H + 1) xs = [0] * (W + 1) for _ in range(M): y, x = list(map(int, input().split())) s.add((y, x)) ys[y] += 1 xs[x] += 1 res = 0 mxy = [] mx = max(ys) for i in range(H + 1): if ys[i] == mx: mxy.append(i) res += mx mxx = [] mx = max(xs) for i in range(W + 1): if xs[i] == mx: mxx.append(i) res += mx - 1 for x in mxx: for y in mxy: if (y, x) in s: continue res += 1 break else: continue break print(res)
p02580
h,w,m=list(map(int,input().split())) bomb=[list(map(int,input().split())) for i in range(m)] num_h = [0] * (h+1) num_w = [0] * (w+1) bomb_set = set() for hi,wi in bomb: num_h[hi] += 1 num_w[wi] += 1 bomb_set.add((hi,wi)) max_hs = [k for k,v in enumerate(num_h) if v == max(num_h)] max_ws = [k for k,v in enumerate(num_w) if v == max(num_w)] result = max(num_h) + max(num_w) for i in max_hs: for j in max_ws: if (i,j) not in bomb_set: print(result) exit(0) print((result-1))
h,w,m=list(map(int,input().split())) bomb=[list(map(int,input().split())) for i in range(m)] num_h = [0] * (h+1) num_w = [0] * (w+1) bomb_set = set() for hi,wi in bomb: num_h[hi] += 1 num_w[wi] += 1 bomb_set.add((hi,wi)) max_h = max(num_h) max_w = max(num_w) max_hs = [k for k,v in enumerate(num_h) if v == max_h] max_ws = [k for k,v in enumerate(num_w) if v == max_w] result = max_h + max_w for i in max_hs: for j in max_ws: if (i,j) not in bomb_set: print(result) exit(0) print((result-1))
p02580
from itertools import product from sys import exit def maxindexes(L,Lmax): ret = [] for i in range(len(L)): if L[i] == Lmax: ret.append(i) return ret H,W,M = list(map(int,input().split())) row = [0]*H col = [0]*W bomb = [] for _ in range(M): a,b = (int(x)-1 for x in input().split()) row[a] += 1 col[b] += 1 bomb.append((a,b)) rmax = max(row) cmax = max(col) rmaxind= maxindexes(row,rmax) cmaxind = maxindexes(col,cmax) for p in product(rmaxind,cmaxind): if p not in bomb: print((rmax+cmax)) exit(0) print((rmax+cmax-1))
from itertools import product from sys import exit def maxindexes(L,Lmax): ret = [] for i in range(len(L)): if L[i] == Lmax: ret.append(i) return ret H,W,M = list(map(int,input().split())) row = [0]*H col = [0]*W bomb = set([]) for _ in range(M): a,b = (int(x)-1 for x in input().split()) row[a] += 1 col[b] += 1 bomb.add((a,b)) rmax = max(row) cmax = max(col) rmaxind= maxindexes(row,rmax) cmaxind = maxindexes(col,cmax) prod = product(rmaxind,cmaxind) for p in prod: if p not in bomb: print((rmax+cmax)) exit(0) print((rmax+cmax-1))
p02580
import sys h,w,m = list(map(int,input().split())) h_lst = [0]*h w_lst = [0]*w memo = [] for i in range(m): x,y = list(map(int,input().split())) h_lst[x-1] += 1 w_lst[y-1] += 1 memo.append((x-1,y-1)) sh = 0 for i in range(h): if h_lst[i] > sh: sh = h_lst[i] sw = 0 for i in range(w): if w_lst[i] > sw: sw = w_lst[i] memo = set(memo) for i in range(h): if h_lst[i] == sh: for j in range(w): if (i,j) not in memo and w_lst[j] == sw: print((sh+sw)) sys.exit() print(((sh+sw)-1))
import sys h,w,m = list(map(int,input().split())) h_lst = [[0,i] for i in range(h)] w_lst = [[0,i] for i in range(w)] memo = [] for i in range(m): x,y = list(map(int,input().split())) h_lst[x-1][0] += 1 w_lst[y-1][0] += 1 memo.append((x-1,y-1)) h_lst.sort(reverse = True) w_lst.sort(reverse = True) Max_h = h_lst[0][0] Max_w = w_lst[0][0] h_ans = [h_lst[0][1]] w_ans = [w_lst[0][1]] if h != 1: s = 1 while s < h and h_lst[s][0] == Max_h: h_ans.append(h_lst[s][1]) s+= 1 if w!= 1: t=1 while t < w and w_lst[t][0] == Max_w: w_ans.append(w_lst[t][1]) t += 1 memo = set(memo) #探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない! for j in h_ans: for k in w_ans: if (j,k) not in memo: print((Max_h+Max_w)) sys.exit() print(((Max_h+Max_w)-1))
p02580
from sys import stdin input = stdin.readline from collections import defaultdict, deque h, w, m = list(map(int,input().split())) row = defaultdict(int) col = defaultdict(int) grid = defaultdict(int) for _ in range(m): x,y = list(map(int,input().split())) row[x]+=1 col[y]+=1 grid[(x,y)]=1 row = sorted(list(row.items()), key = lambda x: x[1], reverse = True) col = sorted(list(col.items()), key = lambda x: x[1], reverse = True) i,j = 0,0 ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0) dq = deque([(i,j)]) while dq: i,j = dq.popleft() temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0) if ans<temp: ans = temp break if i+1<len(row):dq.append((i+1,j)) if j+1<len(col):dq.append((i,j+1)) print(ans)
from sys import stdin input = stdin.readline from collections import defaultdict, deque h, w, m = list(map(int,input().split())) row = defaultdict(int) col = defaultdict(int) grid = defaultdict(int) for _ in range(m): x,y = list(map(int,input().split())) row[x]+=1 col[y]+=1 grid[(x,y)]=1 row = sorted(list(row.items()), key = lambda x: x[1], reverse = True) col = sorted(list(col.items()), key = lambda x: x[1], reverse = True) #print(row) #print(col) t = len(row) for idx, ele in enumerate(row): i,j = ele if j!=row[0][1]: t = idx break row = row[:t] t = len(col) for idx, ele in enumerate(col): i,j = ele if j!=col[0][1]: t = idx break col = col[:t] #print(row) #print(col) #print(grid) ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0) i,j = 0,0 for r,cr in row: for c,cc in col: if not grid[(r,c)]: ans = cr+cc break print(ans) # dq = deque([(i,j)]) # while dq: # i,j = dq.popleft() # temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0) # if ans<temp: # ans = temp # break # if i+1<len(row):dq.append((i+1,j)) # if j+1<len(col):dq.append((i,j+1)) # print(ans)
p02580
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from math import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 INF = float('inf') from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) H,W,M = readInts() dic1 = defaultdict(int) dic2 = defaultdict(int) s = set() for i in range(M): h,w = [int(x)-1 for x in input().split()] dic1[h] += 1 dic2[w] += 1 s.add((h,w)) # print(dic) ans = 0 # 辞書の値が最大・最小となるキーを取得 max1 = max(dic1.values()) max2 = max(dic2.values()) for k1,v1 in list(dic1.items()): if v1 < max1: continue for k2,v2 in list(dic2.items()): if v2 < max2: continue if (k1,k2) in s: ans = max(ans,dic1[k1] + dic2[k2] - 1) else: ans = max(ans,dic1[k1] + dic2[k2]) print(ans)
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from math import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 INF = float('inf') from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) H,W,M = readInts() dic1 = Counter() dic2 = Counter() s = set() for i in range(M): h,w = [int(x)-1 for x in input().split()] dic1[h] += 1 dic2[w] += 1 s.add((h,w)) # print(dic) ans = 0 # 重なっているもので最大値がある時もあれば # 行、列の交差点でボムなしが一番大きいものがある for h,w in s: ans = max(ans, dic1[h] + dic2[w] - 1) dic1 = dic1.most_common() dic2 = dic2.most_common() max1 = dic1[0][1] max2 = dic2[0][1] for k1,v1 in dic1: if v1 < max1: break # continueする必要がない most_commonで大きい方から集めてるので for k2,v2 in dic2: if v2 < max2: break # 同じく if (k1,k2) in s: # 一度計算したもの continue # 両方とも最大であればok ans = max(ans, v1 + v2) break print(ans)
p02580
#!/usr/bin/env python3 import collections import sys input=sys.stdin.readline h,w,m=list(map(int,input().split())) items=[set() for _ in range(h+1)] count_h=[0]*(h+1) count_w=[0]*(w+1) for _ in range(m): y,x=list(map(int,input().split())) items[y].add(x) count_h[y]+=1 count_w[x]+=1 count_num=collections.defaultdict(int) for x in range(1,w+1): count_num[count_w[x]]+=1 count_cand=list(count_num.keys()) count_cand=sorted(count_cand,reverse=True) ans=0 for y in range(1,h+1): value_y=count_h[y] count_tmp=collections.defaultdict(int) for x in items[y]: value_x=count_w[x] count_tmp[value_x]+=1 ans=max(ans,value_y+value_x-1) for x in count_cand: if count_num[x]>count_tmp[x]: ans=max(ans,value_y+x) break print(ans)
#!/usr/bin/env python3 import collections import sys input=sys.stdin.readline h,w,m=list(map(int,input().split())) items=set() count_h=[0]*(h+1) count_w=[0]*(w+1) for _ in range(m): y,x=list(map(int,input().split())) items.add((y,x)) count_h[y]+=1 count_w[x]+=1 max_h=max(count_h) max_w=max(count_w) cand_h=[] cand_w=[] for y in range(1,h+1): if count_h[y]==max_h: cand_h.append(y) for x in range(1,w+1): if count_w[x]==max_w: cand_w.append(x) ans=max_h+max_w for y in cand_h: for x in cand_w: if (y,x) not in items: print(ans) exit() else: print((ans-1))
p02580
#import random def putmx(lis,mx): ret=[] for (i,j) in zip(list(range(len(lis))),lis): if j==mx: ret.append(i) return ret h,w,m=list(map(int,input().split())) hb=[0]*h wb=[0]*w bmb=[] for i in range(h): bmb.append([]) for i in range(m): hh,ww=list(map(int,input().split())) hh-=1 ww-=1 bmb[hh].append(ww) hb[hh]+=1 wb[ww]+=1 mhb=max(hb) mwb=max(wb) hmx=putmx(hb,mhb) wmx=putmx(wb,mwb) #print(hb,wb,hmx,wmx) fl=False for i in hmx: for j in wmx: if not j in bmb[i]: print((mhb+mwb)) fl=True break if fl: break else: print((mhb+mwb-1))
#import random def putmx(lis,mx): ret=[] for (i,j) in zip(list(range(len(lis))),lis): if j==mx: ret.append(i) return ret h,w,m=list(map(int,input().split())) hb=[0]*h wb=[0]*w bmb=[] for i in range(h): bmb.append({-1}) for i in range(m): hh,ww=list(map(int,input().split())) hh-=1 ww-=1 bmb[hh].add(ww) hb[hh]+=1 wb[ww]+=1 mhb=max(hb) mwb=max(wb) hmx=putmx(hb,mhb) wmx=set(putmx(wb,mwb)) #print(hb,wb,hmx,wmx) fl=False for i in hmx: if wmx|bmb[i]!=bmb[i]: print((mhb+mwb)) break else: print((mhb+mwb-1)) #print(hmx,wmx,bmb)
p02580
import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(readline()) def ints(): return list(map(int, readline().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, readline().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b HH, WW, M = ints() H, W = read_col(M) def flatten(i, j): return i * WW + j def reshape(x): return x // WW, x % WW H = mina(*H) W = mina(*W) H_cnt = Counter(H) W_cnt = Counter(W) # 爆弾がある座標に関しては-1,それ以外はそのまま # 爆弾のある座標の具体的な爆破数を持っていれば良い def default_num(x): i, j = reshape(x) return H_cnt[i], W_cnt[j] n_bomb = defaultdict(lambda: 0) ma = -1 for h, w in zip(H, W): n_bomb[flatten(h, w)] = H_cnt[h] + W_cnt[w] - 1 ma = max(ma, H_cnt[h] + W_cnt[w] - 1) # 縦横大きい方から見てく H_rank = H_cnt.most_common() W_rank = W_cnt.most_common() # print(H_rank, W_rank) for i, h_cnt in H_rank: for j, w_cnt in W_rank: if h_cnt + w_cnt < ma: break # どうあがいてもこれ以上大きくするのは無理 n = n_bomb[flatten(i, j)] if n == 0: n = h_cnt + w_cnt ma = max(ma, n) print(ma)
import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(readline()) def ints(): return list(map(int, readline().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, readline().split()))) return ret def read_matrix(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(list(map(int, readline().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b HH, WW, M = ints() H, W = read_col(M) def flatten(i, j): return i * WW + j def reshape(x): return x // WW, x % WW H = mina(*H) W = mina(*W) H_cnt = Counter(H) W_cnt = Counter(W) # 爆弾がある座標に関しては-1,それ以外はそのまま # 爆弾のある座標の具体的な爆破数を持っていれば良い n_bomb = defaultdict(lambda: 0) ma = -1 for h, w in zip(H, W): n_bomb[flatten(h, w)] = H_cnt[h] + W_cnt[w] - 1 ma = max(ma, H_cnt[h] + W_cnt[w] - 1) # 縦横大きい方から見てく H_rank = H_cnt.most_common() W_rank = W_cnt.most_common() # print(H_rank, W_rank) for i, h_cnt in H_rank: for j, w_cnt in W_rank: if h_cnt + w_cnt <= ma: break # どうあがいてもこれ以上大きくするのは無理 n = n_bomb[flatten(i, j)] if n == 0: n = h_cnt + w_cnt ma = max(ma, n) print(ma)
p02580
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline h, w, m = list(map(int, input().split())) cnt_h = [0] * h cnt_w = [0] * w bomb = [[False] * w for _ in range(h)] for _ in range(m): y, x = [int(x) - 1 for x in input().split()] cnt_h[y] += 1 cnt_w[x] += 1 bomb[y][x] = 1 kouho_h = [] kouho_w = [] max_h = max(cnt_h) max_w = max(cnt_w) for i in range(h): if cnt_h[i] == max_h: kouho_h.append(i) for i in range(w): if cnt_w[i] == max_w: kouho_w.append(i) for i in kouho_h: for j in kouho_w: if bomb[i][j] == False: print((max_h + max_w)) exit() print((max_h + max_w - 1)) if __name__ == '__main__': main()
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline h, w, m = list(map(int, input().split())) cnt_h = [0] * h cnt_w = [0] * w bomb = set() for _ in range(m): y, x = [int(x) - 1 for x in input().split()] cnt_h[y] += 1 cnt_w[x] += 1 bomb.add((y, x)) kouho_h = [] kouho_w = [] max_h = max(cnt_h) max_w = max(cnt_w) for i in range(h): if cnt_h[i] == max_h: kouho_h.append(i) for i in range(w): if cnt_w[i] == max_w: kouho_w.append(i) for i in kouho_h: for j in kouho_w: if (i, j) not in bomb: print((max_h + max_w)) exit() print((max_h + max_w - 1)) if __name__ == '__main__': main()
p02580
import sys input = sys.stdin.buffer.readline def main(): H, W, M = list(map(int, input().split())) #HW = [0]*m HC = [0]*H WC = [0]*W A = [0]*M for i in range(M): h, w = list(map(int, input().split())) h, w = h-1, w-1 #HW[i] = (h, w) HC[h] += 1 WC[w] += 1 A[i] = (h, w) from collections import Counter hct = Counter(HC) wct = Counter(WC) hct = list(hct.items()) wct = list(wct.items()) hct.sort(reverse=True) wct.sort(reverse=True) #print(hct) #print(wct) temph = hct[0][0] tempw= wct[0][0] tempa = temph+tempw cnthw = hct[0][1]*wct[0][1] cnt = 0 for h, w in A: if HC[h]+WC[w] ==tempa: cnt += 1 #print(cnt, cnthw) if cnt < cnthw: print(tempa) else: print((tempa-1)) if __name__ == '__main__': main()
import sys import io, os #input = sys.stdin.buffer.readline input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline h, w, m = list(map(int, input().split())) R = [0]*h C = [0]*w YX = [] for i in range(m): y, x = list(map(int, input().split())) y, x = y-1, x-1 R[y] +=1 C[x] +=1 YX.append((y, x)) max_r = max(R) max_c = max(C) cr = 0 cc = 0 for i in range(h): if R[i] == max_r: cr += 1 for i in range(w): if C[i] == max_c: cc +=1 c = 0 for y, x in YX: if R[y] == max_r and C[x] == max_c: c += 1 if c < cr*cc: print((max_r+max_c)) else: print((max_r+max_c-1))
p02580
import sys H, W, M = list(map(int,input().split())) R = [0] * H C = [0] * W S = set() for _ in range(M): h, w = list(map(int,input().split())) S.add((h-1, w-1)) R[h-1] += 1 C[w-1] += 1 r = max(R) c = max(C) HL = [i for i in range(H) if R[i] == r] WL = [i for i in range(W) if C[i] == c] for h in HL: for w in WL: if not (h, w) in S: print((r + c)) sys.exit() print((r + c - 1))
H, W, M = list(map(int,input().split())) R = [0] * H C = [0] * W L = [] for _ in range(M): h, w = list(map(int,input().split())) R[h-1] += 1 C[w-1] += 1 L.append([h-1, w-1]) r = max(R) c = max(C) print((r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))))
p02580
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print(('\n'.join(map(str,x)))) def printline(x):print((' '.join(map(str,x)))) import bisect from operator import itemgetter h,w,m = readints() r = [0]*h c = [0]*w p = [readints() for i in range(m)] p.sort(key=itemgetter(1)) d = [[] for i in range(h)] for i in range(m): a,b = (x-1 for x in p[i]) r[a] += 1 c[b] += 1 d[a].append(b) mr = max(r) mc = max(c) R = [i for i,x in enumerate(r) if x==mr] C = [i for i,x in enumerate(c) if x==mc] flag = 1 if len(R)*len(C)>m: flag = 0 else: for x in R: for y in C: z = bisect.bisect_left(d[x],y) if z>=len(d[x]): flag = 0 break else: if y != d[x][z]: flag = 0 break print((max(r)+max(c)-flag))
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print(('\n'.join(map(str,x)))) def printline(x):print((' '.join(map(str,x)))) h,w,m = readints() r = [0]*h c = [0]*w d = [set() for i in range(h)] for i in range(m): a,b = (x-1 for x in readints()) r[a] += 1 c[b] += 1 d[a].add(b) mr = max(r) mc = max(c) R = [i for i,x in enumerate(r) if x==mr] C = [i for i,x in enumerate(c) if x==mc] flag = 1 if len(R)*len(C)>m: flag = 0 else: for x in R: for y in C: if y not in d[x]: flag = 0 break print((max(r)+max(c)-flag))
p02580
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) h, w, m = LI() bomb = defaultdict(lambda : 0) cnt_h = [0] * h cnt_w = [0] * w for _ in range(m): H, W = LI() bomb[(H-1, W-1)] = 1 cnt_h[H-1] += 1 cnt_w[W-1] += 1 m_h = max(cnt_h) m_w = max(cnt_w) H_l = [] W_l = [] for i in range(h): if cnt_h[i] == m_h: H_l.append(i) for i in range(w): if cnt_w[i] == m_w: W_l.append(i) ans = m_h + m_w flag = False for i in H_l: for j in W_l: if not bomb[(i, j)]: flag = True if flag: print(ans) else: print((ans-1))
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) h, w, m = LI() bomb = defaultdict(lambda : 0) cnt_h = [0] * h cnt_w = [0] * w for _ in range(m): H, W = LI() bomb[(H-1, W-1)] = 1 cnt_h[H-1] += 1 cnt_w[W-1] += 1 m_h = max(cnt_h) m_w = max(cnt_w) H_l = [] W_l = [] for i in range(h): if cnt_h[i] == m_h: H_l.append(i) for i in range(w): if cnt_w[i] == m_w: W_l.append(i) ans = m_h + m_w for i in H_l: for j in W_l: if not bomb[(i, j)]: print(ans) quit() print((ans-1))
p02580
import sys from collections import Counter H,W,m = list(map(int,input().split())) h_ls = [0] * H w_ls = [0] * W bombers = [[0,0] for _ in range(m)] for i in range(m): h,w = list(map(int,input().split())) h_ls[h-1] += 1 w_ls[w-1] += 1 bombers[i] = [h-1,w-1] h_max = max(h_ls) h_counter = Counter(h_ls) # Couter使ってみる h_max_args = [0]*h_counter[h_max] next_ind = 0 for i in range(H): if h_ls[i] == h_max: h_max_args[next_ind] = i next_ind += 1 w_max = max(w_ls) w_counter = Counter(w_ls) w_max_args = [0]*w_counter[w_max] next_ind = 0 for i in range(W): if w_ls[i] == w_max: w_max_args[next_ind] = i next_ind += 1 for h in h_max_args: for w in w_max_args: if not [h,w] in bombers: print((w_max+h_max)) sys.exit() print((w_max+h_max-1))
import sys from collections import Counter H,W,m = list(map(int,input().split())) h_ls = [0] * H w_ls = [0] * W bombers = [(0,0) for _ in range(m)] for i in range(m): h,w = list(map(int,input().split())) h_ls[h-1] += 1 w_ls[w-1] += 1 bombers[i] = (h-1,w-1) h_max = max(h_ls) h_counter = Counter(h_ls) # Couter使ってみる h_max_args = [0]*h_counter[h_max] next_ind = 0 for i in range(H): if h_ls[i] == h_max: h_max_args[next_ind] = i next_ind += 1 w_max = max(w_ls) w_counter = Counter(w_ls) w_max_args = [0]*w_counter[w_max] next_ind = 0 for i in range(W): if w_ls[i] == w_max: w_max_args[next_ind] = i next_ind += 1 bombers = set(bombers) for h in h_max_args: for w in w_max_args: if not (h,w) in bombers: print((w_max+h_max)) sys.exit() print((w_max+h_max-1))
p02580
import sys input = sys.stdin.readline def segfunc(x,y): return max(x,y) class SegmentTree(object): def __init__(self, A, dot, unit): n = 1 << (len(A) - 1).bit_length() tree = [unit] * (2 * n) for i, v in enumerate(A): tree[i + n] = v for i in range(n - 1, 0, -1): tree[i] = dot(tree[i << 1], tree[i << 1 | 1]) self._n = n self._tree = tree self._dot = dot self._unit = unit def __getitem__(self, i): return self._tree[i + self._n] def update(self, i, v): i += self._n self._tree[i] = v while i != 1: i >>= 1 self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) def add(self, i, v): self.update(i, self[i] + v) def sum(self, l, r): #これで[l,r)から取り出す。 l += self._n r += self._n l_val = r_val = self._unit while l < r: if l & 1: l_val = self._dot(l_val, self._tree[l]) l += 1 if r & 1: r -= 1 r_val = self._dot(self._tree[r], r_val) l >>= 1 r >>= 1 return self._dot(l_val, r_val) INF = float("inf") H,W,M = list(map(int,input().split())) A = [0 for _ in range(H)] B = [0 for _ in range(W)] Treeh = SegmentTree(A,segfunc,-INF) Treew = SegmentTree(B,segfunc,-INF) G = [[False]*W for _ in range(H)] for i in range(M): h,w = list(map(int,input().split())) h-=1;w-=1 G[h][w] = True Treeh.add(h,1) Treew.add(w,1) X = Treeh.sum(0,H) Y = Treew.sum(0,W) MaxX_L = [] for i in range(H): #print(Treeh.__getitem__(i)) if Treeh.__getitem__(i) == X: MaxX_L.append(i) MaxY_L = [] for i in range(W): #print(Treeh.__getitem__(i)) if Treew.__getitem__(i) == Y: MaxY_L.append(i) ans = X+Y for x in MaxX_L: for y in MaxY_L: if not G[x][y]: print(ans) exit() ans -= 1 print(ans)
H,W,M = list(map(int,input().split())) Bomb = [] H_num = [0 for _ in range(H)] W_num = [0 for _ in range(W)] for i in range(M): a,b = list(map(int,input().split())) a-=1;b-=1 Bomb.append([a,b]) H_num[a] += 1 W_num[b] += 1 HMAX = max(H_num);WMAX = max(W_num) ans = HMAX+WMAX HMAX_list = set([]); WMAX_list = set([]) for i in range(H): if H_num[i] == HMAX: HMAX_list.add(i) for i in range(W): if W_num[i] == WMAX: WMAX_list.add(i) kosu = len(HMAX_list)*len(WMAX_list) cnt = 0 for z in Bomb: x = z[0];y = z[1] if x in HMAX_list and y in WMAX_list: cnt += 1 #print(kosu,cnt) if cnt < kosu: print(ans) else: print((ans-1))
p02580
from collections import defaultdict h, w, m = list(map(int, input().split())) cnt_h = [0] * h cnt_w = [0] * w dic = defaultdict(int) for _ in range(m): h_m, w_m = list(map(int, input().split())) cnt_h[h_m - 1] += 1 cnt_w[w_m - 1] += 1 dic[h_m - 1, w_m - 1] += 1 max_h = max(cnt_h) max_w = max(cnt_w) mh = [] mw = [] for i in range(h): if max_h == cnt_h[i]: mh.append(i) for i in range(w): if max_w == cnt_w[i]: mw.append(i) flag = False for i in mh: for j in mw: if dic[i, j] == 0: flag = True if flag: print((max_h + max_w)) else: print((max_h + max_w - 1))
from collections import defaultdict h, w, m = list(map(int, input().split())) cnt_h = [0] * h cnt_w = [0] * w dic = defaultdict(int) for _ in range(m): h_m, w_m = list(map(int, input().split())) cnt_h[h_m - 1] += 1 cnt_w[w_m - 1] += 1 dic[(h_m - 1, w_m - 1)] += 1 max_h = max(cnt_h) max_w = max(cnt_w) mh = [] mw = [] for i in range(h): if max_h == cnt_h[i]: mh.append(i) for i in range(w): if max_w == cnt_w[i]: mw.append(i) for i in mh: for j in mw: if dic[(i, j)] == 0: print((max_h + max_w)) quit() print((max_h + max_w - 1))
p02580
import sys import random H,W,M=list(map(int,input().split())) hlist=[0]*H wlist=[0]*W hwset=set() for _ in range(M): h,w=list(map(int,input().split())) hlist[h-1]+=1 wlist[w-1]+=1 hwset.add((h-1,w-1)) hmax=max(hlist) wmax=max(wlist) hlist2=[] for i in range(H): if hlist[i]==hmax: hlist2.append(i) hlist2.sort(reverse=True) random.shuffle(hlist2) wlist2=[] for i in range(W): if wlist[i]==wmax: wlist2.append(i) wlist2.sort(reverse=True) random.shuffle(wlist2) #print(hlist2,wlist2) H2=len(hlist2) W2=len(wlist2) if H2*W2>=10**7: norm=(H2*W2)//(10**7) H2=int(H2/(norm**0.5)) W2=int(W2/(norm**0.5)) for i in range(H2): ii=hlist2[i] for j in range(W2): jj=wlist2[j] if not (ii,jj) in hwset: print((hmax+wmax)) sys.exit(0) else: print((hmax+wmax-1))
import sys H,W,M=list(map(int,input().split())) hlist=[0]*H wlist=[0]*W hwset=set() for _ in range(M): h,w=list(map(int,input().split())) hlist[h-1]+=1 wlist[w-1]+=1 hwset.add((h-1,w-1)) hmax=max(hlist) hlist2=[] for i in range(H): if hlist[i]==hmax: hlist2.append(i) wmax=max(wlist) wlist2=[] for i in range(W): if wlist[i]==wmax: wlist2.append(i) #print(hlist2,wlist2) H2=len(hlist2) W2=len(wlist2) if H2*W2>M: print((hmax+wmax)) else: for i in range(H2): ii=hlist2[i] for j in range(W2): jj=wlist2[j] if not (ii,jj) in hwset: print((hmax+wmax)) sys.exit(0) else: print((hmax+wmax-1))
p02580
import collections H,W,M=list(map(int,input().split())) h=[None]*M w=[None]*M for i in range(M): h[i],w[i]=list(map(int,input().split())) c1=collections.Counter(h) c2=collections.Counter(w) cnt=0 ans=0 for i in range(min(len(c1),20)): for j in range(min(len(c2),20)): for x in range(M): flag=True if h[x]==c1.most_common()[i][0] and w[x]==c2.most_common()[j][0]: ans=max(ans,c1.most_common()[i][1]+c2.most_common()[j][1]-1) flag=False break if flag: ans=max(ans,c1.most_common()[i][1]+c2.most_common()[j][1]) print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines H, W, M = list(map(int, readline().split())) bomb = [tuple([int(x) - 1 for x in s.split()]) for s in readlines()] X = [0] * H Y = [0] * W for h, w in bomb: X[h] += 1 Y[w] += 1 maxX = max(X) maxY = max(Y) R = [h for h, x in enumerate(X) if x == maxX] C = [w for w, y in enumerate(Y) if y == maxY] bomb = set(bomb) for r in R: for c in C: if (r, c) not in bomb: print((maxX + maxY)) exit() print((maxX + maxY - 1))
p02580
H, W, M = list(map(int, input().split())) hws = [list([int(x)-1 for x in input().split()]) for _ in range(M)] booms = [set() for _ in range(H)] yoko = [0 for _ in range(W)] tate = [0 for _ in range(H)] for hw in hws: tate[hw[0]] += 1 yoko[hw[1]] += 1 booms[hw[0]].add(hw[1]) max_tate = max(tate) max_yoko = max(yoko) tate_candidates = [] yoko_candidates = [] for i in range(H): if tate[i] == max_tate: tate_candidates.append(i) for i in range(W): if yoko[i] == max_yoko: yoko_candidates.append(i) exist = 0 for tate_candidate in tate_candidates: for yoko_candidate in yoko_candidates: if yoko_candidate not in booms[tate_candidate]: exist = 1 print((max_tate + max_yoko + (exist-1)))
H, W, M = list(map(int, input().split())) hws = [list([int(x)-1 for x in input().split()]) for _ in range(M)] booms = [set() for _ in range(H)] yoko = [0 for _ in range(W)] tate = [0 for _ in range(H)] for hw in hws: tate[hw[0]] += 1 yoko[hw[1]] += 1 booms[hw[0]].add(hw[1]) max_tate = max(tate) max_yoko = max(yoko) tate_candidates = [] yoko_candidates = [] for i in range(H): if tate[i] == max_tate: tate_candidates.append(i) for i in range(W): if yoko[i] == max_yoko: yoko_candidates.append(i) exist = 0 for tate_candidate in tate_candidates: for yoko_candidate in yoko_candidates: if yoko_candidate not in booms[tate_candidate]: exist = 1 break else: continue break print((max_tate + max_yoko + (exist-1)))
p02580
h, w, m = list(map(int, input().split())) target_points = {tuple([int(x) - 1 for x in input().split()]) for _ in range(m)} row_points = [0] * h col_points = [0] * w for row, col in target_points: row_points[row] += 1 col_points[col] += 1 row_max = max(row_points) col_max = max(col_points) row_max_indexes = [i for i in range(h) if row_points[i] == row_max] col_max_indexes = [i for i in range(w) if col_points[i] == col_max] crossing_points = {(row, col) for row in row_max_indexes for col in col_max_indexes} print((row_max + col_max - (not (crossing_points - target_points))))
h, w, m = list(map(int, input().split())) target_points = {tuple([int(x) - 1 for x in input().split()]) for _ in range(m)} row_points = [0] * h col_points = [0] * w for row, col in target_points: row_points[row] += 1 col_points[col] += 1 row_max = max(row_points) col_max = max(col_points) row_max_indexes = [i for i in range(h) if row_points[i] == row_max] col_max_indexes = [i for i in range(w) if col_points[i] == col_max] empty_crossing_exist = False for row in row_max_indexes: for col in col_max_indexes: if (row, col) not in target_points: empty_crossing_exist = True break if empty_crossing_exist: break print((row_max + col_max - (not empty_crossing_exist)))
p02580
h,w,m = list(map(int,input().split())) hli = [0]*h wli = [0]*w li = [] for i in range(m): a,b = list(map(int,input().split())) li.append([a,b]) hli[a-1] += 1 wli[b-1] += 1 a = max(hli) b = max(wli) hli2 = [] wli2 = [] for i in range(h): if hli[i] == a: hli2.append(i+1) for i in range(w): if wli[i] == b: wli2.append(i+1) for i in hli2: for j in wli2: if [i,j] not in li: print((a + b)) exit() print((a + b - 1))
h,w,m = list(map(int,input().split())) hli = [0]*h wli = [0]*w li = [] liset = set() for i in range(m): a,b = list(map(int,input().split())) li.append([a,b]) liset.add((a,b)) hli[a-1] += 1 wli[b-1] += 1 a = max(hli) b = max(wli) hli2 = [] wli2 = [] for i in range(h): if hli[i] == a: hli2.append(i+1) for i in range(w): if wli[i] == b: wli2.append(i+1) for i in hli2: for j in wli2: if (i,j) not in liset: print((a + b)) exit() print((a + b - 1))
p02580
h,w,m=list(map(int,input().split())) H=[0]*(3*10**5+1) W=[0]*(3*10**5+1) M=[] for i in range(m): h,w=list(map(int,input().split())) M.append([h,w]) H[h]+=1 W[w]+=1 p=max(H) q=max(W) X=set([i for i in range(3*10**5+1) if H[i]==p]) Y=set([i for i in range(3*10**5+1) if W[i]==q]) Z=[[M[i][0],M[i][1]] for i in range(m) if M[i][0] in X or M[i][1] in Y ] cnt=1 flag=True for x in X: if flag: for y in Y: if not [x,y] in Z: cnt=0 flag=False break print((p+q-cnt))
h,w,m=list(map(int,input().split())) H=[0]*(3*10**5+1) W=[0]*(3*10**5+1) M=[] for i in range(m): h,w=list(map(int,input().split())) M.append([h,w]) H[h]+=1 W[w]+=1 p=max(H) q=max(W) X=set([i for i in range(3*10**5+1) if H[i]==p]) Y=set([i for i in range(3*10**5+1) if W[i]==q]) cnt=0 for i in range(m): if M[i][0] in X and M[i][1] in Y: cnt+=1 if cnt==len(X)*len(Y): print((p+q-1)) else: print((p+q))
p02580
from collections import defaultdict H,W,M=list(map(int,input().split())) AB=[tuple(map(int,input().split()))for i in range(M)] AB=[(a-1,b-1)for a,b in AB] st=set(AB) Wc=defaultdict(lambda :0) Hc=defaultdict(lambda :0) for a,b in AB: Hc[a]+=1 Wc[b]+=1 Hm=max(Hc.values()) hhh=list(Hc.keys()) www=list(Wc.keys()) for i in hhh: if Hc[i]!=Hm: Hc.pop(i) Wm=max(Wc.values()) for j in www: if Wc[j]!=Wm: Wc.pop(j) ans=0 count=0 for i in list(Hc.keys()): for j in list(Wc.keys()): add = -1 if (i,j) in st else 0 tmp= Hc[i] + Wc[j] + add ans=max(ans,tmp) if count>300000: break count+=1 print(ans)
H,W,M=list(map(int,input().split())) HW=[tuple(map(int,input().split()))for i in range(M)] HW=[(h-1,w-1)for h,w in HW] st=set(HW) countH=[0]*H countW=[0]*W for h,w in HW: countH[h]+=1 countW[w]+=1 maxH=max(countH) maxW=max(countW) candiH=[] candiW=[] for i in range(H): if maxH==countH[i]: candiH.append(i) for i in range(W): if maxW==countW[i]: candiW.append(i) count=0 ans=maxH+maxW-1 add=0 for i in candiH: for j in candiW: if (i,j) not in st: add=1 if count>300000: break count+=1 print((ans+add))
p02580
from collections import defaultdict as ddict H,W,M=list(map(int,input().split())) tgts=set() for _ in range(M): i,j=list(map(int,input().split())) tgts.add((i,j)) rows=ddict(int) cols=ddict(int) ii=jj=0 ia,ja=[],[] for i,j in tgts: rows[i]+=1 cols[j]+=1 x=rows[i] if x>ii: ii=x ia=[i] elif x==ii: ia.append(i) y=cols[j] if y>jj: jj=y ja=[j] elif y==jj: ja.append(j) ans=0 for i in ia: for j in ja: k=rows[i]+cols[j] if (i,j) in tgts: k-=1 ans=max(ans,k) print(ans)
from collections import defaultdict as ddict ii=jj=0 ia,ja=[],[] rows=ddict(int) cols=ddict(int) H,W,M=list(map(int,input().split())) tgts=set() for _ in range(M): i,j=list(map(int,input().split())) tgts.add((i,j)) rows[i]+=1 cols[j]+=1 x=rows[i] if x>ii: ii=x ia=[i] elif x==ii: ia.append(i) y=cols[j] if y>jj: jj=y ja=[j] elif y==jj: ja.append(j) ans=0 for i in ia: for j in ja: k=rows[i]+cols[j] if (i,j) in tgts: k-=1 else: ans=k break ans=max(ans,k) print(ans)
p02580
from collections import defaultdict as ddict h,w,m=list(map(int,input().split())) xs=[0]*w ys=[0]*h xsmx=ysmx=0 pts=set() for _ in range(m): y,x=list(map(int,input().split())) x,y=x-1,y-1 xs[x]+=1 ys[y]+=1 pts.add((x,y)) xsmx=max(xsmx,xs[x]) ysmx=max(ysmx,ys[y]) xsc=[x for x in range(w) if xs[x]==xsmx] ysc=[y for y in range(h) if ys[y]==ysmx] ans=xsmx+ysmx-1 ok=False for y in ysc: for x in xsc: if (x,y) not in pts: ans+=1 ok=True break if ok: break print(ans)
h,w,m=list(map(int,input().split())) xsct=[0]*w ysct=[0]*h ips=set() xsmx=ysmx=0 for _ in range(m): y,x=list(map(int,input().split())) x,y=x-1,y-1 xsct[x]+=1 ysct[y]+=1 ips.add((x,y)) xsmx=max(xsmx,xsct[x]) ysmx=max(ysmx,ysct[y]) xs=[x for x in range(w) if xsct[x]==xsmx] ys=[y for y in range(h) if ysct[y]==ysmx] ans=xsmx+ysmx-1 ok=False for y in ys: for x in xs: if (x,y) not in ips: ans+=1 ok=True break if ok: break print(ans)
p02580
h,w,m=list(map(int,input().split())) cx=[0]*w cy=[0]*h xy=set() for _ in range(m): y,x=list(map(int,input().split())) x,y=x-1,y-1 cx[x]+=1 cy[y]+=1 xy.add((x,y)) xmx=max(cx) ymx=max(cy) xs=[x for x in range(w) if cx[x]==xmx] ys=[y for y in range(h) if cy[y]==ymx] ans=xmx+ymx-1 ok=False for y in ys: for x in xs: if (x,y) not in xy: ans+=1 ok=True break if ok: break print(ans)
h,w,m=list(map(int,input().split())) r=[0]*h c=[0]*w s=set() for _ in range(m): i,j=list(map(int,input().split())) i-=1 j-=1 r[i]+=1 c[j]+=1 s.add(i*w+j) rmx=max(r) cmx=max(c) rc=[i for i in range(h) if r[i]==rmx] cc=[j for j in range(w) if c[j]==cmx] ans=rmx+cmx-1 ok=False for i in rc: for j in cc: if i*w+j not in s: ans+=1 ok=True break if ok: break print(ans)
p02580
h,w,m=list(map(int,input().split())) r=[0]*h c=[0]*w s=set() for _ in range(m): i,j=list(map(int,input().split())) i-=1 j-=1 r[i]+=1 c[j]+=1 s.add(i*w+j) rmx=max(r) cmx=max(c) rc=[i for i in range(h) if r[i]==rmx] cc=[j for j in range(w) if c[j]==cmx] ans=rmx+cmx-1 ok=False for i in rc: for j in cc: if i*w+j not in s: ans+=1 ok=True break if ok: break print(ans)
h,w,m=list(map(int,input().split())) r=[0]*h c=[0]*w s=set() for _ in range(m): i,j=list(map(int,input().split())) i-=1 j-=1 r[i]+=1 c[j]+=1 s.add(i*w+j) rmx=max(r) cmx=max(c) rc=[i for i in range(h) if r[i]==rmx] cc=[j for j in range(w) if c[j]==cmx] ans=rmx+cmx-1 for i in rc: for j in cc: if i*w+j not in s: print((ans+1)) exit() print(ans)
p02580
from collections import deque def argmax_poss(a): if len(a) == 0: return [] all_ = [0] max_ = a[0] for i in range(1, len(a)): if a[i] > max_: all_ = [i] max_ = a[i] elif a[i] == max_: all_.append(i) return all_ h,w,m = list(map(int,input().split())) Ms = [] h_scores = [0 for i in range(h)] w_scores = [0 for i in range(w)] record = deque([]) for i in range(m): h,w = list(map(int,input().split())) record.append((h-1,w-1)) h_scores[h-1] += 1 w_scores[w-1] += 1 max_h_poss = argmax_poss(h_scores) max_w_poss = argmax_poss(w_scores) out_pos_count = 0 is_ok = False for h in max_h_poss: for w in max_w_poss: if (h,w) not in record: is_ok = True break if is_ok: print((max(h_scores) + max(w_scores))) else: print((max(h_scores) + max(w_scores)-1))
from collections import deque def argmax_poss(a): if len(a) == 0: return [] all_ = [0] max_ = a[0] for i in range(1, len(a)): if a[i] > max_: all_ = [i] max_ = a[i] elif a[i] == max_: all_.append(i) return all_ h,w,m = list(map(int,input().split())) Ms = [] h_scores = [0 for i in range(h)] w_scores = [0 for i in range(w)] record = set() for i in range(m): h,w = list(map(int,input().split())) record.add((h-1,w-1)) h_scores[h-1] += 1 w_scores[w-1] += 1 max_h_poss = argmax_poss(h_scores) max_w_poss = argmax_poss(w_scores) out_pos_count = 0 is_ok = False for h in max_h_poss: for w in max_w_poss: if (h,w) not in record: is_ok = True break if is_ok: print((max(h_scores) + max(w_scores))) else: print((max(h_scores) + max(w_scores)-1))
p02580
import itertools H, W, M = list(map(int, input().split())) Bh = [0]*(H+1) Bw = [0]*(W+1) OD = set() for _ in range(M): h, w = list(map(int, input().split())) Bh[h] += 1 Bw[w] += 1 OD.add((h, w)) l1 = [i for i, x in enumerate(Bh) if x == max(Bh)] l2 = [j for j, x in enumerate(Bw) if x == max(Bw)] for i, j in itertools.product(l1, l2): if (i, j) not in OD: break else: print((max(Bh)+max(Bw)-1)) exit() print((max(Bh)+max(Bw)))
import itertools H, W, M = list(map(int, input().split())) Bh = [0]*(H+1) Bw = [0]*(W+1) OD = set() for _ in range(M): h, w = list(map(int, input().split())) Bh[h] += 1 Bw[w] += 1 OD.add((h, w)) M1 = max(Bh) M2 = max(Bw) l1 = [i for i, x in enumerate(Bh) if x == M1] l2 = [j for j, x in enumerate(Bw) if x == M2] for i, j in itertools.product(l1, l2): if (i, j) not in OD: break else: print((M1+M2-1)) exit() print((M1+M2))
p02580
from collections import defaultdict H,W,M = list(map(int,input().split())) bomb = [[0,0] for _ in range(M)] bomb_d = defaultdict(int) for i in range(M): bomb[i] = list(map(int,input().split())) bomb[i][0] -= 1 bomb[i][1] -= 1 bomb_d[tuple(bomb[i])] = 1 dh = [0]*H dw = [0]*W for i in range(M): dh[bomb[i][0]] += 1 dw[bomb[i][1]] += 1 Maxh = max(dh) Maxw = max(dw) h_p = [] w_p = [] for i in range(H): if dh[i] == Maxh: h_p.append(i) for i in range(W): if dw[i] == Maxw: w_p.append(i) f = 0 for h in h_p: for w in w_p: if bomb_d[(h,w)] != 1: f = 1 if f == 0: print((Maxh+Maxw-1)) else: print((Maxh+Maxw))
from collections import defaultdict H,W,M = list(map(int,input().split())) bomb = [[0,0] for _ in range(M)] bomb_d = defaultdict(int) for i in range(M): bomb[i] = list(map(int,input().split())) bomb[i][0] -= 1 bomb[i][1] -= 1 bomb_d[tuple(bomb[i])] = 1 dh = [0]*H dw = [0]*W for i in range(M): dh[bomb[i][0]] += 1 dw[bomb[i][1]] += 1 Maxh = max(dh) Maxw = max(dw) h_p = [] w_p = [] for i in range(H): if dh[i] == Maxh: h_p.append(i) for i in range(W): if dw[i] == Maxw: w_p.append(i) f = 0 for h in h_p: for w in w_p: if bomb_d[(h,w)] != 1: f = 1 break else: continue break if f == 0: print((Maxh+Maxw-1)) else: print((Maxh+Maxw))
p02580
# E - Bomber from collections import Counter h, w, m = list(map(int, input().split())) hw = [tuple(map(int, input().split())) for i in range(m)] ys, xs = list(zip(*hw)) ymax, = Counter(ys).most_common(1) xmax, = Counter(xs).most_common(1) bombed = max(ymax[1], xmax[1]) if bombed < m: if ymax[1] > xmax[1]: hw2 = [(a, b) for a, b in hw if a != ymax[0]] _, xs = list(zip(*hw2)) xmax, = Counter(xs).most_common(1) bombed += xmax[1] else: hw2 = [(a, b) for a, b in hw if b != xmax[0]] ys, _ = list(zip(*hw2)) ymax, = Counter(ys).most_common(1) bombed += ymax[1] print(bombed)
# E - Bomber from collections import Counter h, w, m = list(map(int, input().split())) hw = [tuple(map(int, input().split())) for i in range(m)] ys, xs = list(zip(*hw)) ymax, = Counter(ys).most_common(1) xmax, = Counter(xs).most_common(1) bombed = max(ymax[1], xmax[1]) if bombed < m: if ymax[1] > xmax[1]: xs = [b for a, b in hw if a != ymax[0]] xmax, = Counter(xs).most_common(1) bombed += xmax[1] else: ys = [a for a, b in hw if b != xmax[0]] ymax, = Counter(ys).most_common(1) bombed += ymax[1] print(bombed)
p02580
import random import time start=time.time() h,w,m=map(int,input().split()) hh=[[0,i]for i in range(h)] ww=[[0,i]for i in range(w)] hw=set() for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 hh[a][0]+=1 ww[b][0]+=1 hw.add((a,b)) ww.sort(reverse=1) s=ww[0][0] w=[] for x,j in ww: if x==s:w.append(j) hh.sort(reverse=1) t=hh[0][0] hhh=[] for x,i in hh: if x==t:hhh.append((x,i)) ans=[] random.shuffle(w) for j in w: for x,i in hhh: if (i,j) in hw: ans.append(s+x-1) else: exit(print(s+x)) if time.time()-start>=1.7: m=ans[0] if h-50000<=len(hhh)<=h-random.randint(10,100):m+=1 exit(print(m)) print(ans[0])
import random import time start=time.time() h,w,m=map(int,input().split()) hh=[[0,i]for i in range(h)] ww=[[0,i]for i in range(w)] hw=set() for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 hh[a][0]+=1 ww[b][0]+=1 hw.add((a,b)) ww.sort(reverse=1) s=ww[0][0] w=[] for x,j in ww: if x==s:w.append(j) hh.sort(reverse=1) t=hh[0][0] hhh=[] for x,i in hh: if x==t:hhh.append((x,i)) ans=[] random.shuffle(w) for j in w: for x,i in hhh: if (i,j) in hw: ans.append(s+x-1) else: exit(print(s+x)) if time.time()-start>=1.7: m=ans[0] if h-100000<=len(hhh)<=h-random.randint(100,1000):m+=1 exit(print(m)) print(ans[0])
p02580
h,w,m=map(int,input().split()) hh=[[0,i]for i in range(h)] ww=[[0,i]for i in range(w)] hw=set() for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 hh[a][0]+=1 ww[b][0]+=1 hw.add((a,b)) ww.sort(reverse=1) s=ww[0][0] w=[] for x,j in ww: if x==s:w.append(j) ans=0 t=max(hh)[0] for j in w: for x,i in sorted(hh,reverse=1): if x!=t:break if (i,j) in hw: ans=s+x-1 else: exit(print(s+x)) print(ans)
h,w,m=map(int,input().split()) hh=[[0,i]for i in range(h)] ww=[[0,i]for i in range(w)] hw=set() for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 hh[a][0]+=1 ww[b][0]+=1 hw.add((a,b)) ww.sort(reverse=1) s=ww[0][0] w=[] for x,j in ww: if x==s:w.append(j) hh.sort(reverse=1) ans=0 t=max(hh)[0] for j in w: for x,i in hh: if x!=t:break if (i,j) in hw: ans=s+x-1 else: exit(print(s+x)) print(ans)
p02580
h,w,m=map(int,input().split()) hh=[[0,i]for i in range(h)] ww=[[0,i]for i in range(w)] hw=set() for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 hh[a][0]+=1 ww[b][0]+=1 hw.add((a,b)) ww.sort(reverse=1) s=ww[0][0] w=[] for x,j in ww: if x==s:w.append(j) hh.sort(reverse=1) ans=0 t=max(hh)[0] for j in w: for x,i in hh: if x!=t:break if (i,j) in hw: ans=s+x-1 else: exit(print(s+x)) print(ans)
import sys input = lambda: sys.stdin.readline().rstrip() h, w, m = list(map(int, input().split())) hw = [] hcount = [0] * h wcount = [0] * w for _ in range(m): a, b = list(map(int, input().split())) a -= 1 b -= 1 hcount[a] += 1 wcount[b] += 1 hw.append([a, b]) hmax = max(hcount) wmax = max(wcount) x = hcount.count(hmax) * wcount.count(wmax) for a, b in hw: if hcount[a] == hmax and wcount[b] == wmax: x -= 1 if x == 0: print((hmax + wmax - 1)) else: print((hmax + wmax))
p02580
n,m,k=list(map(int,input().split())) r=[0]*(n+1) c=[0]*(m+1) l=[] for _ in range(k): a,b=list(map(int,input().split())) l.append([a,b]) r[a]+=1 c[b]+=1 m1=max(r) x=[] for i in range(n+1): if(r[i]==m1): x.append(i) m2=max(c) y=[] for i in range(m+1): if(c[i]==m2): y.append(i) ans=m1+m2 z=0 for i in x: for j in y: if([i,j] not in l): z=-1 break if(z==0): print((ans-1)) else: print(ans)
n,m,k=list(map(int,input().split())) m+=1 n+=1 r=[0]*(n) c=[0]*(m) d={} for _ in range(k): a,b=list(map(int,input().split())) d[(a,b)]=1 r[a]+=1 c[b]+=1 m1=max(r) x=[] for i in range(n): if(r[i]==m1): x.append(i) m2=max(c) y=[] for i in range(m): if(c[i]==m2): y.append(i) ans=m1+m2 z=0 for i in x: for j in y: if((i,j) not in d): z=-1 break if(z==0): print((ans-1)) else: print(ans)
p02580
H, W, M = list(map(int, input().split())) Hc = [0 for i in range(H)] Wc = [0 for i in range(W)] HW = [[0 for i in range(W)] for i in range(H)] for m in range(M): h, w = list(map(int, input().split())) Hc[h - 1] += 1 Wc[w - 1] += 1 HW[h - 1][w - 1] = 1 Hcmax = max(Hc) Hcmax_idx = [i for i, x in enumerate(Hc) if x == Hcmax] Wcmax = max(Wc) Wcmax_idx = [i for i, x in enumerate(Wc) if x == Wcmax] ans = Hcmax + Wcmax - 1 f = False for i in Hcmax_idx: for j in Wcmax_idx: if HW[i][j] == 0: ans = Hcmax + Wcmax f = True break if f: break print(ans)
H, W, M = list(map(int, input().split())) Hc = [0 for i in range(H)] Wc = [0 for i in range(W)] B = [] for m in range(M): h, w = list(map(int, input().split())) Hc[h - 1] += 1 Wc[w - 1] += 1 B.append((h - 1, w - 1)) Hcmax = max(Hc) Hcmax_idx = [i for i, x in enumerate(Hc) if x == Hcmax] Wcmax = max(Wc) Wcmax_idx = [i for i, x in enumerate(Wc) if x == Wcmax] ans = Hcmax + Wcmax - 1 B = set(B) f = False for i in Hcmax_idx: if f: break for j in Wcmax_idx: if (i, j) not in B: ans = Hcmax + Wcmax f = True break print(ans)
p02580
#!/usr/bin/env python3 from collections import deque h, w, m = list(map(int, input().split())) hw = [tuple(map(int, input().split())) for i in range(m)] hw.sort() hw_rev = sorted(hw, key=lambda x: x[1]) index_sum_h = [] sum_h = [] index = -1 for i in hw: a, b = i if a == index: index_sum_h[-1][1] += 1 else: index = a index_sum_h.append([a, 1]) index_sum_w = [] index = -1 for i in hw_rev: a, b = i if b == index: index_sum_w[-1][1] += 1 else: index = b index_sum_w.append([b, 1]) # print(hw) # print(index_sum_h) # print(index_sum_w) index_sum_h = sorted(index_sum_h, key=lambda x: x[1], reverse=True) index_sum_w = sorted(index_sum_w, key=lambda x: x[1], reverse=True) # print(index_sum_h) # print(index_sum_w) dq = deque([[0, 0]]) ans_tmp = index_sum_h[0][1]+index_sum_w[0][1] hw = set(hw) while len(dq) > 0: index_h, index_w = dq.popleft() a, b = index_sum_h[index_h] c, d = index_sum_w[index_w] # print([a, c]) # print([a, c] in hw) if (a, c) in hw: ans = ans_tmp-1 if index_h+1 < len(index_sum_h): if index_sum_h[index_h+1][1] == b: dq.append([index_h+1, index_w]) if index_w+1 < len(index_sum_w): if index_sum_w[index_w+1][1] == d: dq.append([index_h, index_w+1]) else: print((b+d)) exit() print(ans)
#!/usr/bin/env python3 from collections import Counter h, w, m = list(map(int, input().split())) H = [] W = [] for i in range(m): hh, ww = tuple(map(int, input().split())) H.append(hh) W.append(ww) h_m = Counter(H).most_common()[0] w_m = Counter(W).most_common()[0] ans_1 = h_m[1] ans_2 = w_m[1] # print(ans_1, ans_2) WW = [] HH = [] for i in range(m): if H[i] == h_m[0]: continue WW.append(W[i]) for i in range(m): if W[i] == w_m[0]: continue HH.append(H[i]) if WW: ans_1 += Counter(WW).most_common()[0][1] if HH: ans_2 += Counter(HH).most_common()[0][1] print((max(ans_1, ans_2))) # hw.sort() # hw_rev = sorted(hw, key=lambda x: x[1]) # index_sum_h = [] # sum_h = [] # index = -1 # for i in hw: # a, b = i # if a == index: # index_sum_h[-1][1] += 1 # else: # index = a # index_sum_h.append([a, 1]) # index_sum_w = [] # index = -1 # for i in hw_rev: # a, b = i # if b == index: # index_sum_w[-1][1] += 1 # else: # index = b # index_sum_w.append([b, 1]) # # print(hw) # # print(index_sum_h) # # print(index_sum_w) # index_sum_h = sorted(index_sum_h, key=lambda x: x[1], reverse=True) # index_sum_w = sorted(index_sum_w, key=lambda x: x[1], reverse=True) # # print(index_sum_h) # # print(index_sum_w) # dq = deque([[0, 0]]) # ans_tmp = index_sum_h[0][1]+index_sum_w[0][1] # hw = set(hw) # while len(dq) > 0: # index_h, index_w = dq.popleft() # a, b = index_sum_h[index_h] # c, d = index_sum_w[index_w] # # print([a, c]) # # print([a, c] in hw) # if (a, c) in hw: # ans = ans_tmp-1 # if index_h+1 < len(index_sum_h): # if index_sum_h[index_h+1][1] == b: # dq.append([index_h+1, index_w]) # if index_w+1 < len(index_sum_w): # if index_sum_w[index_w+1][1] == d: # dq.append([index_h, index_w+1]) # else: # print(b+d) # exit() # print(ans)
p02580