結果

問題 No.2692 How Many Times Reached?
ユーザー NP
提出日時 2024-03-22 22:00:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2024-09-30 11:31:36
合計ジャッジ時間 4,322 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 15 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

def count_reaches(N, board):
    dx = [-1, -1, -1, 0, 0, 1, 1, 1]
    dy = [-1, 0, 1, -1, 1, -1, 0, 1]
    
    def is_valid(x, y):
        return 0 <= x < N and 0 <= y < N
    
    def check_direction(x, y, dx, dy):
        cnt_A, cnt_dot = 0, 0
        for i in range(N):
            nx, ny = x + i*dx, y + i*dy
            if not is_valid(nx, ny):
                return False
            if board[nx][ny] == 'A':
                cnt_A += 1
            elif board[nx][ny] == '.':
                cnt_dot += 1
        return cnt_A == N-1 and cnt_dot == 1
    
    cnt_reaches = 0
    for i in range(N):
        for j in range(N):
            if board[i][j] != 'A':
                continue
            for dir in range(8):
                cnt_reaches += check_direction(i, j, dx[dir], dy[dir])
    return cnt_reaches

N = int(input())

board = []
for _ in range(N):
    row = input().strip()
    board.append(row)

print(count_reaches(N, board))
0