結果

問題 No.240 ナイト散歩
コンテスト
ユーザー ともき
提出日時 2015-07-10 23:05:53
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 912 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,392 ms
コンパイル使用メモリ 266,060 KB
実行使用メモリ 66,128 KB
最終ジャッジ日時 2026-03-09 13:35:51
合計ジャッジ時間 25,305 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec

// PriorityQueue[Long]()(scala.math.Ordering.Long.reverse)
package Lib {
  object EnRich {
    implicit class AString(val self : String) extends AnyVal {
      def splitToIntArray = self.split(" ").map(_.toInt)
    }
  }
}

import Lib.EnRich._
object Main {
  def go(x : Int, y : Int, k : Int = 3) : Set[(Int,Int)] = {
    if(k == 0) Set((x,y))
    else {
      (for(i <- Vector(-2,-1,1,2);
          j <- Vector(-2,-1,1,2);
          if Math.abs(i) + Math.abs(j) == 3)
       yield (i,j)
      ).map({case (i,j) => go(x+i,y+j,k-1)})
      .fold(Set[(Int,Int)]())(_ ++ _) + ((x,y))
    }
  }
  def main(args : Array[String]) : Unit = {
    val (x,y) = {
      val xy = readLine.splitToIntArray
      (xy(0),xy(1))
    }
    val ans = if(go(0,0,3) contains (x,y)) "YES" else "NO"
    println(ans)
  }
}
0