Submission #423650
Source Code Expand
import scala.collection.immutable.Stack import scala.annotation.tailrec case class Graph(es: scala.collection.mutable.Map[Vertex, Seq[Edge]]) case class Vertex(s: Char, i: Int, j: Int) case class Edge(v: Vertex) object Main{ def main(args: Array[String]):Unit = { import scala.collection.mutable val graph = Graph(mutable.Map():mutable.Map[Vertex, Seq[Edge]]) val scanner = new java.util.Scanner(System.in) val h = scanner.nextInt val w = scanner.nextInt val inputs = (0 until h).toArray.map{x => scanner.next.toArray} for{i <- (0 until h) j <- (0 until w) }(getFourWay(graph, inputs, h, w, i, j)) val start = graph.es.keySet.filter(_.s == 's').head val goal = graph.es.keySet.filter(_.s == 'g').head if(dfs(graph, start, goal)) println("Yes") else println("No") } def getFourWay(graph:Graph ,arr2:Array[Array[Char]], h:Int, w:Int, i:Int, j:Int): Unit = { val edges = scala.collection.mutable.ArrayBuffer.empty[Edge] // 北(i-1, j), 東(i, j+1), 南(i+1, j), 西(i, j-1) if(i-1 >= 0){edges += Edge(Vertex(arr2(i-1)(j), i-1, j))} if(j+1 < w){edges += Edge(Vertex(arr2(i)(j+1), i, j+1))} if(i+1 < h){edges += Edge(Vertex(arr2(i+1)(j), i+1, j))} if(j-1 >= 0){edges += Edge(Vertex(arr2(i)(j-1), i, j-1))} graph.es += Vertex(arr2(i)(j), i, j) -> edges.toSeq } def dfs(g: Graph, v: Vertex, goal: Vertex): Boolean = { dfs(g, goal, Set(), Stack(v)) } @tailrec def dfs(g: Graph, goal: Vertex, visited: Set[Vertex], stack: Stack[Vertex]): Boolean = { val (v, s) = stack.pop2 if (v == goal) true else if (visited.contains(v) && s.nonEmpty) dfs(g, goal, visited + v, s) else if (visited.contains(v)) false else { g.es.get(v) match { case Some(e) => dfs(g, goal, visited + v, s.pushAll(e.reverseMap(_.v).filter(_.s != '#'))) case _ if s.nonEmpty => dfs(g, goal, visited + v, s) case _ => false } } } }
Submission Info
Submission Time | |
---|---|
Task | A - 深さ優先探索 |
User | ababup1192 |
Language | Scala (2.11.5) |
Score | 0 |
Code Size | 2109 Byte |
Status | TLE |
Exec Time | 2037 ms |
Memory | 198656 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 |
|
|
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 | 1155 ms | 48324 KB |
00_min_02.txt | RE | 1160 ms | 48396 KB |
00_min_03.txt | RE | 1160 ms | 48528 KB |
00_min_04.txt | RE | 1186 ms | 48324 KB |
00_min_05.txt | AC | 1177 ms | 48416 KB |
00_min_06.txt | RE | 1164 ms | 48016 KB |
00_min_07.txt | RE | 1150 ms | 48672 KB |
00_min_08.txt | RE | 1161 ms | 48536 KB |
00_sample_01.txt | AC | 1153 ms | 48380 KB |
00_sample_02.txt | AC | 1138 ms | 48288 KB |
00_sample_03.txt | AC | 1150 ms | 48472 KB |
00_sample_04.txt | AC | 1148 ms | 48280 KB |
00_sample_05.txt | AC | 1158 ms | 47972 KB |
01_rnd_00.txt | TLE | 2036 ms | 139680 KB |
01_rnd_01.txt | TLE | 2035 ms | 185224 KB |
01_rnd_02.txt | TLE | 2036 ms | 176904 KB |
01_rnd_03.txt | TLE | 2035 ms | 185472 KB |
01_rnd_04.txt | TLE | 2035 ms | 175736 KB |
01_rnd_05.txt | TLE | 2035 ms | 139088 KB |
01_rnd_06.txt | TLE | 2035 ms | 184408 KB |
01_rnd_07.txt | TLE | 2033 ms | 189016 KB |
01_rnd_08.txt | TLE | 2036 ms | 140220 KB |
01_rnd_09.txt | TLE | 2034 ms | 139092 KB |
01_rnd_10.txt | TLE | 2035 ms | 183652 KB |
01_rnd_11.txt | TLE | 2034 ms | 139668 KB |
01_rnd_12.txt | TLE | 2035 ms | 176348 KB |
01_rnd_13.txt | TLE | 2035 ms | 150212 KB |
01_rnd_14.txt | TLE | 2033 ms | 140028 KB |
01_rnd_15.txt | TLE | 2036 ms | 184028 KB |
01_rnd_16.txt | TLE | 2036 ms | 140740 KB |
01_rnd_17.txt | TLE | 2035 ms | 183736 KB |
01_rnd_18.txt | TLE | 2034 ms | 141196 KB |
01_rnd_19.txt | TLE | 2036 ms | 198656 KB |
02_rndhard_00.txt | TLE | 2036 ms | 139272 KB |
02_rndhard_01.txt | TLE | 2034 ms | 141196 KB |
02_rndhard_02.txt | TLE | 2036 ms | 175908 KB |
02_rndhard_03.txt | TLE | 2034 ms | 159192 KB |
02_rndhard_04.txt | TLE | 2035 ms | 139596 KB |
02_rndhard_05.txt | TLE | 2034 ms | 139240 KB |
02_rndhard_06.txt | TLE | 2035 ms | 139064 KB |
02_rndhard_07.txt | TLE | 2037 ms | 139528 KB |
02_rndhard_08.txt | TLE | 2037 ms | 140592 KB |
02_rndhard_09.txt | TLE | 2035 ms | 140200 KB |
02_rndhard_10.txt | TLE | 2035 ms | 140224 KB |
02_rndhard_11.txt | TLE | 2036 ms | 139960 KB |
02_rndhard_12.txt | TLE | 2036 ms | 140512 KB |
02_rndhard_13.txt | TLE | 2035 ms | 140068 KB |
02_rndhard_14.txt | TLE | 2035 ms | 140616 KB |
02_rndhard_15.txt | TLE | 2034 ms | 140080 KB |
02_rndhard_16.txt | TLE | 2035 ms | 139644 KB |
02_rndhard_17.txt | TLE | 2035 ms | 140844 KB |
02_rndhard_18.txt | TLE | 2035 ms | 139772 KB |
02_rndhard_19.txt | TLE | 2034 ms | 139780 KB |
02_rndhard_20.txt | TLE | 2035 ms | 140240 KB |
02_rndhard_21.txt | TLE | 2034 ms | 141084 KB |
02_rndhard_22.txt | TLE | 2035 ms | 140480 KB |
02_rndhard_23.txt | TLE | 2034 ms | 141072 KB |
02_rndhard_24.txt | TLE | 2034 ms | 140328 KB |
02_rndhard_25.txt | TLE | 2036 ms | 139548 KB |
02_rndhard_26.txt | TLE | 2035 ms | 140112 KB |
02_rndhard_27.txt | TLE | 2036 ms | 138788 KB |
02_rndhard_28.txt | TLE | 2035 ms | 140560 KB |
02_rndhard_29.txt | TLE | 2035 ms | 139212 KB |
02_rndhard_30.txt | TLE | 2035 ms | 139908 KB |
02_rndhard_31.txt | TLE | 2036 ms | 140304 KB |
02_rndhard_32.txt | TLE | 2035 ms | 140472 KB |
02_rndhard_33.txt | TLE | 2036 ms | 140420 KB |
02_rndhard_34.txt | TLE | 2034 ms | 140420 KB |
02_rndhard_35.txt | TLE | 2034 ms | 139576 KB |
02_rndhard_36.txt | TLE | 2035 ms | 140684 KB |
02_rndhard_37.txt | TLE | 2035 ms | 140732 KB |
02_rndhard_38.txt | TLE | 2035 ms | 138824 KB |
02_rndhard_39.txt | TLE | 2036 ms | 140072 KB |
03_rndhardsmall_00.txt | AC | 1146 ms | 48084 KB |
03_rndhardsmall_01.txt | RE | 1148 ms | 48020 KB |
03_rndhardsmall_02.txt | AC | 1165 ms | 48408 KB |
03_rndhardsmall_03.txt | AC | 1163 ms | 48440 KB |
03_rndhardsmall_04.txt | RE | 1148 ms | 48144 KB |
03_rndhardsmall_05.txt | RE | 1151 ms | 48492 KB |
03_rndhardsmall_06.txt | AC | 1147 ms | 48576 KB |
03_rndhardsmall_07.txt | AC | 1144 ms | 48280 KB |
03_rndhardsmall_08.txt | AC | 1142 ms | 48448 KB |
03_rndhardsmall_09.txt | AC | 1149 ms | 48224 KB |