황소개발자

백준 16924 파이썬 python : 십자가 찾기 @@황소처럼 우직하게@@ 코테에 잘나옴 은근 본문

백준 문제 풀이

백준 16924 파이썬 python : 십자가 찾기 @@황소처럼 우직하게@@ 코테에 잘나옴 은근

hjp845 2020. 4. 22. 02:19
반응형

채점하는데 오래걸려서 유튭보고 왓넹 

import sys
input = sys.stdin.readline

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

check = [[0 for i in range(w)] for j in range(h)]

mat = []
ans = [] # x, y, s

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def checks(y, x):
    for s in range(1, w):
        flag = True
        for i in range(4):
            ny = y + dy[i] * s
            nx = x + dx[i] * s
            if 0 <= nx < w and 0 <= ny < h and mat[ny][nx] == '*':
                pass
            else:
                # exit
                flag = False
                break
        if flag:
            ans.append([y + 1, x + 1, s])
            for i in range(4):
                ny = y + dy[i] * s
                nx = x + dx[i] * s
                check[ny][nx] = 0
            check[y][x] = 0
        else:
            break

for i in range(h):
    mat.append(input().strip())

for i in range(h):
    for j in range(w):
        if mat[i][j] == '*':
            check[i][j] = 1

for i in range(h):
    for j in range(w):
        if mat[i][j] == '*':
            checks(i, j)

total = 0
for i in range(h):
    for j in range(w):
        total += check[i][j]

if total == 0:
    print(len(ans))
    for ss in ans:
        print(*ss)
else:
    print(-1)
반응형
Comments