結果
| 問題 |
No.190 Dry Wet Moist
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-21 14:32:10 |
| 言語 | Scala(Beta) (3.6.2) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,564 bytes |
| コンパイル時間 | 5,979 ms |
| コンパイル使用メモリ | 227,820 KB |
| 最終ジャッジ日時 | 2024-11-14 19:29:07 |
| 合計ジャッジ時間 | 6,672 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
[31m[31m-- [E040] Syntax Error: Main.scala:59:32 ---------------------------------------[0m[0m
[31m59 |[0m [33mdef[0m [36mmain[0m([36margs[0m: [35mArray[0m[[35mString[0m]) {
[31m[31m |[0m ^[0m
[31m |[0m '=' expected, but '{' found
1 error found
ソースコード
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")
}
}