import java.util.Scanner object Problem179 { def canPaint(move: (Int, Int), sorted: Seq[(Int, Int)], painted: Map[(Int, Int), String]): Boolean = { if (sorted.isEmpty) { return true } val from = sorted.head painted.get(from) match { case None => { val to = (move._1 + from._1, move._2 + from._2) if (sorted.contains(to)) { canPaint(move, sorted.tail, painted + (from -> "RED") + (to -> "BLUE")) } else { return false } } case _ => canPaint(move, sorted.tail, painted) } } def proc(paintedBlack: Seq[(Int, Int)]): String = { val sorted = paintedBlack.sorted val painted = sorted.size if (painted == 0 || painted % 2 != 0) { return "NO" } // 先頭からの差分をリスト化する val (keyX, keyY) = sorted.head val moveList = { for { (x, y) <- sorted.tail } yield { (x - keyX, y - keyY) } } for (move <- moveList) { val ok = canPaint(move, sorted, Map[(Int, Int), String]()) if (ok) { return "YES" } } "NO" } def main(args: Array[String]) { val sc = new Scanner(System.in) val (h, w) = (sc.nextInt(), sc.nextInt()) val paintedBlack = (for (i <- 0 until h) yield { sc.next().zipWithIndex.filter(_._1 == '#').map(x => (i, x._2)) }).flatten val result: String = proc(paintedBlack) println(result) } }