結果
問題 | No.179 塗り分け |
ユーザー |
![]() |
提出日時 | 2019-04-21 21:45:04 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 74 ms / 3,000 ms |
コード長 | 1,143 bytes |
コンパイル時間 | 119 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-23 14:58:59 |
合計ジャッジ時間 | 2,814 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 40 |
ソースコード
import itertools import copy h, w = map(int, input().split()) start_x, start_y = None, None field = [list(input()) for _ in range(h)] black_n = "".join(map("".join, field)).count("#") if black_n > 0 and black_n % 2: print("NO") exit() def check(y, x): global start_x, start_y if field[y][x] != "#": return False if start_x is None: start_x = x start_y = y dx, dy = x - start_x, y - start_y # m = copy.deepcopy(field) visited = [{} for _ in range(h)] for red_y in range(h): for red_x in range(w): if visited[red_y].get(red_x) is None and field[red_y][red_x] == "#": # m[red_y][red_x] = "@" visited[red_y][red_x] = True nx = red_x + dx ny = red_y + dy if ny >= h or nx >= w or field[ny][nx] != "#" or visited[ny].get(nx) is not None: return False # m[ny][nx] = "@" visited[ny][nx] = True return True for i in range(h): for j in range(w): if check(i, j): print("YES") exit() print("NO")