結果

問題 No.340 雪の足跡
ユーザー 37zigen37zigen
提出日時 2020-04-13 23:01:11
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,305 bytes
コンパイル時間 2,467 ms
コンパイル使用メモリ 79,304 KB
実行使用メモリ 103,048 KB
最終ジャッジ日時 2023-10-26 04:11:16
合計ジャッジ時間 28,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
57,356 KB
testcase_01 AC 139 ms
57,292 KB
testcase_02 AC 138 ms
57,300 KB
testcase_03 AC 136 ms
57,292 KB
testcase_04 AC 140 ms
57,288 KB
testcase_05 AC 136 ms
57,300 KB
testcase_06 AC 142 ms
57,292 KB
testcase_07 AC 135 ms
57,508 KB
testcase_08 WA -
testcase_09 AC 145 ms
57,284 KB
testcase_10 AC 140 ms
57,352 KB
testcase_11 AC 225 ms
60,776 KB
testcase_12 AC 204 ms
60,456 KB
testcase_13 AC 224 ms
60,532 KB
testcase_14 AC 421 ms
64,724 KB
testcase_15 AC 455 ms
64,528 KB
testcase_16 AC 393 ms
62,408 KB
testcase_17 AC 490 ms
64,656 KB
testcase_18 AC 459 ms
64,908 KB
testcase_19 AC 499 ms
64,776 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 226 ms
81,424 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 607 ms
63,100 KB
testcase_27 AC 416 ms
62,396 KB
testcase_28 AC 624 ms
64,236 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int N=sc.nextInt();
		int[][][] horizontal=new int[2][H+1][W+1];
		int[][][] vertical=new int[2][H+1][W+1];
		for (int i=0;i<N;++i) {
			int M=sc.nextInt();
			int[] B=new int[M+1];
			for (int j=0;j<M+1;++j) {
				B[j]=Integer.parseInt(sc.next()); // w+hW
			}
			for (int j=0;j<M;++j) {
				int src=B[j];
				int dst=B[j+1];
				int hs=src/W;
				int ws=src%W;
				int hd=dst/W;
				int wd=dst%W;
				if (hs==hd) {
					if (ws<wd) { 
						++horizontal[1][hs][ws];
						--horizontal[1][hd][wd];
					} else {
						--horizontal[0][hs][ws+1];
						++horizontal[0][hd][wd+1];
					}
				} else {
					if (hs<hd) {
						++vertical[1][hs][ws];
						--vertical[1][hd][wd];
					} else {
						--vertical[0][hs+1][ws];
						++vertical[0][hd+1][wd];
					}
				}
			}
		}
		for (int k=0;k<2;++k) {
			for (int i=0;i<=H;++i) {
				for (int j=0;j<=W;++j) {
					if (j+1<=W) horizontal[k][i][j+1]+=horizontal[k][i][j];
					if (i+1<=H) vertical[k][i+1][j]+=vertical[k][i][j];
				}
			}
		}
		int[][] dist=new int[H][W];
		int INF=Integer.MAX_VALUE/3;
		for (int i=0;i<H;++i) for (int j=0;j<W;++j) dist[i][j]=INF;
		dist[0][0]=0;
		Queue<Integer> que=new ArrayDeque<Integer>();
		que.add(0);
		while (!que.isEmpty()) {
			int p=que.poll();
			int h=p/W;
			int w=p%W;
			if (dist[h][w]==INF) continue;
			int[] dh= {-1,1,0,0};
			int[] dw= {0,0,-1,1};
			for (int k=0;k<4;++k) {
				int nh=h+dh[k];
				int nw=w+dw[k];
				if (nh<0||nw<0||nh>=H||nw>=W) continue;
				if (dist[nh][nw]<=dist[h][w]+1) continue;
				if ((dw[k]!=0&&(horizontal[(dw[k]+1)/2][h][w]>0||horizontal[((dw[k]+1)/2)^1][h][w+dw[k]]>0))||(dh[k]!=0&&(vertical[(dh[k]+1)/2][h][w]>0||vertical[((dh[k]+1)/2)^1][h+dh[k]][w]>0))) {
					dist[nh][nw]=dist[h][w]+1;
					que.add(nw+nh*W);
				}
			}
		}
		pw.println(dist[H-1][W-1]==INF?"Odekakedekinai..":dist[H-1][W-1]);
		pw.close();
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}
0