結果

問題 No.190 Dry Wet Moist
ユーザー くわいくわい
提出日時 2015-11-21 14:32:10
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,564 bytes
コンパイル時間 6,182 ms
コンパイル使用メモリ 223,492 KB
最終ジャッジ日時 2023-09-11 21:48:27
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
-- [E040] Syntax Error: Main.scala:59:32 ---------------------------------------
59 |  def main(args: Array[String]) {
   |                                ^
   |                                '=' expected, but '{' found
1 error found

ソースコード

diff #

import scala.annotation.tailrec
import scala.io.StdIn

object Problem190 {

  val DRY: Int = -1
  val MOIST: Int = 0
  val WET: Int = 1

  def humidity(a: Int, b: Int): Int = (a + b).compare(0)

  def dry(s: IndexedSeq[Int]): Int = {
    @tailrec
    def rec(result: Int, s: IndexedSeq[Int]): Int = {
      if (s.length < 2) return result

      humidity(s.head, s.last) match {
        case DRY => rec(result + 1, s.tail.init)
        case MOIST => rec(result, s.init)
        case WET => rec(result, s.init)
      }
    }
    rec(0, s)
  }

  def wet(s: IndexedSeq[Int]): Int = {
    @tailrec
    def rec(result: Int, s: IndexedSeq[Int]): Int = {
      if (s.length < 2) return result

      humidity(s.head, s.last) match {
        case DRY => rec(result, s.tail)
        case MOIST => rec(result, s.tail)
        case WET => rec(result + 1, s.tail.init)
      }
    }
    rec(0, s)
  }

  def moist(s: IndexedSeq[Int]): Int = {
    @tailrec
    def rec(result: Int, s: IndexedSeq[Int]): Int = {
      if (s.length < 2) return result

      humidity(s.head, s.last) match {
        case DRY => rec(result, s.tail)
        case MOIST => rec(result + 1, s.tail.init)
        case WET => rec(result, s.init)
      }
    }
    rec(0, s)
  }

  def proc(N: Int, A: IndexedSeq[Int]): (Int, Int, Int) = {
    val s = A.sorted
    (dry(s), wet(s), moist(s))
  }

  def main(args: Array[String]) {
    val N = StdIn.readInt()
    val A = StdIn.readLine().split(" ").map(_.toInt).toIndexedSeq
    val (dry, wet, moist) = proc(N, A)
    println(s"$dry $wet $moist")
  }
}
0