250日目-BOJ no.2578


https://www.acmicpc.net/problem/2578

My Solution

import sys

pan = []
ann = []
check = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
for _ in range(5):
   pan.append(list(map(int, sys.stdin.readline().rstrip().split())))
for _ in range(5):
   ann.append(list(map(int, sys.stdin.readline().rstrip().split())))


cnt = 0
isbreak = False
for a1 in ann:
   for a2 in a1:
       for i in range(len(pan)):
           if a2 in pan[i]:
               check[i][pan[i].index(a2)] = 1
               cnt += 1
               bingo = 0
               for k in range(len(check)):
                   if sum(check[k]) == 5:
                       bingo += 1
                   if sum([k2[k] for k2 in check]) == 5:
                       bingo += 1
               temp = 0
               tot = 0
               while temp < 5:
                   tot += check[temp][len(check)-1-temp]
                   temp += 1
               if tot == 5:
                   bingo += 1
               temp = 0
               tot = 0
               while temp < 5:
                   tot += check[temp][temp]
                   temp += 1
               if tot == 5:
                   bingo += 1

               if bingo >= 3:
                   isbreak = True
                   break
       if isbreak is True:
           break
   if isbreak is True:
       break
print(cnt)