Submission #1417419
Source Code Expand
import java.util.Scanner; import java.util.Queue; import java.util.LinkedList; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int startX = 0, startY = 0; int goalX = 0, goalY = 0; char[][] map = new char[10][10]; int[][] distance = new int[10][10]; // Distance from starting point for(int y = 0; y < 10; y++) { String line = scanner.nextLine(); for(int x = 0; x < 10; x++) { map[x][y] = line.charAt(x); switch(map[x][y]) { case 'S': startY = y; startX = x; distance[x][y] = 0; break; case 'G': goalY = y; goalX = x; distance[x][y] = -1; break; case '.': distance[x][y] = -1; break; default: break; } } } Queue<Point> queue = new LinkedList<Point>(); int[] directionX = { -1, 0, 1, 0 }; // Left, Up, Right, Down int[] directionY = { 0, -1, 0, 1 }; // Left, Up, Right, Down queue.add(new Point(startX, startY)); // Add starting point to queue. while(!queue.isEmpty()) { queue.poll();// Poll point from queue. if(startX==goalX || startY==goalY)break;// If the point is goal, break loop. // For all possible directions, // if corresponding distance is not set and point is valid, // then set its distance from starting point, and add the point to queue. } System.out.println(distance[goalX][goalY]); } } class Point { int x = 0; int y = 0; Point(int x, int y) { this.x = x; this.y = y; } }
Submission Info
Submission Time | |
---|---|
Task | B - 雨上がり |
User | RYOSKATE |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 1792 Byte |
Status | RE |
Exec Time | 101 ms |
Memory | 23764 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 0 / 50 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | case_000.txt, case_001.txt, case_002.txt, case_003.txt, case_004.txt, case_005.txt, case_006.txt, case_007.txt, case_008.txt, case_009.txt, case_010.txt, case_011.txt, case_012.txt, case_013.txt, case_014.txt, case_015.txt, case_016.txt, case_017.txt, case_018.txt, case_019.txt, case_020.txt, case_021.txt, case_022.txt, case_023.txt, case_024.txt, case_025.txt, case_026.txt, case_027.txt, case_028.txt, case_029.txt, case_030.txt, case_031.txt, case_032.txt, case_033.txt, case_034.txt, case_035.txt, case_036.txt, case_037.txt, case_038.txt, case_039.txt, case_040.txt, case_041.txt, case_042.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
case_000.txt | RE | 91 ms | 19540 KB |
case_001.txt | RE | 90 ms | 19284 KB |
case_002.txt | RE | 89 ms | 19924 KB |
case_003.txt | RE | 89 ms | 21716 KB |
case_004.txt | RE | 91 ms | 21076 KB |
case_005.txt | RE | 89 ms | 19284 KB |
case_006.txt | RE | 92 ms | 21588 KB |
case_007.txt | RE | 89 ms | 22228 KB |
case_008.txt | RE | 92 ms | 21716 KB |
case_009.txt | RE | 90 ms | 21076 KB |
case_010.txt | RE | 90 ms | 21588 KB |
case_011.txt | RE | 90 ms | 18644 KB |
case_012.txt | RE | 91 ms | 21588 KB |
case_013.txt | RE | 92 ms | 19924 KB |
case_014.txt | RE | 91 ms | 21844 KB |
case_015.txt | RE | 97 ms | 21844 KB |
case_016.txt | RE | 94 ms | 20692 KB |
case_017.txt | RE | 90 ms | 21844 KB |
case_018.txt | RE | 91 ms | 21844 KB |
case_019.txt | RE | 92 ms | 17748 KB |
case_020.txt | RE | 91 ms | 21844 KB |
case_021.txt | RE | 92 ms | 21844 KB |
case_022.txt | RE | 93 ms | 19668 KB |
case_023.txt | RE | 90 ms | 21076 KB |
case_024.txt | RE | 91 ms | 21460 KB |
case_025.txt | RE | 91 ms | 21716 KB |
case_026.txt | RE | 92 ms | 21712 KB |
case_027.txt | RE | 91 ms | 21716 KB |
case_028.txt | RE | 90 ms | 21716 KB |
case_029.txt | RE | 101 ms | 20692 KB |
case_030.txt | RE | 90 ms | 21844 KB |
case_031.txt | RE | 99 ms | 21588 KB |
case_032.txt | RE | 90 ms | 23764 KB |
case_033.txt | RE | 93 ms | 18644 KB |
case_034.txt | RE | 90 ms | 20564 KB |
case_035.txt | RE | 90 ms | 19796 KB |
case_036.txt | RE | 91 ms | 20560 KB |
case_037.txt | RE | 90 ms | 21972 KB |
case_038.txt | RE | 90 ms | 21588 KB |
case_039.txt | RE | 90 ms | 18772 KB |
case_040.txt | RE | 91 ms | 19796 KB |
case_041.txt | RE | 89 ms | 21844 KB |
case_042.txt | RE | 92 ms | 21460 KB |