結果

問題 No.43 野球の試合
ユーザー finefine
提出日時 2016-03-23 23:08:08
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,010 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,488 KB
最終ジャッジ日時 2024-04-09 21:13:17
合計ジャッジ時間 9,639 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
12,416 KB
testcase_01 AC 78 ms
12,160 KB
testcase_02 AC 79 ms
12,160 KB
testcase_03 AC 77 ms
12,160 KB
testcase_04 AC 78 ms
12,160 KB
testcase_05 AC 79 ms
12,160 KB
testcase_06 AC 2,281 ms
12,288 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def sol n,d,w,c
    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)].min
                d[i][j] = 'x'
                d[j][i] = 'o'
                w[i] -= 1
                w[j] += 1
                ans = [ans, sol(n,d,w,c - 2)].min
                d[i][j] = '-'
                d[j][i] = '-'
                w[j] -= 1
            end
            }
        }
    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
        }
    }

1.upto(n - 1){|i|
    if d[0][i] == '-'
        d[0][i] = 'o'
        d[i][0] = 'x'
        w[0] += 1
        c -= 2
    end
    }

p sol(n,d,w,c)
0