AtCoder Beginner Contest 007

Submission #1511844

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<Integer> qy = new ArrayDeque<Integer>();
		Deque<Integer> qx = new ArrayDeque<Integer>();
		qy.offer(ny);
		qx.offer(nx);
		while (!qy.isEmpty() && !qx.isEmpty()) {
			int tempX = qx.poll();
			int tempY = qy.poll();

			for (int i = 0; i < 4; i++) {
				if (m[tempY + y[i]][tempX + x[i]] == -1) {
					m[tempY + y[i]][tempX + x[i]] = m[tempY][tempX] + 1;
					qy.offer(tempY + y[i]);
					qx.offer(tempX + x[i]);
				}
			}

		}

	}
}

Submission

Task問題 C - 幅優先探索
User nameユーザ名 edna
Created time投稿日時
Language言語 Java8 (OpenJDK 1.8.0)
Status状態 WA
Score得点 0
Source lengthソースコード長 1510 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 91 ms 21332 KB
subtask0_sample02.txt AC 91 ms 18640 KB
subtask0_sample03.txt AC 112 ms 21716 KB
subtask1_01.txt AC 98 ms 18900 KB
subtask1_02.txt AC 99 ms 19668 KB
subtask1_03.txt WA
subtask1_04.txt AC 105 ms 18644 KB
subtask1_05.txt WA
subtask1_06.txt WA
subtask1_07.txt AC 91 ms 18768 KB
subtask1_08.txt AC 96 ms 18644 KB
subtask1_09.txt WA
subtask1_10.txt AC 112 ms 19540 KB
subtask1_11.txt WA
subtask1_12.txt WA
subtask1_13.txt WA
subtask1_14.txt AC 95 ms 19924 KB
subtask1_15.txt WA
subtask1_16.txt WA
subtask1_17.txt WA
subtask1_18.txt WA
subtask1_19.txt WA
subtask1_20.txt AC 98 ms 19540 KB
subtask1_21.txt AC 106 ms 19028 KB
subtask1_22.txt AC 101 ms 19412 KB