結果
問題 | No.421 しろくろチョコレート |
ユーザー |
![]() |
提出日時 | 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, matchused[v]=trueg[v].each{|u|w=match[u]if !w or (!used[w] and dfs(g, w, used, match))match[v]=umatch[u]=vreturn trueend} if g[v]falseenddef bipartite_matching gres=0match={}g.keys.each{|v|unless match[v]used={}res+=1 if dfs(g, v, used, match)end}resendh, w=gets.split.map &:to_iw+=2choco=?.*wh.times {choco<<?.choco<<gets}choco<<?.*wgraph={}black=0white=0for i in 0..choco.size-1next if choco[i]!~/b|w/choco[i]==?b ? black+=1 : white+=1for 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]endenda=bipartite_matching graphb=[black, white].min-ac=black+white-2*(a+b)puts 100*a+10*b+c