Submission #1435973


Source Code Expand

/**
 * http://abc007.contest.atcoder.jp/tasks/abc007_3
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		int C = sc.nextInt();
		int s[] = new int[2];
		int g[] = new int[2];
		int cost[][]  = new int[R][C];
		char field[][]  = new char[R][C];
		s[0] = sc.nextInt()-1;
		s[1] = sc.nextInt()-1;
		g[0] = sc.nextInt()-1;
		g[1] = sc.nextInt()-1;
		for(int y=0; y<R; y++){
			String c = sc.next();
			for(int x=0; x<C; x++){
				cost[y][x] = -1;
				field[y][x] = (char) c.charAt(x);
			}
		}
		sc.close();
		
		List<Pos> search = new ArrayList<Pos>();
		search.add(new Pos(s[0],s[1]));
		cost[s[0]][s[1]]=0;
		
		while(true){
			
			if(search.size()==0){
				break;
			}
			
			Pos current = search.remove(0);
			int x = current.x;
			int y = current.y;
			
			Pos[] candidates = { new Pos(y,x-1), new Pos(y, x+1), new Pos(y-1,x), new Pos(y+1,x)};
			
			int minCost = Integer.MAX_VALUE;
			for(Pos pos: candidates){
				if(field[pos.y][pos.x] == '.'){
					if(cost[pos.y][pos.x] == -1){
						cost[pos.y][pos.x] = cost[y][x]+1;
						search.add(new Pos(pos.y,pos.x));
					}else{
						minCost = Math.min(minCost, cost[pos.y][pos.x]);
					}
				}
			}

		}
		
		System.out.println(cost[g[0]][g[1]]);
		
	}
	
	private static class Pos{
		Pos(final int y, final int x){
			this.x = x;
			this.y = y;
		}
		int x;
		int y;
	}

}

Submission Info

Submission Time
Task C - 幅優先探索
User namayaki
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1482 Byte
Status CE

Compile Error

./Main.java:8: error: cannot find symbol
		Scanner sc = new Scanner(System.in);
		^
  symbol:   class Scanner
  location: class Main
./Main.java:8: error: cannot find symbol
		Scanner sc = new Scanner(System.in);
		                 ^
  symbol:   class Scanner
  location: class Main
./Main.java:28: error: cannot find symbol
		List<Pos> search = new ArrayList<Pos>();
		^
  symbol:   class List
  location: class Main
./Main.java:28: error: cannot find symbol
		List<Pos> search = new ArrayList<Pos>();
		                       ^
  symbol:   class ArrayList
  location: class Main
4 errors