Submission #423541


Source Code Expand

import scala.collection.mutable
import scala.annotation.tailrec
import collection.JavaConversions._

object Main {

  private[this] val Array(h,w,_*) = readLine.split(" ").map(_.toInt)
  private[this] val grid = (for(i <- 0 until h) yield readLine).toArray

  type Cell = (Int,Int)

  def next(now: Cell, used: mutable.Set[Cell]): List[Cell] = {
    List((0,-1), (1,0), (0,1), (-1,0))
    .flatMap{case (dx:Int, dy:Int) => List((now._1 + dx, now._2 + dy))}
    .filter((d:Cell) => 0 <= d._1 && 0 <= d._2 && d._1 < w && d._2 < h)
    .filter((d:Cell) => grid(d._2)(d._1)!='#' && !used.contains(d))
  }

  @tailrec
  def dfs(stk: mutable.Stack[Cell], used: mutable.Set[Cell] = mutable.Set.empty[Cell]): Boolean = {

    val now = stk.pop

    if(grid(now._2)(now._1)=='g') true
    else {
      val nx = next(now,used)
      if(stk.size + nx.size == 0) false
      else dfs(stk.pushAll(nx), used + now)
    }
  }

  def main (args: Array[String]): Unit = {
    val res = for{
      sy <- 0 until h
      sx <- 0 until w
      if(grid(sy)(sx)=='s')
    } yield dfs(mutable.Stack((sx,sy)))

    println(if(res.fold(false)(_ | _))"Yes" else "No")
  }
}

Submission Info

Submission Time
Task A - 深さ優先探索
User TobiasGSmollett
Language Scala (2.11.5)
Score 0
Code Size 1187 Byte
Status TLE
Exec Time 2051 ms
Memory 64176 KB

Compile Error

