結果

問題 No.265 数学のテスト
ユーザー くわいくわい
提出日時 2015-11-02 17:17:19
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 961 bytes
コンパイル時間 5,955 ms
コンパイル使用メモリ 228,060 KB
最終ジャッジ日時 2024-04-27 02:14:27
合計ジャッジ時間 6,414 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

ソースコード

diff #

import scala.io.StdIn

object Problem265 {

  def d(freq: Int, di: Int): Int = {
    if (freq < di) return 0
    di match {
      case 0 => 1
      case _ => freq * d(freq - 1, di - 1)
    }
  }

  def proc(N: Int, dmax: Int, S: String): String = {
    val cnt = Array.fill(dmax + 1)(0L)
    var di = 0
    var cof = 0L
    var freq = 0

    def commit: Unit = {
      if (freq >= di) {
        cnt(freq - di) += d(freq, di) * cof
      }
      cof = 0L
      freq = 0
    }

    for (i <- 0 until N) {
      S(i) match {
        case 'd' => di += 1
        case '}' => commit; di -= 1
        case '+' => commit
        case 'x' => freq += 1; if (cof == 0L) cof = 1L
        case c if c.isDigit => cof = c - '0'
        case _ =>
      }
    }
    commit

    cnt.mkString(" ")
  }

  def main(args: Array[String]) {
    val N = StdIn.readInt()
    val d = StdIn.readInt()
    val S = StdIn.readLine()

    val result = proc(N, d, S)
    println(result)
  }
}
0