結果
問題 | No.697 池の数はいくつか |
ユーザー | vwxyz |
提出日時 | 2022-01-05 07:10:13 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,636 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 81,992 KB |
実行使用メモリ | 849,348 KB |
最終ジャッジ日時 | 2024-11-25 17:09:17 |
合計ジャッジ時間 | 25,647 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
55,408 KB |
testcase_01 | AC | 38 ms
55,268 KB |
testcase_02 | AC | 41 ms
54,708 KB |
testcase_03 | AC | 41 ms
54,324 KB |
testcase_04 | AC | 41 ms
55,568 KB |
testcase_05 | AC | 43 ms
55,116 KB |
testcase_06 | AC | 37 ms
55,228 KB |
testcase_07 | AC | 40 ms
54,288 KB |
testcase_08 | AC | 38 ms
55,900 KB |
testcase_09 | AC | 39 ms
54,692 KB |
testcase_10 | AC | 40 ms
55,304 KB |
testcase_11 | AC | 39 ms
55,680 KB |
testcase_12 | AC | 39 ms
55,588 KB |
testcase_13 | AC | 39 ms
54,788 KB |
testcase_14 | AC | 38 ms
55,256 KB |
testcase_15 | AC | 38 ms
55,276 KB |
testcase_16 | AC | 37 ms
56,076 KB |
testcase_17 | AC | 38 ms
55,244 KB |
testcase_18 | AC | 38 ms
56,088 KB |
testcase_19 | AC | 41 ms
54,540 KB |
testcase_20 | AC | 42 ms
55,012 KB |
testcase_21 | AC | 42 ms
55,084 KB |
testcase_22 | AC | 42 ms
55,820 KB |
testcase_23 | AC | 43 ms
54,524 KB |
testcase_24 | AC | 820 ms
275,604 KB |
testcase_25 | AC | 838 ms
276,692 KB |
testcase_26 | AC | 846 ms
275,756 KB |
testcase_27 | AC | 842 ms
275,592 KB |
testcase_28 | AC | 838 ms
276,944 KB |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | MLE | - |
testcase_34 | MLE | - |
ソースコード
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)