結果

問題 No.421 しろくろチョコレート
ユーザー hogeover30hogeover30
提出日時 2016-10-25 04:49:22
言語 Ruby
(3.3.0)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 23,552 KB
最終ジャッジ日時 2023-10-24 14:50:51
合計ジャッジ時間 8,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
16,112 KB
testcase_01 AC 100 ms
16,532 KB
testcase_02 AC 83 ms
16,112 KB
testcase_03 AC 80 ms
16,112 KB
testcase_04 AC 82 ms
16,112 KB
testcase_05 AC 84 ms
16,112 KB
testcase_06 AC 82 ms
16,148 KB
testcase_07 AC 88 ms
16,536 KB
testcase_08 AC 82 ms
16,112 KB
testcase_09 AC 81 ms
16,112 KB
testcase_10 AC 80 ms
16,112 KB
testcase_11 AC 88 ms
16,532 KB
testcase_12 AC 77 ms
16,112 KB
testcase_13 AC 77 ms
16,112 KB
testcase_14 AC 78 ms
16,112 KB
testcase_15 AC 78 ms
16,112 KB
testcase_16 AC 119 ms
18,020 KB
testcase_17 AC 111 ms
17,316 KB
testcase_18 AC 121 ms
17,968 KB
testcase_19 AC 78 ms
16,112 KB
testcase_20 AC 97 ms
16,800 KB
testcase_21 AC 107 ms
17,328 KB
testcase_22 AC 90 ms
16,532 KB
testcase_23 AC 79 ms
16,112 KB
testcase_24 AC 78 ms
16,108 KB
testcase_25 AC 78 ms
16,112 KB
testcase_26 AC 77 ms
16,112 KB
testcase_27 AC 78 ms
16,112 KB
testcase_28 AC 94 ms
16,796 KB
testcase_29 AC 98 ms
16,796 KB
testcase_30 AC 95 ms
16,580 KB
testcase_31 AC 469 ms
23,552 KB
testcase_32 AC 106 ms
16,992 KB
testcase_33 AC 101 ms
16,800 KB
testcase_34 AC 82 ms
16,112 KB
testcase_35 AC 81 ms
16,112 KB
testcase_36 AC 86 ms
16,272 KB
testcase_37 AC 129 ms
18,304 KB
testcase_38 AC 164 ms
19,940 KB
testcase_39 AC 88 ms
16,272 KB
testcase_40 AC 142 ms
18,400 KB
testcase_41 AC 93 ms
16,636 KB
testcase_42 AC 85 ms
16,156 KB
testcase_43 AC 88 ms
16,272 KB
testcase_44 AC 189 ms
19,012 KB
testcase_45 AC 82 ms
16,112 KB
testcase_46 AC 82 ms
16,112 KB
testcase_47 AC 89 ms
16,276 KB
testcase_48 AC 306 ms
20,640 KB
testcase_49 AC 84 ms
16,264 KB
testcase_50 AC 82 ms
16,112 KB
testcase_51 AC 177 ms
19,832 KB
testcase_52 AC 87 ms
16,536 KB
testcase_53 AC 81 ms
16,112 KB
testcase_54 AC 83 ms
16,112 KB
testcase_55 AC 81 ms
16,112 KB
testcase_56 AC 81 ms
16,112 KB
testcase_57 AC 82 ms
16,112 KB
testcase_58 AC 88 ms
16,536 KB
testcase_59 AC 84 ms
16,132 KB
testcase_60 AC 187 ms
19,708 KB
testcase_61 AC 213 ms
20,252 KB
testcase_62 AC 81 ms
16,112 KB
testcase_63 AC 82 ms
16,112 KB
testcase_64 AC 82 ms
16,112 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0