문제 확인하기
2. 정답 코드 (python3, memory: 31120KB, time: 40ms)
import sys
input_fn = sys.stdin.readline
bingo_card = [list(map(int, input_fn().split())) for _ in range(5)]
marked_numbers = []
for _ in range(5):
marked_numbers += list(map(int, input_fn().split()))
def check_bingo():
bingo_count = 0
for row in bingo_card:
if row.count(0) == 5:
bingo_count += 1
for col in range(5):
marked_count = 0
for row in range(5):
if bingo_card[row][col] == 0:
marked_count += 1
if marked_count == 5:
bingo_count += 1
left_diag = 0
for i in range(5):
if bingo_card[i][i] == 0:
left_diag += 1
if left_diag == 5:
bingo_count += 1
right_diag = 0
for i in range(5):
if bingo_card[i][4-i] == 0:
right_diag += 1
if right_diag == 5:
bingo_count += 1
return bingo_count
marked_count = 0
for i in range(25):
for x in range(5):
for y in range(5):
if marked_numbers[i] == bingo_card[x][y]:
bingo_card[x][y] = 0
marked_count += 1
if marked_count >= 12:
result = check_bingo()
if result >= 3:
print(i+1)
break