Submission #162423


Source Code Expand

import java.io.*;
import java.util.*;
import java.math.*;


public class Main {
    static BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    static boolean isDebug = false;

    int N;
    
    static int[] moveY = {-1, 0, 0, 1};
    static int[] moveX = {0, -1, 1, 0};
    
    public void solve() throws Throwable {
        
        int[] first = readIntArray();

        int[] start = readIntArray();
        int[] goal = readIntArray();

        char[][] map = new char[first[0] + 2][first[1] + 2];
        
        for (int i = 0; i < first[0] + 2; i++) {
            Arrays.fill(map[i], '#');
        }
        for (int i = 1; i <= first[0]; i++) {
            map[i] = readCharWrapArray('#');
        }

        for (int i = 0; i < first[0] + 2; i++) {
            debug(map[i]);
        }
        
        Deque<Type> que = new ArrayDeque<Type>();
        que.push(new Type(start));
        
        int index = 0;

        
        for (;index < 1000; index++) {
            Deque<Type> nQue = new ArrayDeque<Type>();
            while (!que.isEmpty()) {
                Type t = que.poll();
                debug("t " + t.y + " : " + t.x);
                if (t.y == goal[0] && t.x == goal[1]) {
                    out.println(index);
                    out.flush();
                    return;
                }
                for (int i = 0; i < moveY.length; i++) {
                    int mY = t.y + moveY[i];
                    int mX = t.x + moveX[i];
                    if (map[mY][mX] == '.') {
                        debug(mY + ":" + mX);
                        map[mY][mX] = '#';
                        nQue.add(new Type(mY, mX));
                    }
                }
            }
            que = nQue;
        }
        out.println("-1");
        
        out.flush();
    }
    
    
    public static void main(String[] args) throws Throwable {
        long start = System.currentTimeMillis();

        Main main = new Main();
        main.solve();
        
        debug((System.currentTimeMillis() - start + ":ms"));
    }
    
    private int readInt() throws IOException {
        return Integer.parseInt(br.readLine());
    }
    
    private int[] readIntArray() throws IOException {
        String[] s = br.readLine().split(" ");

        int cnt = s.length;
        int[] out = new int[cnt];

        for (int i = 0; i < cnt; i++) {
            out[i] = Integer.parseInt(s[i]);
        }

        return out;
    }

    private char[] readCharArray() throws IOException {
        return br.readLine().toCharArray();
    }

    private char[] readCharWrapArray(char def) throws IOException {
        char[] base = br.readLine().toCharArray();
        
        char[] out = new char[base.length + 2];
        
        Arrays.fill(out, def);

        System.arraycopy(base, 0, out, 1, base.length);
        return out;
    }

    
    private static void debug(Object... o) {
        if (isDebug) out.println(Arrays.deepToString(o));
    }

}
class Type {
    int x, y;
    Type(int y, int x) { this.y = y; this.x = x; }
    Type(int[] a) { this.y = a[0]; this.x = a[1]; }
}

Submission Info

Submission Time
Task C - 幅優先探索
User tochukaso
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 3342 Byte
Status WA
Exec Time 472 ms
Memory 22832 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 3
AC × 23
WA × 2
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 AC 421 ms 20784 KB
subtask0_sample02.txt AC 413 ms 20644 KB
subtask0_sample03.txt AC 451 ms 22680 KB
subtask1_01.txt WA 426 ms 21172 KB
subtask1_02.txt WA 429 ms 21180 KB
subtask1_03.txt AC 430 ms 21044 KB
subtask1_04.txt AC 469 ms 22832 KB
subtask1_05.txt AC 427 ms 21172 KB
subtask1_06.txt AC 451 ms 21732 KB
subtask1_07.txt AC 418 ms 20784 KB
subtask1_08.txt AC 421 ms 20788 KB
subtask1_09.txt AC 442 ms 21172 KB
subtask1_10.txt AC 415 ms 20912 KB
subtask1_11.txt AC 471 ms 22832 KB
subtask1_12.txt AC 440 ms 21808 KB
subtask1_13.txt AC 434 ms 21168 KB
subtask1_14.txt AC 414 ms 20792 KB
subtask1_15.txt AC 472 ms 21600 KB
subtask1_16.txt AC 428 ms 21304 KB
subtask1_17.txt AC 460 ms 22572 KB
subtask1_18.txt AC 444 ms 21688 KB
subtask1_19.txt AC 429 ms 21172 KB
subtask1_20.txt AC 434 ms 21296 KB
subtask1_21.txt AC 446 ms 21736 KB
subtask1_22.txt AC 430 ms 21168 KB