結果

問題 No.43 野球の試合
ユーザー letrangerjpletrangerjp
提出日時 2017-06-15 14:19:38
言語 Ruby
(3.3.0)
結果
AC  
実行時間 404 ms / 5,000 ms
コード長 913 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 17,320 KB
最終ジャッジ日時 2023-10-25 06:48:23
合計ジャッジ時間 2,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,160 KB
testcase_01 AC 84 ms
16,164 KB
testcase_02 AC 85 ms
16,164 KB
testcase_03 AC 81 ms
16,164 KB
testcase_04 AC 85 ms
16,164 KB
testcase_05 AC 80 ms
16,164 KB
testcase_06 AC 85 ms
16,164 KB
testcase_07 AC 404 ms
17,320 KB
testcase_08 AC 83 ms
16,164 KB
testcase_09 AC 86 ms
16,164 KB
testcase_10 AC 84 ms
16,164 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{
  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
    N.times{|y|
      N.times{|x|
        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], f[win_mask]].min
      }
    }
  end
}
p f[mask]
0