結果

問題 No.282 おもりと天秤(2)
ユーザー くわいくわい
提出日時 2015-10-12 16:59:45
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,180 bytes
コンパイル時間 5,122 ms
コンパイル使用メモリ 226,596 KB
最終ジャッジ日時 2024-04-27 02:12:54
合計ジャッジ時間 5,896 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

ソースコード

diff #

import java.util.Scanner

object Problem282 {

  val sc = new Scanner(System.in)

  def question(s: Seq[Int]) = {
    println("? " + s.mkString(" "))
    val answer = Seq.fill(s.length / 2)(sc.next())
    answer
  }

  def fillSeq(s: Seq[Int], n: Int) = {
    s ++ Seq.fill(n * 2 - s.length)(0)
  }

  def swapSeqByAnswer(s: Seq[Int], answer: Seq[String]): Seq[Int] = {
    val z = s.grouped(2).toSeq.zip(answer)

    z flatMap { v =>
      v._2 match {
        case ">" => v._1.reverse
        case _ => v._1
      }
    }
  }

  def nonZeroFilter(swapped: Seq[Int]): Seq[Int] = {
    swapped.filter(_ != 0)
  }

  def main(args: Array[String]) {
    val N = sc.nextInt()

    def proc(raw: Seq[Int]): Seq[Int] = {
      def subProc(raw: Seq[Int]): Seq[Int] = {
        val filledSeq = fillSeq(raw, N)
        val answer = question(filledSeq)
        val swapped = swapSeqByAnswer(filledSeq, answer)
        nonZeroFilter(swapped)
      }

      val res1 = subProc(raw)
      val res2 = subProc(0 +: res1)

      if (res1 == res2) {
        res2
      } else {
        proc(res2)
      }
    }

    val result = proc((1 to N).toSeq)
    println("! " + result.mkString(" "))
  }
}
0