結果

問題 No.43 野球の試合
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-03-13 13:27:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 597 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 11,220 KB
実行使用メモリ 15,456 KB
最終ジャッジ日時 2023-08-14 05:32:26
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,208 KB
testcase_01 AC 83 ms
15,132 KB
testcase_02 AC 83 ms
15,136 KB
testcase_03 AC 86 ms
15,068 KB
testcase_04 AC 84 ms
15,116 KB
testcase_05 AC 84 ms
15,040 KB
testcase_06 AC 86 ms
15,292 KB
testcase_07 AC 184 ms
15,456 KB
testcase_08 AC 83 ms
15,112 KB
testcase_09 AC 83 ms
15,172 KB
testcase_10 AC 83 ms
15,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:23: warning: assigned but unused variable - a
Main.rb:23: warning: assigned but unused variable - b
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, 0)
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
    a,b = Q[i]
    Q[i].map do |j| 
      W[j] += 1
      s = dfs(i + 1)
      W[j] -= 1
      s
    end.min
  else
    r = (0 ... N).group_by{|i| W[i] }
    return r.keys.sort.reverse.index{|t| r[t].include?(0) } + 1
  end
end

puts dfs(0)
0