[白俊]1780号:紙の個数

6682 ワード

質問の表示

私はまたインデックスの間違いを犯した.
n = int(input())
arr = []
for _ in range(n):
    arr.append(list(map(int, input().split())))

ans = [0, 0, 0] #-1, 0, 1 종이의 개수
def solve(i, j, n):
    if n == 1:
        ans[arr[i][j]+1] += 1
        return
    first = arr[i][j]
    isUsable = True # 모두 같은 숫자면 종이를 쓸 수 있다
    for r in range(n):
        for c in range(n):
            if first != arr[i+r][j+c]:
                isUsable = False
                break
        if not isUsable:
            break
    if isUsable:
        ans[arr[i][j]+1] += 1
        return
    else:
        for r in range(3):
            for c in range(3):
                solve(i+n//3*r, j+n//3*c, n//3)
solve(0, 0, n)
for e in ans:
    print(e)
アテンションインデックス