結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
lllllll88938494
|
| 提出日時 | 2022-09-22 16:01:19 |
| 言語 | Python3 (3.14.2 + numpy 2.4.0 + scipy 1.16.3) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 646 bytes |
| 記録 | |
| コンパイル時間 | 971 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 370,048 KB |
| 最終ジャッジ日時 | 2024-12-22 04:57:22 |
| 合計ジャッジ時間 | 81,013 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 TLE * 11 MLE * 2 |
ソースコード
from collections import deque
h,w=map(int,input().split())
grid=[list(map(int,input().split())) for i in range(h)]
f=[[0]*w for i in range(h)]
cnt = 1
l=[1,0,-1,0]
r=[0,1,0,-1]
def bfs(x,y):
d=deque()
d.append((x,y))
while d:
x,y=d.popleft()
f[x][y] = cnt
for i in range(4):
if 0 <= x + l[i] < h and 0 <= y + r[i] < w:
if grid[x+l[i]][y+r[i]] == 1 and f[x+l[i]][y+r[i]] == 0:
d.append((x+l[i],y+r[i]))
for i in range(h):
for j in range(w):
if grid[i][j] == 1 and f[i][j] ==0:
bfs(i,j)
cnt += 1
print(cnt-1)
lllllll88938494