AtCoder Beginner Contest 007

Submission #1511769

Source codeソースコード

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

public class Main {
	static int r;
	static int c;
	static int sy;
	static int sx;
	static int gy;
	static int gx;
	static int[][] m;
	static int[] x = { 0, 1, 0, -1 };
	static int[] y = { -1, 0, 1, 0 };

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		sy = scan.nextInt();
		sx = scan.nextInt();
		gy = scan.nextInt();
		gx = scan.nextInt();

		m = new int[r + 2][c + 2];

		for (int i = 1; i <= r; i++) {
			String temp = scan.next();
			for (int j = 1; j <= c; j++) {
				if (temp.charAt(j - 1) == '.') {
					m[i][j] = -1;
				} else {
					m[i][j] = -2;
				}

			}
		}
		m[sy][sx] = 0;
		bfs(sy, sx);
		int ans = Integer.MIN_VALUE;

		for (int i = 1; i <= r; i++) {
			for (int j = 1; j <= c; j++) {
				if (m[i][j] > ans) {
					ans = m[i][j];
				}

			}
		}
		System.out.println(ans);

	}

	static void bfs(int ny, int nx) {
		Deque<int[]> q = new ArrayDeque<>();
		for (int i = 0; i < 4; i++) {
			if (m[ny + y[i]][nx + x[i]] == -1) {
				m[ny + y[i]][nx + x[i]] = m[ny][nx] + 1;
				int[] a = { ny + y[i], nx + x[i] };
				q.offer(a);
			}
		}
		while (!q.isEmpty()) {
			int[] b = q.pollFirst();
			bfs(b[0], b[1]);
		}

	}
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt
All 0 / 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 92 ms 18900 KB
subtask0_sample02.txt AC 95 ms 21716 KB
subtask0_sample03.txt WA
subtask1_01.txt AC 99 ms 18896 KB
subtask1_02.txt AC 100 ms 21844 KB
subtask1_03.txt WA
subtask1_04.txt WA
subtask1_05.txt WA
subtask1_06.txt WA
subtask1_07.txt AC 92 ms 19796 KB
subtask1_08.txt AC 97 ms 18644 KB
subtask1_09.txt WA
subtask1_10.txt WA
subtask1_11.txt WA
subtask1_12.txt WA
subtask1_13.txt WA
subtask1_14.txt AC 97 ms 20692 KB
subtask1_15.txt WA
subtask1_16.txt WA
subtask1_17.txt WA
subtask1_18.txt WA
subtask1_19.txt WA
subtask1_20.txt WA
subtask1_21.txt WA
subtask1_22.txt WA