結果

問題 No.340 雪の足跡
ユーザー code-devocode-devo
提出日時 2016-01-30 04:16:10
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,431 bytes
コンパイル時間 3,472 ms
コンパイル使用メモリ 94,500 KB
実行使用メモリ 119,028 KB
最終ジャッジ日時 2023-10-21 17:45:34
合計ジャッジ時間 9,911 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
57,708 KB
testcase_01 AC 144 ms
57,324 KB
testcase_02 AC 135 ms
57,652 KB
testcase_03 AC 145 ms
57,556 KB
testcase_04 AC 140 ms
57,676 KB
testcase_05 AC 142 ms
57,616 KB
testcase_06 AC 150 ms
57,640 KB
testcase_07 AC 142 ms
57,484 KB
testcase_08 AC 142 ms
57,480 KB
testcase_09 AC 147 ms
57,840 KB
testcase_10 AC 146 ms
57,472 KB
testcase_11 AC 358 ms
62,932 KB
testcase_12 AC 320 ms
61,824 KB
testcase_13 AC 391 ms
64,956 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// とりあえず、01_small_00.txt を通す。

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String... args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int n = sc.nextInt();

        Map<Integer, Set<Integer>> map = new HashMap<>();
        while (sc.hasNextInt()) {
            int m = sc.nextInt();
            int b = sc.nextInt();
            for (int i = 0; i < m; i++) {
                int bTo = sc.nextInt();

                int offset;
                if (bTo >= b + w) {
                    offset = w;
                } else if (bTo > b) {
                    offset = 1;
                } else if (bTo <= b - w) {
                    offset = -w;
                } else {
                    offset = -1;
                }

                while (b != bTo) {
                    map.computeIfAbsent(b, x -> new HashSet());
                    map.get(b).add(b + offset);
                    map.computeIfAbsent(b + offset, x -> new HashSet());
                    map.get(b + offset).add(b);
                    b += offset;
                }
            }
        }

        Queue<Point> queue = new LinkedList<>();
        queue.add(new Point(0, 0));
        Set<Integer> visited = new HashSet<>();
        visited.add(0);

        Point point;
        while ((point = queue.poll()) != null) {
            if (point.index == w * h - 1) {
                System.out.println(point.move);
                System.exit(0);
            }

            Set<Integer> indexesTo = map.get(point.index);
            if (indexesTo != null) {
                for (Integer indexTo : indexesTo) {
                    if (!visited.contains(indexTo)) {
                        visited.add(indexTo);
                        queue.add(new Point(indexTo, point.move + 1));
                    }
                }
            }
        }

        System.out.println("Odekakedekinai..");
    }
}

class Point {

    final int index;
    final int move;

    Point(int index, int move) {
        this.index = index;
        this.move = move;
    }

    @Override
    public String toString() {
        return String.format("index: %d, move: %d", index, move);
    }
}
0