結果

問題 No.43 野球の試合
ユーザー DialBirdDialBird
提出日時 2017-02-13 18:19:36
言語 Ruby
(3.3.0)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 15,832 KB
最終ジャッジ日時 2023-08-28 15:36:45
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,180 KB
testcase_01 AC 75 ms
15,148 KB
testcase_02 AC 75 ms
15,280 KB
testcase_03 AC 75 ms
15,072 KB
testcase_04 AC 74 ms
15,096 KB
testcase_05 AC 76 ms
15,256 KB
testcase_06 AC 81 ms
15,148 KB
testcase_07 AC 126 ms
15,832 KB
testcase_08 AC 76 ms
15,052 KB
testcase_09 AC 75 ms
15,136 KB
testcase_10 AC 77 ms
15,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Solve
  def initialize
    @n = gets.to_i
    @game_board = @n.times.map do
      gets.chomp.split('')
    end
    @wins = Array.new(@n, 0)
  end

  def run
    return calc(0,0)
  end

  private

  def calc(x,y)
    if x >= @n
      y += 1
      return get_rank if y >= @n
      x = y
    end

    case @game_board[x][y]
    when 'o'
      @wins[x] += 1 
      rank = calc(x+1, y)
      @wins[x] -= 1
      return rank
    when 'x'
      @wins[y] += 1 
      rank = calc(x+1, y)
      @wins[y] -= 1
      return rank
    when '-'
      @wins[x] += 1 
      rank_1 = calc(x+1, y)
      @wins[x] -= 1
      @wins[y] += 1 
      rank_2 = calc(x+1, y)
      @wins[y] -= 1
      return [rank_1, rank_2].min
    else
      return calc(x+1, y)
    end
  end

  def get_rank
    current_max = @wins[0]
    rank = 1
    wins_sort = @wins.sort

    wins_sort.each do |i|
      if current_max < i
        rank += 1
        current_max = i
      end
    end

    return rank
  end
end

p Solve.new.run
0