結果

問題 No.43 野球の試合
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-03-13 13:33:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 540 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-05-01 18:25:32
合計ジャッジ時間 1,825 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def min(a,b); a < b ? a : b; end
def max(a,b); a > b ? a : b; end
  
N = gets.to_i
B = N.times.map { gets.chomp }
W = Array.new(N + 1, 0); W[N] = 1_000_000
Q = []

(0 ... N).each do |i|
  (i ... N).each do |j|
    if B[i][j] == 'o'
      W[i] += 1
    elsif B[i][j] == 'x'
      W[j] += 1
    elsif B[i][j] == '-'
      Q << [i, j]
    end
  end
end

def dfs(i)
  if i < Q.size
    Q[i].map do |j| 
      W[j] += 1
      s = dfs(i + 1)
      W[j] -= 1
      s
    end.min
  else
    W.select{|w| w > W[0] }.uniq.size
  end
end

puts dfs(0)
0