結果
問題 | No.697 池の数はいくつか |
ユーザー | vwxyz |
提出日時 | 2022-01-05 07:09:48 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,636 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 817,716 KB |
最終ジャッジ日時 | 2024-11-25 17:08:08 |
合計ジャッジ時間 | 57,110 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | MLE | - |
testcase_02 | MLE | - |
testcase_03 | AC | 28 ms
11,008 KB |
testcase_04 | AC | 28 ms
10,880 KB |
testcase_05 | AC | 28 ms
11,136 KB |
testcase_06 | AC | 27 ms
10,880 KB |
testcase_07 | AC | 29 ms
11,008 KB |
testcase_08 | AC | 28 ms
11,136 KB |
testcase_09 | AC | 28 ms
10,880 KB |
testcase_10 | AC | 28 ms
11,136 KB |
testcase_11 | AC | 28 ms
11,008 KB |
testcase_12 | AC | 28 ms
10,880 KB |
testcase_13 | AC | 27 ms
11,136 KB |
testcase_14 | AC | 27 ms
11,008 KB |
testcase_15 | AC | 27 ms
11,136 KB |
testcase_16 | AC | 27 ms
11,008 KB |
testcase_17 | AC | 27 ms
10,880 KB |
testcase_18 | AC | 28 ms
11,136 KB |
testcase_19 | AC | 27 ms
10,880 KB |
testcase_20 | AC | 26 ms
10,880 KB |
testcase_21 | AC | 29 ms
10,880 KB |
testcase_22 | AC | 28 ms
11,008 KB |
testcase_23 | AC | 28 ms
11,008 KB |
testcase_24 | AC | 2,914 ms
271,752 KB |
testcase_25 | AC | 2,922 ms
271,744 KB |
testcase_26 | AC | 2,911 ms
271,636 KB |
testcase_27 | AC | 2,929 ms
271,372 KB |
testcase_28 | AC | 2,971 ms
271,724 KB |
testcase_29 | MLE | - |
testcase_30 | TLE | - |
testcase_31 | MLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
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)