結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2022-03-23 16:07:41 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 745 bytes |
| コンパイル時間 | 578 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 338,944 KB |
| 最終ジャッジ日時 | 2024-10-11 19:04:48 |
| 合計ジャッジ時間 | 19,544 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 MLE * 1 -- * 5 |
ソースコード
h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]
used = [[False] * w for _ in range(h)]
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
ans = 0
for i in range(h):
for j in range(w):
if used[i][j] or A[i][j] == 0:
continue
ans += 1
stack = [(i, j)]
while stack:
ii, jj = stack.pop()
for di, dj in directions:
ni = ii + di
nj = jj + dj
if ni == -1 or ni == h or nj == -1 or nj == w:
continue
if A[ni][nj] == 0 or used[ni][nj]:
continue
used[ni][nj] = True
stack.append((ni, nj))
print(ans)