結果

問題 No.43 野球の試合
ユーザー letrangerjpletrangerjp
提出日時 2017-06-15 14:21:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 348 ms / 5,000 ms
コード長 930 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 12,028 KB
実行使用メモリ 16,700 KB
最終ジャッジ日時 2023-10-25 06:48:29
合計ジャッジ時間 1,867 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
16,188 KB
testcase_01 AC 81 ms
16,188 KB
testcase_02 AC 79 ms
16,188 KB
testcase_03 AC 82 ms
16,188 KB
testcase_04 AC 81 ms
16,188 KB
testcase_05 AC 81 ms
16,188 KB
testcase_06 AC 89 ms
16,312 KB
testcase_07 AC 348 ms
16,700 KB
testcase_08 AC 81 ms
16,188 KB
testcase_09 AC 82 ms
16,188 KB
testcase_10 AC 81 ms
16,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
M = 31
S = N.times.map{
  gets[0,N]
}
mask = 0
last_mask = 0
S.each_with_index{|s, y|
  s.chars.each_with_index{|c, x|
    next if y >= x
    n = y * N + x
    last_mask |= 1 << 1 * n
    next if c == ?-
    # 試合済み
    mask |= 1 << 1 * n
    # 勝利
    mask |= 1 << 1 * n + M if c == ?o
  }
}
f = ->mask, from=0{
  if (mask & (1 << M) - 1) == last_mask
    table = [0] * N
    N.times{|y|
      N.times{|x|
        next if y >= x
        r = mask & (1 << y * N + x + M) > 0
        table[y] += 1 if r
        table[x] += 1 if !r
      }
    }
    table.uniq.sort_by{|v|-v}.index(table[0]) + 1
  else
    (from...N*N).each{|yx|
      y, x = yx.divmod(N)
      next if y >= x
      n = y * N + x
      # 試合済み
      next if mask & (1 << n) > 0
      lose_mask = mask | (1 << n)
      win_mask = lose_mask | (1 << n + M)
      return [f[lose_mask, yx+1], f[win_mask, yx+1]].min
    }
  end
}
p f[mask]
0