結果

問題 No.240 ナイト散歩
ユーザー ともき
提出日時 2015-07-10 23:05:53
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 1,018 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 10,393 ms
コンパイル使用メモリ 263,620 KB
実行使用メモリ 66,748 KB
最終ジャッジ日時 2024-06-29 02:22:03
合計ジャッジ時間 46,130 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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