Löse ABC176 E in Python

Einführung

Ich werde E - Bomber ausführen, das ich gestern in ABC nicht lösen konnte.

E - Bomber Das Raster in einem zweidimensionalen Array zu halten ist umständlich und zeitaufwändig. Verwalten Sie daher die Anzahl der Bomben auf jeder der $ H- und W $ -Achsen. Wenn Sie die maximale Anzahl jeder Bombe auf den Achsen $ H und W $ auswählen und die Summe der Maximalwerte zurückgeben, scheint die Antwort korrekt zu sein, aber das reicht nicht aus. Dies liegt daran, dass es nicht möglich ist, den Fall zu behandeln, in dem sich an der Kreuzung eine Bombe befindet. Wenn sich an den Kreuzungen Bomben befinden, beträgt die Summe ihrer Höchstwerte -1.

Halten Sie die Schnittpunkte, indem Sie ein Tupel in das Diktat einfügen. 0 ist der Punkt, an dem es keine Bombe gibt, 1 ist der Punkt, an dem es eine Bombe gibt.

from collections import defaultdict

h, w, m = map(int, input().split())

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = 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 #Wenn es einen Punkt von 0 gibt, ist dies der Maximalwert. Brechen Sie ihn also ab.
            break
    if flag:
        break

if flag:
    print(max_h + max_w)
else:
    print(max_h + max_w - 1)

Recommended Posts

Löse ABC176 E in Python
Löse ABC169 mit Python
Löse ABC175 D in Python
Löse den Atcoder ABC169 A-D mit Python
Löse ABC036 A ~ C mit Python
Löse ABC037 A ~ C mit Python
Löse den Atcoder ABC176 (A, B, C, E) in Python
Löse ABC146-C mit Python
ABC 157 D - Lösungsvorschläge für Freunde in Python!
Löse ABC098-C in Python
Löse ABC159-D in Python
Ich wollte ABC159 mit Python lösen
Löse ABC165 A, B, D mit Python
Löse ABC160-E mit Python
AtCoder ABC 177 Python (A ~ E)
Löse AtCoder ABC166 mit Python
AtCoder ABC 178 Python (A ~ E)
Atcoder ABC164 A-C in Python
AtCoder ABC 176 Python (A ~ E)
Atcoder ABC167 A-D in Python
Löse Wooldridge-Übungen in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Lösen Sie Optimierungsprobleme mit Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D mit Python
Löse ABC163 A ~ C mit Python
Löse ABC166 A ~ D mit Python
ABC166 in Python A ~ C Problem
Löse ABC168 A ~ C mit Python
Löse ABC162 A ~ C mit Python
Vorlage AtCoder ABC 179 Python (A ~ E)
Löse ABC167 A ~ C mit Python
Löse ABC158 A ~ C mit Python
Lösen Sie normale Differentialgleichungen in Python
Anfänger ABC154 (Python)
Quadtree in Python --2
Python in der Optimierung
Anfänger ABC156 (Python)
Metaprogrammierung mit Python
Python 3.3 mit Anaconda
Geokodierung in Python
SendKeys in Python
Metaanalyse in Python
Unittest in Python
AtCoder ABC 174 Python
Algorithmus in Python (ABC 146 C Dichotomie
Epoche in Python
Zwietracht in Python
Ich wollte ABC160 mit Python lösen
Deutsch in Python
DCI in Python
Quicksort in Python
nCr in Python
N-Gramm in Python
So schreiben Sie offline in Echtzeit Lösen von E04-Problemen mit Python
Programmieren mit Python
Anfänger ABC155 (Python)