結果

問題 No.43 野球の試合
ユーザー finefine
提出日時 2016-03-23 23:28:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 1,024 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 11,240 KB
実行使用メモリ 15,244 KB
最終ジャッジ日時 2023-08-27 06:15:11
合計ジャッジ時間 1,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,204 KB
testcase_01 AC 82 ms
15,124 KB
testcase_02 AC 83 ms
15,176 KB
testcase_03 AC 81 ms
15,244 KB
testcase_04 AC 82 ms
15,112 KB
testcase_05 AC 81 ms
15,104 KB
testcase_06 AC 82 ms
15,036 KB
testcase_07 AC 84 ms
15,176 KB
testcase_08 AC 81 ms
15,228 KB
testcase_09 AC 82 ms
15,244 KB
testcase_10 AC 82 ms
15,220 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def sol n,d,w,c,memo
    if memo[c] <= n && n == 6
        return memo[c]
    end
    if c == 0
        return w.uniq.sort.reverse.index(w[0]) + 1
    end
    ans = n
    n.times{|i|
        (i + 1).upto(n - 1){|j|
            if d[i][j] == '-'
                d[i][j] = 'o'
                d[j][i] = 'x'
                w[i] += 1
                ans = [ans, sol(n,d,w,c - 2,memo)].min
                d[i][j] = 'x'
                d[j][i] = 'o'
                w[i] -= 1
                w[j] += 1
                ans = [ans, sol(n,d,w,c - 2,memo)].min
                d[i][j] = '-'
                d[j][i] = '-'
                w[j] -= 1
            end
            }
        }
    memo[c] = [ans, memo[c]].min
    return ans
end

n = gets.to_i
d = Array.new(n)
w = Array.new(n,0)
c = 0

n.times{|i|
    d[i] = gets.chomp.split('')
    n.times{|j|
        if d[i][j] == 'o'
            w[i] += 1
        elsif d[i][j] == '-'
            c += 1
        end
        }
    }

memo = Array.new(c + 1, n + 1)
p sol(n,d,w,c,memo)
0