結果

問題 No.43 野球の試合
ユーザー purple_jwlpurple_jwl
提出日時 2016-10-27 23:19:21
言語 Scala(Beta)
(3.4.0)
結果
WA  
実行時間 -
コード長 828 bytes
コンパイル時間 9,319 ms
コンパイル使用メモリ 254,808 KB
実行使用メモリ 62,440 KB
最終ジャッジ日時 2023-09-12 06:42:50
合計ジャッジ時間 21,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 958 ms
62,400 KB
testcase_01 AC 949 ms
62,176 KB
testcase_02 AC 945 ms
62,064 KB
testcase_03 AC 947 ms
62,060 KB
testcase_04 WA -
testcase_05 AC 952 ms
62,376 KB
testcase_06 AC 1,010 ms
62,048 KB
testcase_07 AC 947 ms
62,440 KB
testcase_08 AC 959 ms
62,408 KB
testcase_09 AC 953 ms
62,216 KB
testcase_10 AC 943 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)
      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