結果

問題 No.340 雪の足跡
ユーザー code-devocode-devo
提出日時 2016-01-30 04:00:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,455 bytes
コンパイル時間 4,357 ms
コンパイル使用メモリ 85,316 KB
実行使用メモリ 119,140 KB
最終ジャッジ日時 2023-10-21 17:45:23
合計ジャッジ時間 8,500 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,788 KB
testcase_01 AC 140 ms
57,316 KB
testcase_02 AC 130 ms
57,772 KB
testcase_03 AC 139 ms
57,320 KB
testcase_04 AC 132 ms
57,180 KB
testcase_05 WA -
testcase_06 AC 129 ms
56,556 KB
testcase_07 AC 132 ms
57,592 KB
testcase_08 AC 133 ms
57,500 KB
testcase_09 AC 140 ms
57,592 KB
testcase_10 AC 139 ms
57,732 KB
testcase_11 AC 349 ms
63,168 KB
testcase_12 AC 309 ms
61,608 KB
testcase_13 AC 371 ms
64,996 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 #

// まずTLEとなるでしょう・・・

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) {
            Set<Integer> indexesTo = map.get(point.index);
            if (indexesTo != null) {
                for (Integer indexTo : indexesTo) {
                    if (indexTo == w * h - 1) {
                        System.out.println(point.move + 1);
                        System.exit(0);
                    }
                    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