結果
| 問題 |
No.421 しろくろチョコレート
|
| コンテスト | |
| ユーザー |
hogeover30
|
| 提出日時 | 2016-10-25 04:49:22 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 484 ms / 2,000 ms |
| コード長 | 893 bytes |
| コンパイル時間 | 74 ms |
| コンパイル使用メモリ | 7,168 KB |
| 実行使用メモリ | 17,664 KB |
| 最終ジャッジ日時 | 2024-09-23 07:10:26 |
| 合計ジャッジ時間 | 9,196 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 65 |
コンパイルメッセージ
Syntax OK
ソースコード
def dfs g, v, used, match
used[v]=true
g[v].each{|u|
w=match[u]
if !w or (!used[w] and dfs(g, w, used, match))
match[v]=u
match[u]=v
return true
end
} if g[v]
false
end
def bipartite_matching g
res=0
match={}
g.keys.each{|v|
unless match[v]
used={}
res+=1 if dfs(g, v, used, match)
end
}
res
end
h, w=gets.split.map &:to_i
w+=2
choco=?.*w
h.times {
choco<<?.
choco<<gets
}
choco<<?.*w
graph={}
black=0
white=0
for i in 0..choco.size-1
next if choco[i]!~/b|w/
choco[i]==?b ? black+=1 : white+=1
for j in [-1, 1, -w, w]
next if i+j<0 or i+j>=choco.size or choco[i+j]!~/b|w/
graph[i] ? graph[i]<< i+j : graph[i]=[i+j]
end
end
a=bipartite_matching graph
b=[black, white].min-a
c=black+white-2*(a+b)
puts 100*a+10*b+c
hogeover30