結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2020-02-07 18:29:48 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 875 bytes |
| コンパイル時間 | 75 ms |
| コンパイル使用メモリ | 12,288 KB |
| 実行使用メモリ | 826,144 KB |
| 最終ジャッジ日時 | 2024-11-25 15:53:42 |
| 合計ジャッジ時間 | 44,703 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 3 |
| other | AC * 26 TLE * 3 MLE * 3 |
ソースコード
from collections import deque
import sys
input = sys.stdin.readline
def readlines(n):
for h in range(n):
for w, bit in enumerate(input().split()):
if bit == "1":
yield h,w
def main():
H, W = map(int, input().split())
A = set(readlines(H))
dire = [(-1,0),(0,1),(1,0),(0,-1)]
size = len(A)
ans = 0
for h,w in A.copy():
if size < 0:
break
if (h,w) not in A:
continue
ans += 1
frontier = deque()
frontier.append((h, w))
while frontier:
y, x = frontier.popleft()
for d, r in dire:
suc_y = y+d
suc_x = x+r
if (suc_y, suc_x) not in A:
continue
frontier.append((suc_y, suc_x))
A.remove((suc_y,suc_x))
size -= 1
print(ans)
main()