結果

問題 No.43 野球の試合
ユーザー DialBird
提出日時 2017-02-13 18:16:35
言語 Ruby
(3.4.1)
結果
AC  
実行時間 181 ms / 5,000 ms
コード長 1,030 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-12-29 18:53:33
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
    if @game_board[x][y] == 'o'
      @wins[x] += 1 
      rank = calc(x+1, y)
      @wins[x] -= 1
      return rank
    elsif @game_board[x][y] == 'x'
      @wins[y] += 1 
      rank = calc(x+1, y)
      @wins[y] -= 1
      return rank
    elsif @game_board[x][y] == '-'
      @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