結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
Poina15
|
| 提出日時 | 2018-09-01 16:51:17 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 708 bytes |
| コンパイル時間 | 223 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 588,828 KB |
| 最終ジャッジ日時 | 2024-11-25 14:07:07 |
| 合計ジャッジ時間 | 51,149 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 2 |
| other | AC * 26 TLE * 6 |
ソースコード
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
group = [[0] * W for _ in range(H)]
def bfs(sr, sc, current_group, group, A, H, W):
stack = [(sr, sc)]
while stack:
r, c = stack.pop()
for dr, dc in zip([1, -1, 0, 0], [0, 0, 1, -1]):
rr, cc = r + dr, c + dc
if 0 <= rr < H and 0 <= cc < W:
if group[rr][cc] or A[rr][cc] == 0:
continue
group[rr][cc] = current_group
stack.append((rr, cc))
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] and group[i][j] == 0:
ans += 1
bfs(i, j, ans, group, A, H, W)
print(ans)
Poina15