less than 1 minute read

SWEA 1979 어디에 단어가 들어갈 수 있을까

문제링크

파이썬

t = int(input())
for i in range(1,t+1):
    n, m = map(int,input().split())
    s = [list(map(int,input().split())) for _ in range(n)]
    res = 0
    for j in range(n):
        cnt =0
        for k in range(n):
            if s[j][k] == 1:
                cnt+=1
            if s[j][k] == 0 or k == n-1:
                if cnt ==m:
                    res +=1
                cnt = 0
        for k in range(n):
            if s[k][j] == 1:
                cnt+=1
            if s[k][j] == 0 or k == n-1:
                if cnt== m:
                    res+=1
                cnt = 0
                    
    print("#"+str(i), res)
    
    
            
                    

카테고리:

업데이트:

댓글남기기