結果
問題 | No.697 池の数はいくつか |
ユーザー | vwxyz |
提出日時 | 2022-01-05 07:10:13 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,636 bytes |
コンパイル時間 | 272 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 849,400 KB |
最終ジャッジ日時 | 2024-05-04 07:28:30 |
合計ジャッジ時間 | 9,288 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
56,204 KB |
testcase_01 | AC | 37 ms
56,500 KB |
testcase_02 | AC | 37 ms
54,824 KB |
testcase_03 | AC | 36 ms
55,216 KB |
testcase_04 | AC | 36 ms
54,912 KB |
testcase_05 | AC | 35 ms
55,980 KB |
testcase_06 | AC | 35 ms
55,752 KB |
testcase_07 | AC | 36 ms
54,456 KB |
testcase_08 | AC | 37 ms
54,884 KB |
testcase_09 | AC | 35 ms
55,544 KB |
testcase_10 | AC | 36 ms
55,768 KB |
testcase_11 | AC | 35 ms
55,584 KB |
testcase_12 | AC | 34 ms
55,420 KB |
testcase_13 | AC | 35 ms
55,540 KB |
testcase_14 | AC | 35 ms
55,568 KB |
testcase_15 | AC | 36 ms
55,780 KB |
testcase_16 | AC | 37 ms
56,012 KB |
testcase_17 | AC | 37 ms
54,228 KB |
testcase_18 | AC | 37 ms
55,504 KB |
testcase_19 | AC | 36 ms
54,472 KB |
testcase_20 | AC | 35 ms
55,020 KB |
testcase_21 | AC | 38 ms
55,280 KB |
testcase_22 | AC | 37 ms
55,360 KB |
testcase_23 | AC | 41 ms
54,468 KB |
testcase_24 | AC | 799 ms
275,836 KB |
testcase_25 | AC | 805 ms
276,592 KB |
testcase_26 | AC | 821 ms
275,952 KB |
testcase_27 | AC | 820 ms
275,768 KB |
testcase_28 | AC | 796 ms
276,632 KB |
testcase_29 | MLE | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
ソースコード
import sys readline=sys.stdin.readline from collections import deque class Graph: def __init__(self,V,edges=False,graph=False,directed=False,weighted=False,inf=float("inf")): self.V=V self.directed=directed self.weighted=weighted self.inf=inf if not graph: self.edges=edges self.graph=[[] for i in range(self.V)] if weighted: for i,j,d in self.edges: self.graph[i].append((j,d)) if not self.directed: self.graph[j].append((i,d)) else: for i,j in self.edges: self.graph[i].append(j) if not self.directed: self.graph[j].append(i) else: self.graph=graph self.edges=[] for i in range(self.V): if self.weighted: for j,d in self.graph[i]: if self.directed or not self.directed and i<=j: self.edges.append((i,j,d)) else: for j in self.graph[i]: if self.directed or not self.directed and i<=j: self.edges.append((i,j)) def MIV_BFS(self,initial_vertices=False,bipartite_graph=False,linked_components=False,parents=False): if not initial_vertices: initial_vertices=[i for i in range(self.V)] seen=[False]*self.V if bipartite_graph: bg=[None]*self.V cnt=-1 if linked_components: lc=[] if parents: ps=[None]*self.V for s in initial_vertices: if seen[s]: continue seen[s]=True if bipartite_graph: cnt+=1 bg[s]=(cnt,0) if linked_components: lc.append([s]) queue=deque([s]) while queue: x=queue.popleft() for y in self.graph[x]: if self.weighted: y,d=y if not seen[y]: seen[y]=True queue.append(y) if bipartite_graph: bg[y]=(cnt,bg[x][1]^1) if linked_components: lc[-1].append(y) if parents: ps[y]=x if bipartite_graph: bg_=bg bg=[[[],[]] for i in range(cnt+1)] for tpl in self.edges: i,j=tpl[:2] if self.weighted else tpl if not bg_[i][1]^bg_[j][1]: bg[bg_[i][0]]=False for x in range(self.V): if bg[bg_[x][0]]: bg[bg_[x][0]][bg_[x][1]].append(x) retu=() if bipartite_graph: retu+=(bg,) if linked_components: retu+=(lc,) if parents: retu=(ps,) if len(retu)==1: retu=retu[0] return retu H,W=map(int,readline().split()) A=[list(map(int,readline().split())) for h in range(H)] edges=[] for h in range(H-1): for w in range(W): if A[h][w] and A[h+1][w]: edges.append((h*W+w,(h+1)*W+w)) for h in range(H): for w in range(W-1): if A[h][w] and A[h][w+1]: edges.append((h*W+w,h*W+w+1)) G=Graph(H*W,edges=edges) ans=len(G.MIV_BFS(linked_components=True)) for h in range(H): for w in range(W): if A[h][w]==0: ans-=1 print(ans)