Submission #4309950


Source Code Expand

package atcoder;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;


public  class Main  {

	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		int C = sc.nextInt();
		int sy = sc.nextInt()-1;
		int sx = sc.nextInt()-1;
		int gy = sc.nextInt()-1;
		int gx = sc.nextInt()-1;
		String scanR[] = new String[R];
		for(int i = 0; i<R;i++) {
			scanR[i] = sc.next();
		}
		int map[][] = new int [R][C];  // 1が道 0が壁
		int t[] = new int[4]; //
		for(int i = 0; i<R; i++) {
			char[] c = scanR[i].toCharArray();
			for(int j = 0; j<C; j++) {
				if(c[j] =='#') map[i][j] = 0;  //壁
				else map[i][j] = 1; //道
			}
		}
		Queue <Node>queue = new ArrayDeque<>();
		Node  mapNode[][] = new Node[R][C];
		for(int i=0; i<R; i++) {
			for(int j=0; j<C; j++) {
				boolean w = (map[i][j]==1) ? true:false;
				Node p = new Node(i,j,w);
				mapNode[i][j] =p;
			}
		}
		boolean flag = true;
		int counter = 0;
		
		for(int p = 0; p<R; p++) {
			for(int q = 0; q<C; q++) {
				boolean ue = true;
				boolean sita =true;
				boolean migi = true;
				boolean hidari =true;
				if(p==0) ue=false;
				if(p==R-1)sita =false;
				if(q==0) hidari=false;
				if(q==C-1)migi=false;
				
				if(map[p][q]==0) {mapNode[p][q] =null; continue;}
				else {
					if(ue&&map[p-1][q]==1)mapNode[p][q].setup(mapNode[p-1][q]);
					if(hidari&&map[p][q-1]==1)mapNode[p][q].setleft(mapNode[p][q-1]);
					if(migi&&map[p][q+1]==1)mapNode[p][q].setright(mapNode[p][q+1]);
					if(sita&&map[p+1][q]==1)mapNode[p][q].setdown(mapNode[p+1][q]);
				}
			}
		}
		
		queue.add(mapNode[sy][sx]);
		while(!queue.isEmpty()) {
			
			Node c = queue.poll();
			if(c.i ==gy&& c.j ==gx)break;
			int countq = c.count;
			countq++;
			int i = c.i;
			int j = c.j;
			
			if(c.left!= null) {c.left.count =countq; queue.offer(c.left);}
			if(c.down!= null) {c.down.count =countq; queue.offer(c.down);}
			if(c.up != null) {c.up.count = countq; queue.offer(c.up);}
			if(c.right != null) {c.right.count = countq; queue.offer(c.right);}
		}
		
		int extractcount = mapNode[gy][gx].count;
		
		System.out.println(extractcount);
		}
		
		
	}
	
	
	
	


class Node{
	Node up=null;
	Node left=null;
	Node down=null;
	Node right=null;
	String xy;
	int i; //y
	int j; //x
	int count; //経路数
	boolean h = false; //壁ならfalse;
	public void setcount(int countq){
		count= countq;
	}
	
	public Node(int c,int d,boolean y) {
		i = c;
		j = d;
		h =y;
	}
	public void setup(Node tup) {
		up = tup;
	}
	
	public void setdown(Node tdown) {
		down = tdown;
	}
	public void setleft(Node tleft) {
		left = tleft;
	}
	public void setright(Node tright) {
		right = tright;
	}
	
	
	
	
}

Submission Info

Submission Time
Task C - 幅優先探索
User anpan_jinro
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2845 Byte
Status RE
Exec Time 84 ms
Memory 23380 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
RE × 3
RE × 25
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 84 ms 21204 KB
subtask0_sample02.txt RE 78 ms 20180 KB
subtask0_sample03.txt RE 80 ms 17876 KB
subtask1_01.txt RE 78 ms 18132 KB
subtask1_02.txt RE 82 ms 22996 KB
subtask1_03.txt RE 79 ms 16468 KB
subtask1_04.txt RE 80 ms 22356 KB
subtask1_05.txt RE 76 ms 17876 KB
subtask1_06.txt RE 79 ms 18772 KB
subtask1_07.txt RE 79 ms 20564 KB
subtask1_08.txt RE 79 ms 21332 KB
subtask1_09.txt RE 79 ms 19540 KB
subtask1_10.txt RE 80 ms 23380 KB
subtask1_11.txt RE 79 ms 19796 KB
subtask1_12.txt RE 79 ms 18900 KB
subtask1_13.txt RE 79 ms 18516 KB
subtask1_14.txt RE 81 ms 21332 KB
subtask1_15.txt RE 81 ms 20820 KB
subtask1_16.txt RE 80 ms 20820 KB
subtask1_17.txt RE 79 ms 18260 KB
subtask1_18.txt RE 79 ms 20692 KB
subtask1_19.txt RE 78 ms 19668 KB
subtask1_20.txt RE 79 ms 17492 KB
subtask1_21.txt RE 81 ms 18900 KB
subtask1_22.txt RE 81 ms 21460 KB