結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,288 KB
testcase_01 AC 81 ms
15,192 KB
testcase_02 AC 76 ms
15,188 KB
testcase_03 AC 77 ms
15,192 KB
testcase_04 AC 76 ms
15,240 KB
testcase_05 AC 74 ms
15,144 KB
testcase_06 AC 77 ms
15,160 KB
testcase_07 AC 144 ms
15,176 KB
testcase_08 AC 76 ms
15,100 KB
testcase_09 AC 76 ms
15,252 KB
testcase_10 AC 76 ms
15,052 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
    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