結果

問題 No.43 野球の試合
ユーザー purple_jwlpurple_jwl
提出日時 2016-10-27 23:43:13
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,292 ms / 5,000 ms
コード長 868 bytes
コンパイル時間 8,474 ms
コンパイル使用メモリ 259,364 KB
実行使用メモリ 69,268 KB
最終ジャッジ日時 2023-09-12 06:44:00
合計ジャッジ時間 20,365 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 906 ms
62,092 KB
testcase_01 AC 897 ms
62,068 KB
testcase_02 AC 901 ms
61,912 KB
testcase_03 AC 896 ms
61,976 KB
testcase_04 AC 900 ms
62,172 KB
testcase_05 AC 904 ms
62,284 KB
testcase_06 AC 944 ms
61,992 KB
testcase_07 AC 1,292 ms
69,268 KB
testcase_08 AC 905 ms
62,012 KB
testcase_09 AC 903 ms
61,888 KB
testcase_10 AC 899 ms
61,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.io.StdIn

object Main {
  def rec(idx: Int, n: Int, s: Array[Array[Char]]): Int = {
    if (idx == n * n) {
      val winCount = s.map { (ss) =>
        ss.filter(_ == 'o').size
      }

      var rank = 1
      for (i <- (0 to n).reverse) {
        if (winCount(0) == i) return rank
        if (winCount.filter(_ == i).size != 0) rank += 1
      }
    }

    val x = idx % n
    val y = idx / n

    if (s(y)(x) == '-') {
      s(y)(x) = 'o'
      s(x)(y) = 'x'
      val res1 = rec(idx + 1, n, s)
      s(y)(x) = 'x'
      s(x)(y) = 'o'
      val res2 = rec(idx + 1, n, s)
      s(y)(x) = '-'
      s(x)(y) = '-'
      return Math.min(res1, res2)
    } else {
      return rec(idx + 1, n, s)
    }
  }

  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt
    val s = Array.fill(n)(StdIn.readLine.toArray)
    println(rec(0, n, s))
  }
}
0