Submission #162826
Source Code Expand
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int R = in.nextInt();
int C = in.nextInt();
int sy = in.nextInt() - 1;
int sx = in.nextInt() - 1;
int gy = in.nextInt() - 1;
int gx = in.nextInt() - 1;
char[][] board = new char[R][C];
for (int i=0; i< R; i++){
for (int j=0; j< C; j++){
board[i][j] = in.next().charAt(0);
}
}
int count = 0;
int ypos = sy;
int xpos = sx;
count = solve_board(count, ypos, xpos, gy, gx, board);
System.out.println(count);
}
public static int solve_board(int count, int ypos, int xpos, int gy, int gx, char[][] board){
if (ypos == gy && xpos == gx){
return count;
} else{
if (board[ypos+1][xpos] != '#'){
count++;
solve_board(count,ypos+1,xpos,gy, gx, board);
}
if (board[ypos][xpos-1] != '#'){
count++;
solve_board(count,ypos,xpos-1,gy, gx, board);
}
if (board[ypos-1][xpos] != '#'){
count++;
solve_board(count,ypos-1,xpos,gy, gx, board);
}
if (board[ypos][xpos+1] != '#'){
count++;
solve_board(count,ypos,xpos+1,gy, gx, board);
}
}
System.out.println("Something went wrong");
System.exit(0);
return -1;
}
}
Submission Info
Submission Time |
|
Task |
C - 幅優先探索 |
User |
coffeeapple |
Language |
Java (OpenJDK 1.7.0) |
Score |
0 |
Code Size |
1281 Byte |
Status |
RE |
Exec Time |
498 ms |
Memory |
23380 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt |
All |
subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_sample01.txt |
RE |
497 ms |
23216 KB |
subtask0_sample02.txt |
RE |
476 ms |
23220 KB |
subtask0_sample03.txt |
RE |
489 ms |
23216 KB |
subtask1_01.txt |
RE |
490 ms |
23352 KB |
subtask1_02.txt |
RE |
491 ms |
23224 KB |
subtask1_03.txt |
RE |
491 ms |
23224 KB |
subtask1_04.txt |
RE |
495 ms |
23208 KB |
subtask1_05.txt |
RE |
494 ms |
23220 KB |
subtask1_06.txt |
RE |
493 ms |
23224 KB |
subtask1_07.txt |
RE |
484 ms |
23220 KB |
subtask1_08.txt |
RE |
492 ms |
23196 KB |
subtask1_09.txt |
RE |
490 ms |
23344 KB |
subtask1_10.txt |
RE |
489 ms |
23224 KB |
subtask1_11.txt |
RE |
488 ms |
23340 KB |
subtask1_12.txt |
RE |
491 ms |
23220 KB |
subtask1_13.txt |
RE |
498 ms |
23352 KB |
subtask1_14.txt |
RE |
484 ms |
23336 KB |
subtask1_15.txt |
RE |
495 ms |
23220 KB |
subtask1_16.txt |
RE |
490 ms |
23348 KB |
subtask1_17.txt |
RE |
495 ms |
23380 KB |
subtask1_18.txt |
RE |
487 ms |
23352 KB |
subtask1_19.txt |
RE |
483 ms |
23348 KB |
subtask1_20.txt |
RE |
494 ms |
23352 KB |
subtask1_21.txt |
RE |
496 ms |
23224 KB |
subtask1_22.txt |
RE |
495 ms |
23344 KB |