AtCoder Beginner Contest 007

Submission #3727890

Source codeソースコード

import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
    int R = scanner.nextInt();
    int C = scanner.nextInt();
    int sy = scanner.nextInt()-1;
    int sx = scanner.nextInt()-1;
    int gy = scanner.nextInt()-1;
    int gx = scanner.nextInt()-1;
    String[] str = new String[R];
    for(int i = 0; i < R; i++){
      str[i] = scanner.next();
    }
    char[][] map = new char[R][C];
    int[][] d = new int[R][C];
    for(int i = 0; i < R; i++){
      for(int j = 0; j < C; j++){
        map[i][j] = str[i].charAt(j);
        d[i][j] = -1;
      }
    }
    d[sy][sx] = 0;
    int[] mr = {0, 1, 0, -1};
    int[] mc = {1, 0, -1, 0};
    Deque<Point> deq = new ArrayDeque<Point>();
    deq.add(new Point(sy, sx));
    while(!deq.isEmpty()){
      Point now = deq.poll();
      for(int i = 0; i < mr.length; i++){
        Point next = new Point(now.r+mr[i], now.c+mc[i]);
        if(next.r < 0 || next.r >= R || next.c < 0 || next.c >= C){
          continue;
        }
        if(map[next.r][next.c] == '#'){
          continue;
        }
        if(d[next.r][next.c] != -1){
          continue;
        }
        d[next.r][next.c] = d[now.r][now.c]+1;
        deq.add(next);
      }
    }
    System.out.println(d[gy][gx]);
  }
  static class Point{
    int r;
    int c;
    public Point(int r, int c){
      this.r = r;
      this.c = c;
    }
  }
}

Submission

Task問題 C - 幅優先探索
User nameユーザ名 ff_kt
Created time投稿日時
Language言語 Java8 (OpenJDK 1.8.0)
Status状態 AC
Score得点 100
Source lengthソースコード長 1547 Byte
File nameファイル名
Exec time実行時間 109 ms
Memory usageメモリ使用量 22740 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt
All 100 / 100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample01.txt AC 97 ms 20564 KB
subtask0_sample02.txt AC 98 ms 21844 KB
subtask0_sample03.txt AC 104 ms 18900 KB
subtask1_01.txt AC 103 ms 18644 KB
subtask1_02.txt AC 103 ms 18644 KB
subtask1_03.txt AC 104 ms 22740 KB
subtask1_04.txt AC 104 ms 19796 KB
subtask1_05.txt AC 103 ms 20948 KB
subtask1_06.txt AC 104 ms 18644 KB
subtask1_07.txt AC 98 ms 19924 KB
subtask1_08.txt AC 102 ms 20948 KB
subtask1_09.txt AC 103 ms 19028 KB
subtask1_10.txt AC 101 ms 19796 KB
subtask1_11.txt AC 104 ms 21332 KB
subtask1_12.txt AC 106 ms 21332 KB
subtask1_13.txt AC 105 ms 21716 KB
subtask1_14.txt AC 104 ms 21588 KB
subtask1_15.txt AC 103 ms 22740 KB
subtask1_16.txt AC 104 ms 21844 KB
subtask1_17.txt AC 103 ms 18644 KB
subtask1_18.txt AC 104 ms 18644 KB
subtask1_19.txt AC 102 ms 21972 KB
subtask1_20.txt AC 102 ms 19412 KB
subtask1_21.txt AC 104 ms 18640 KB
subtask1_22.txt AC 109 ms 20820 KB