結果
問題 | No.13 囲みたい! |
ユーザー |
![]() |
提出日時 | 2020-09-03 20:47:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 78 ms / 5,000 ms |
コード長 | 755 bytes |
コンパイル時間 | 201 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 76,544 KB |
最終ジャッジ日時 | 2024-11-24 01:09:32 |
合計ジャッジ時間 | 2,004 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
w, h = map(int, input().split())m = [list(map(int, input().split())) for _ in range(h)]pre = [[None] * w for _ in range(h)]ok = Falsefor i in range(h):for j in range(w):if pre[i][j] is None:num = m[i][j]pre[i][j] = i, jq = [(i, j)]while q:x, y = q.pop()for nx, ny in (x-1, y), (x+1, y), (x, y-1), (x, y+1):if 0 <= nx < h and 0 <= ny < w and m[nx][ny] == num and (nx, ny) != pre[x][y]:if pre[nx][ny] is None:pre[nx][ny] = x, yq.append((nx, ny))else:ok = Trueprint('im' * (not ok) + 'possible')