結果

問題 No.340 雪の足跡
ユーザー htensaihtensai
提出日時 2020-05-14 12:51:08
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,870 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 76,580 KB
実行使用メモリ 115,656 KB
最終ジャッジ日時 2023-10-13 06:46:23
合計ジャッジ時間 11,782 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,124 KB
testcase_01 AC 121 ms
56,220 KB
testcase_02 WA -
testcase_03 AC 118 ms
56,368 KB
testcase_04 WA -
testcase_05 AC 123 ms
56,372 KB
testcase_06 AC 125 ms
56,392 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 120 ms
56,208 KB
testcase_10 WA -
testcase_11 AC 282 ms
60,420 KB
testcase_12 AC 252 ms
60,476 KB
testcase_13 AC 293 ms
60,636 KB
testcase_14 TLE -
testcase_15 TLE -
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 #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int size = w * h;
		ArrayList<HashSet<Integer>> graph = new ArrayList<>();
		for (int i = 0; i < size; i++) {
		    graph.add(new HashSet<>());
		}
		for (int i = 0; i < n; i++) {
		    int count = sc.nextInt();
		    int prev = sc.nextInt();
		    for (int j = 0; j < count; j++) {
		        int current = sc.nextInt();
		        int left = Math.min(prev, current);
		        int right = Math.max(prev, current);
		        if (right - left < w) {
		            for (int k = left; k < right; k++) {
		                graph.get(k).add(k + 1);
		                graph.get(k + 1).add(k);
		            }
		        } else {
		            for (int k = left; k + w <= right; k += w) {
		                graph.get(k).add(k + w);
		                graph.get(k + w).add(k);
		            }
		        }
		        prev = current;
		    }
		}
		int[] costs = new int[size];
		Arrays.fill(costs, Integer.MAX_VALUE);
		PriorityQueue<Path> queue = new PriorityQueue<>();
		queue.add(new Path(0, 0));
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    if (costs[p.idx] <= p.value) {
		        continue;
		    }
		    costs[p.idx] = p.value;
		    for (int x : graph.get(p.idx)) {
		        queue.add(new Path(x, p.value + 1));
		    }
		}
		if (costs[size - 1] == Integer.MAX_VALUE) {
		    System.out.println("Odekakedekinai");
		} else {
		    System.out.println(costs[size - 1]);
		}
	}
	
	static class Path implements Comparable<Path> {
	    int idx;
	    int value;
	    
	    public Path(int idx, int value) {
	        this.idx = idx;
	        this.value = value;
	    }
	    
	    public int compareTo(Path another) {
	        return value - another.value;
	    }
	}
}
0