結果

問題 No.179 塗り分け
コンテスト
ユーザー くわい
提出日時 2015-09-23 18:26:07
言語 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_
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,459 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,659 ms
コンパイル使用メモリ 243,828 KB
最終ジャッジ日時 2026-03-09 13:54:42
合計ジャッジ時間 7,431 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

ソースコード

diff #
raw source code

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)
  }
}
0