warning: there were two deprecation warnings; re-run with -deprecation for details
one warning found

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 5
AC × 57
TLE × 26
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 00_min_01.txt, 00_min_02.txt, 00_min_03.txt, 00_min_04.txt, 00_min_05.txt, 00_min_06.txt, 00_min_07.txt, 00_min_08.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rndhard_00.txt, 02_rndhard_01.txt, 02_rndhard_02.txt, 02_rndhard_03.txt, 02_rndhard_04.txt, 02_rndhard_05.txt, 02_rndhard_06.txt, 02_rndhard_07.txt, 02_rndhard_08.txt, 02_rndhard_09.txt, 02_rndhard_10.txt, 02_rndhard_11.txt, 02_rndhard_12.txt, 02_rndhard_13.txt, 02_rndhard_14.txt, 02_rndhard_15.txt, 02_rndhard_16.txt, 02_rndhard_17.txt, 02_rndhard_18.txt, 02_rndhard_19.txt, 02_rndhard_20.txt, 02_rndhard_21.txt, 02_rndhard_22.txt, 02_rndhard_23.txt, 02_rndhard_24.txt, 02_rndhard_25.txt, 02_rndhard_26.txt, 02_rndhard_27.txt, 02_rndhard_28.txt, 02_rndhard_29.txt, 02_rndhard_30.txt, 02_rndhard_31.txt, 02_rndhard_32.txt, 02_rndhard_33.txt, 02_rndhard_34.txt, 02_rndhard_35.txt, 02_rndhard_36.txt, 02_rndhard_37.txt, 02_rndhard_38.txt, 02_rndhard_39.txt, 03_rndhardsmall_00.txt, 03_rndhardsmall_01.txt, 03_rndhardsmall_02.txt, 03_rndhardsmall_03.txt, 03_rndhardsmall_04.txt, 03_rndhardsmall_05.txt, 03_rndhardsmall_06.txt, 03_rndhardsmall_07.txt, 03_rndhardsmall_08.txt, 03_rndhardsmall_09.txt
Case Name Status Exec Time Memory
00_min_01.txt AC 1110 ms 48916 KB
00_min_02.txt AC 1083 ms 48488 KB
00_min_03.txt AC 1081 ms 48960 KB
00_min_04.txt AC 1082 ms 48604 KB
00_min_05.txt AC 1074 ms 48396 KB
00_min_06.txt AC 1072 ms 48832 KB
00_min_07.txt AC 1072 ms 48776 KB
00_min_08.txt AC 1068 ms 48332 KB
00_sample_01.txt AC 1077 ms 48964 KB
00_sample_02.txt AC 1082 ms 48488 KB
00_sample_03.txt AC 1148 ms 48552 KB
00_sample_04.txt AC 1134 ms 48672 KB
00_sample_05.txt AC 1085 ms 48944 KB
01_rnd_00.txt AC 1227 ms 54452 KB
01_rnd_01.txt TLE 2045 ms 62800 KB
01_rnd_02.txt TLE 2043 ms 63636 KB
01_rnd_03.txt TLE 2044 ms 62164 KB
01_rnd_04.txt TLE 2043 ms 61508 KB
01_rnd_05.txt AC 1278 ms 54840 KB
01_rnd_06.txt TLE 2046 ms 60996 KB
01_rnd_07.txt TLE 2045 ms 61760 KB
01_rnd_08.txt AC 1238 ms 54132 KB
01_rnd_09.txt AC 1265 ms 54688 KB
01_rnd_10.txt TLE 2044 ms 61408 KB
01_rnd_11.txt AC 1226 ms 54432 KB
01_rnd_12.txt TLE 2051 ms 61512 KB
01_rnd_13.txt TLE 2044 ms 61828 KB
01_rnd_14.txt AC 1254 ms 54488 KB
01_rnd_15.txt TLE 2045 ms 62116 KB
01_rnd_16.txt AC 1236 ms 54300 KB
01_rnd_17.txt TLE 2044 ms 64176 KB
01_rnd_18.txt AC 1246 ms 54528 KB
01_rnd_19.txt TLE 2045 ms 63684 KB
02_rndhard_00.txt AC 1909 ms 63204 KB
02_rndhard_01.txt AC 1864 ms 63716 KB
02_rndhard_02.txt TLE 2043 ms 63480 KB
02_rndhard_03.txt TLE 2044 ms 61708 KB
02_rndhard_04.txt AC 1393 ms 55748 KB
02_rndhard_05.txt AC 1416 ms 57436 KB
02_rndhard_06.txt AC 1623 ms 60968 KB
02_rndhard_07.txt AC 1393 ms 57288 KB
02_rndhard_08.txt TLE 2045 ms 61700 KB
02_rndhard_09.txt TLE 2045 ms 61328 KB
02_rndhard_10.txt TLE 2046 ms 63144 KB
02_rndhard_11.txt TLE 2044 ms 63192 KB
02_rndhard_12.txt TLE 2044 ms 60988 KB
02_rndhard_13.txt TLE 2044 ms 61444 KB
02_rndhard_14.txt TLE 2045 ms 61228 KB
02_rndhard_15.txt TLE 2044 ms 61184 KB
02_rndhard_16.txt AC 1572 ms 61484 KB
02_rndhard_17.txt AC 1563 ms 60844 KB
02_rndhard_18.txt AC 1720 ms 60860 KB
02_rndhard_19.txt AC 1643 ms 60804 KB
02_rndhard_20.txt AC 1713 ms 61772 KB
02_rndhard_21.txt AC 1701 ms 61076 KB
02_rndhard_22.txt TLE 2044 ms 61448 KB
02_rndhard_23.txt TLE 2045 ms 61640 KB
02_rndhard_24.txt AC 1627 ms 60980 KB
02_rndhard_25.txt AC 1647 ms 61700 KB
02_rndhard_26.txt AC 1736 ms 63056 KB
02_rndhard_27.txt AC 1525 ms 60228 KB
02_rndhard_28.txt AC 1924 ms 63388 KB
02_rndhard_29.txt AC 1925 ms 63332 KB
02_rndhard_30.txt AC 1320 ms 54664 KB
02_rndhard_31.txt AC 1296 ms 54728 KB
02_rndhard_32.txt TLE 2044 ms 61652 KB
02_rndhard_33.txt TLE 2044 ms 61528 KB
02_rndhard_34.txt AC 1588 ms 61260 KB
02_rndhard_35.txt AC 1609 ms 61500 KB
02_rndhard_36.txt AC 1577 ms 60708 KB
02_rndhard_37.txt AC 1552 ms 61316 KB
02_rndhard_38.txt AC 1993 ms 61768 KB
02_rndhard_39.txt AC 1989 ms 61320 KB
03_rndhardsmall_00.txt AC 1161 ms 48684 KB
03_rndhardsmall_01.txt AC 1156 ms 48632 KB
03_rndhardsmall_02.txt AC 1154 ms 48760 KB
03_rndhardsmall_03.txt AC 1176 ms 48924 KB
03_rndhardsmall_04.txt AC 1176 ms 48972 KB
03_rndhardsmall_05.txt AC 1193 ms 48768 KB
03_rndhardsmall_06.txt AC 1160 ms 48724 KB
03_rndhardsmall_07.txt AC 1140 ms 48788 KB
03_rndhardsmall_08.txt AC 1118 ms 48832 KB
03_rndhardsmall_09.txt AC 1140 ms 48940 KB