結果

問題 No.421 しろくろチョコレート
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2016-09-21 00:03:05
言語 Ruby
(3.2.2)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 11,856 KB
実行使用メモリ 20,748 KB
最終ジャッジ日時 2023-10-24 14:49:54
合計ジャッジ時間 9,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
16,052 KB
testcase_01 AC 95 ms
20,464 KB
testcase_02 AC 88 ms
17,632 KB
testcase_03 AC 84 ms
16,052 KB
testcase_04 AC 86 ms
16,836 KB
testcase_05 AC 88 ms
16,840 KB
testcase_06 AC 89 ms
16,084 KB
testcase_07 AC 98 ms
17,996 KB
testcase_08 AC 92 ms
17,592 KB
testcase_09 AC 88 ms
16,312 KB
testcase_10 AC 89 ms
16,312 KB
testcase_11 AC 95 ms
17,900 KB
testcase_12 AC 83 ms
16,052 KB
testcase_13 AC 83 ms
16,052 KB
testcase_14 AC 85 ms
16,052 KB
testcase_15 AC 85 ms
16,048 KB
testcase_16 AC 127 ms
19,872 KB
testcase_17 AC 116 ms
19,996 KB
testcase_18 AC 125 ms
19,956 KB
testcase_19 AC 83 ms
16,052 KB
testcase_20 AC 103 ms
19,636 KB
testcase_21 AC 112 ms
19,220 KB
testcase_22 AC 97 ms
17,996 KB
testcase_23 AC 84 ms
16,052 KB
testcase_24 AC 83 ms
16,044 KB
testcase_25 AC 83 ms
16,052 KB
testcase_26 AC 83 ms
16,052 KB
testcase_27 AC 83 ms
16,052 KB
testcase_28 AC 100 ms
18,596 KB
testcase_29 AC 104 ms
20,148 KB
testcase_30 AC 101 ms
18,856 KB
testcase_31 AC 494 ms
20,748 KB
testcase_32 AC 110 ms
18,368 KB
testcase_33 AC 105 ms
18,756 KB
testcase_34 AC 88 ms
16,692 KB
testcase_35 AC 87 ms
16,692 KB
testcase_36 AC 91 ms
19,344 KB
testcase_37 AC 133 ms
19,156 KB
testcase_38 AC 165 ms
19,620 KB
testcase_39 AC 91 ms
19,124 KB
testcase_40 AC 142 ms
17,608 KB
testcase_41 AC 98 ms
16,528 KB
testcase_42 AC 88 ms
16,588 KB
testcase_43 AC 91 ms
19,268 KB
testcase_44 AC 177 ms
18,704 KB
testcase_45 AC 88 ms
16,840 KB
testcase_46 AC 88 ms
16,840 KB
testcase_47 AC 95 ms
20,212 KB
testcase_48 AC 310 ms
18,932 KB
testcase_49 AC 89 ms
18,780 KB
testcase_50 AC 89 ms
17,368 KB
testcase_51 AC 172 ms
17,996 KB
testcase_52 AC 91 ms
18,128 KB
testcase_53 AC 85 ms
16,576 KB
testcase_54 AC 88 ms
18,052 KB
testcase_55 AC 85 ms
16,312 KB
testcase_56 AC 86 ms
16,312 KB
testcase_57 AC 86 ms
16,840 KB
testcase_58 AC 95 ms
19,792 KB
testcase_59 AC 91 ms
17,196 KB
testcase_60 AC 183 ms
19,264 KB
testcase_61 AC 209 ms
19,744 KB
testcase_62 AC 83 ms
16,052 KB
testcase_63 AC 83 ms
16,052 KB
testcase_64 AC 87 ms
16,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
V = []
G = Hash.new {|h,k| h[k] = [] }

def add_virt(color)
    v = V.size
    V << color
    v
end
def add_edge(u,v)
    G[u] << v
    G[v] << u
end

def dfs(u, matches, used = Array.new(V.size))
    used[u] = true
    G[u].find do |v|
        w = matches[v]
        if !w || (!used[w] && dfs(w, matches, used))
            matches[u] = v
            matches[v] = u
            true
        end
    end
end

def matching
    matches = Array.new(V.size)
    V.size.times.inject(0) do |s, v|
        s += 1 if !matches[v] && dfs(v, matches)
        s
    end
end

n, m = gets.split.map(&:to_i)
map = n.times.map do
    gets.chomp
end
vmap = Array.new(n) { Array.new(m,nil) }
n.times do |y|
    m.times do |x|
        if map[y][x] == 'w'
            vmap[y][x] = add_virt(:w)
        elsif map[y][x] == 'b'
            vmap[y][x] = add_virt(:b)
        end
    end
end
n.times do |y|
    m.times.each_cons(2) do |a,b|
        if vmap[y][a] && vmap[y][b]
            add_edge(vmap[y][a], vmap[y][b])
        end
    end
end
m.times do |x|
    n.times.each_cons(2) do |a,b|
        if vmap[a][x] && vmap[b][x]
            add_edge(vmap[a][x], vmap[b][x])
        end
    end
end

a,b = [:w,:b].map{|color| V.count(color) }.sort
c = matching

puts c * 100 + (a - c) * 10 + (b - a)




0