Submission #423655
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(start,graph).contains(goal)) println("YES") else println("No") //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(start: Vertex, g: Graph): List[Vertex] = { def dfs0(v: Vertex, visited: List[Vertex]): List[Vertex] = { if (visited.contains(v)) visited else { val neighbours:List[Edge] = (g.es(v) filterNot visited.contains).toList neighbours.filter(_.v.s != '#').foldLeft(v :: visited)((b,a) => dfs0(a.v,b)) } } dfs0(start,List()).reverse } }
Submission Info
Submission Time | |
---|---|
Task | A - 深さ優先探索 |
User | ababup1192 |
Language | Scala (2.11.5) |
Score | 0 |
Code Size | 1953 Byte |
Status | WA |
Exec Time | 2047 ms |
Memory | 142024 KB |
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 | WA | 1153 ms | 48236 KB |
00_min_02.txt | AC | 1137 ms | 48288 KB |
00_min_03.txt | AC | 1130 ms | 48400 KB |
00_min_04.txt | AC | 1129 ms | 48220 KB |
00_min_05.txt | WA | 1135 ms | 48368 KB |
00_min_06.txt | AC | 1138 ms | 48512 KB |
00_min_07.txt | AC | 1138 ms | 48292 KB |
00_min_08.txt | AC | 1130 ms | 48188 KB |
00_sample_01.txt | AC | 1133 ms | 48388 KB |
00_sample_02.txt | WA | 1140 ms | 48436 KB |
00_sample_03.txt | AC | 1158 ms | 48408 KB |
00_sample_04.txt | WA | 1157 ms | 48436 KB |
00_sample_05.txt | AC | 1147 ms | 48156 KB |
01_rnd_00.txt | TLE | 2035 ms | 140592 KB |
01_rnd_01.txt | TLE | 2036 ms | 140532 KB |
01_rnd_02.txt | TLE | 2035 ms | 141396 KB |
01_rnd_03.txt | TLE | 2035 ms | 140856 KB |
01_rnd_04.txt | TLE | 2034 ms | 140204 KB |
01_rnd_05.txt | TLE | 2035 ms | 141116 KB |
01_rnd_06.txt | TLE | 2035 ms | 141612 KB |
01_rnd_07.txt | TLE | 2035 ms | 141576 KB |
01_rnd_08.txt | TLE | 2035 ms | 140540 KB |
01_rnd_09.txt | TLE | 2035 ms | 140364 KB |
01_rnd_10.txt | TLE | 2034 ms | 141296 KB |
01_rnd_11.txt | TLE | 2035 ms | 140016 KB |
01_rnd_12.txt | TLE | 2035 ms | 141912 KB |
01_rnd_13.txt | TLE | 2034 ms | 141628 KB |
01_rnd_14.txt | TLE | 2035 ms | 140608 KB |
01_rnd_15.txt | TLE | 2035 ms | 140660 KB |
01_rnd_16.txt | TLE | 2047 ms | 140768 KB |
01_rnd_17.txt | TLE | 2033 ms | 140220 KB |
01_rnd_18.txt | TLE | 2035 ms | 140512 KB |
01_rnd_19.txt | TLE | 2035 ms | 141916 KB |
02_rndhard_00.txt | TLE | 2035 ms | 141312 KB |
02_rndhard_01.txt | TLE | 2034 ms | 140236 KB |
02_rndhard_02.txt | TLE | 2036 ms | 141224 KB |
02_rndhard_03.txt | TLE | 2036 ms | 140836 KB |
02_rndhard_04.txt | TLE | 2034 ms | 140828 KB |
02_rndhard_05.txt | TLE | 2035 ms | 141040 KB |
02_rndhard_06.txt | TLE | 2035 ms | 140256 KB |
02_rndhard_07.txt | TLE | 2033 ms | 140212 KB |
02_rndhard_08.txt | TLE | 2035 ms | 140864 KB |
02_rndhard_09.txt | TLE | 2035 ms | 141788 KB |
02_rndhard_10.txt | TLE | 2034 ms | 140624 KB |
02_rndhard_11.txt | TLE | 2034 ms | 140444 KB |
02_rndhard_12.txt | TLE | 2034 ms | 141568 KB |
02_rndhard_13.txt | TLE | 2034 ms | 141996 KB |
02_rndhard_14.txt | TLE | 2035 ms | 141624 KB |
02_rndhard_15.txt | TLE | 2034 ms | 140788 KB |
02_rndhard_16.txt | TLE | 2034 ms | 140292 KB |
02_rndhard_17.txt | TLE | 2035 ms | 139856 KB |
02_rndhard_18.txt | TLE | 2036 ms | 141064 KB |
02_rndhard_19.txt | TLE | 2035 ms | 139156 KB |
02_rndhard_20.txt | TLE | 2036 ms | 139780 KB |
02_rndhard_21.txt | TLE | 2035 ms | 140828 KB |
02_rndhard_22.txt | TLE | 2036 ms | 140276 KB |
02_rndhard_23.txt | TLE | 2033 ms | 141056 KB |
02_rndhard_24.txt | TLE | 2035 ms | 140368 KB |
02_rndhard_25.txt | TLE | 2034 ms | 139980 KB |
02_rndhard_26.txt | TLE | 2035 ms | 140132 KB |
02_rndhard_27.txt | TLE | 2034 ms | 140988 KB |
02_rndhard_28.txt | TLE | 2035 ms | 141456 KB |
02_rndhard_29.txt | TLE | 2035 ms | 140664 KB |
02_rndhard_30.txt | TLE | 2035 ms | 141016 KB |
02_rndhard_31.txt | TLE | 2035 ms | 140772 KB |
02_rndhard_32.txt | TLE | 2034 ms | 142024 KB |
02_rndhard_33.txt | TLE | 2033 ms | 140952 KB |
02_rndhard_34.txt | TLE | 2035 ms | 139708 KB |
02_rndhard_35.txt | TLE | 2035 ms | 139892 KB |
02_rndhard_36.txt | TLE | 2036 ms | 140004 KB |
02_rndhard_37.txt | TLE | 2033 ms | 140448 KB |
02_rndhard_38.txt | TLE | 2034 ms | 139660 KB |
02_rndhard_39.txt | TLE | 2035 ms | 141180 KB |
03_rndhardsmall_00.txt | AC | 1145 ms | 48464 KB |
03_rndhardsmall_01.txt | AC | 1130 ms | 47988 KB |
03_rndhardsmall_02.txt | AC | 1164 ms | 48396 KB |
03_rndhardsmall_03.txt | AC | 1167 ms | 48396 KB |
03_rndhardsmall_04.txt | AC | 1156 ms | 48312 KB |
03_rndhardsmall_05.txt | AC | 1157 ms | 48400 KB |
03_rndhardsmall_06.txt | AC | 1170 ms | 47860 KB |
03_rndhardsmall_07.txt | AC | 1154 ms | 48376 KB |
03_rndhardsmall_08.txt | AC | 1158 ms | 48428 KB |
03_rndhardsmall_09.txt | AC | 1160 ms | 48208 KB |