結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             neko_the_shadow
                         | 
                    
| 提出日時 | 2018-06-09 23:44:45 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 779 bytes | 
| コンパイル時間 | 514 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 99,620 KB | 
| 最終ジャッジ日時 | 2024-11-25 13:09:01 | 
| 合計ジャッジ時間 | 58,992 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 10 TLE * 6 | 
ソースコード
import itertools
if __name__ == '__main__':
    h, w = map(int, input().split())
    matrix = [list(map(int, input().split())) for _ in range(h)]
    
    diffs = ((1, 0), (-1, 0), (0, 1), (0, -1))
    counter = 2
    for x, y in itertools.product(range(h), range(w)):
        if matrix[x][y] == 0: continue
        ponds = [(x, y)]
        for dx, dy in diffs:
            i, j = x + dx, y + dy
            if 0 <= i < h and 0 <= j < w and matrix[i][j] != 0: ponds.append((i, j))
        
        coordinate = min((matrix[i][j] for i, j in ponds if matrix[i][j] != 1), default=counter)
        if coordinate == counter: counter += 1
        for i, j in ponds: matrix[i][j] = coordinate
    
    answer = max(map(max, matrix))
    if answer != 0: answer -= 1
    print(answer)
            
            
            
        
            
neko_the_shadow