結果

問題 No.323 yuki国
ユーザー ぴろずぴろず
提出日時 2015-12-15 20:33:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 335 ms / 5,000 ms
コード長 1,441 bytes
コンパイル時間 3,844 ms
コンパイル使用メモリ 75,100 KB
実行使用メモリ 62,420 KB
最終ジャッジ日時 2023-09-10 21:10:29
合計ジャッジ時間 11,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,520 KB
testcase_01 AC 128 ms
55,532 KB
testcase_02 AC 130 ms
55,964 KB
testcase_03 AC 134 ms
55,668 KB
testcase_04 AC 129 ms
55,288 KB
testcase_05 AC 134 ms
57,312 KB
testcase_06 AC 130 ms
55,640 KB
testcase_07 AC 129 ms
55,604 KB
testcase_08 AC 273 ms
60,472 KB
testcase_09 AC 264 ms
60,356 KB
testcase_10 AC 132 ms
55,316 KB
testcase_11 AC 134 ms
55,868 KB
testcase_12 AC 134 ms
55,524 KB
testcase_13 AC 267 ms
60,228 KB
testcase_14 AC 256 ms
62,420 KB
testcase_15 AC 260 ms
60,556 KB
testcase_16 AC 254 ms
60,148 KB
testcase_17 AC 297 ms
60,352 KB
testcase_18 AC 166 ms
55,984 KB
testcase_19 AC 221 ms
60,108 KB
testcase_20 AC 239 ms
56,564 KB
testcase_21 AC 335 ms
60,304 KB
testcase_22 AC 322 ms
60,440 KB
testcase_23 AC 311 ms
60,220 KB
testcase_24 AC 259 ms
60,460 KB
testcase_25 AC 258 ms
60,880 KB
testcase_26 AC 194 ms
58,248 KB
testcase_27 AC 198 ms
58,008 KB
testcase_28 AC 275 ms
60,692 KB
testcase_29 AC 265 ms
60,220 KB
testcase_30 AC 129 ms
55,412 KB
testcase_31 AC 132 ms
55,836 KB
testcase_32 AC 129 ms
55,456 KB
testcase_33 AC 129 ms
55,792 KB
testcase_34 AC 133 ms
55,564 KB
testcase_35 AC 130 ms
55,724 KB
testcase_36 AC 132 ms
55,400 KB
testcase_37 AC 129 ms
55,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukiguni;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int a = sc.nextInt();
		int si = sc.nextInt();
		int sj = sc.nextInt();
		int b = sc.nextInt();
		int gi = sc.nextInt();
		int gj = sc.nextInt();
		char[][] m = new char[h][];
		for(int i=0;i<h;i++) {
			m[i] = sc.next().toCharArray();
		}
		sc.close();
		System.out.println(solve(h,w,a,b,si,sj,gi,gj,m) ? "Yes" : "No");
	}

	public static final int[] DI = {0,-1,0,1};
	public static final int[] DJ = {1,0,-1,0};
	public static boolean solve(int h,int w,int a,int b,int si,int sj,int gi,int gj,char[][] m) {
		int max = Math.max(a+h+w-1,b+2*(h+w));
		boolean[][][] used = new boolean[h][w][max+1];
		Queue<Integer> q = new ArrayDeque<>();
		q.offer(a << 16 | si << 8 | sj);
		used[si][sj][a] = true;
		while(!q.isEmpty()) {
			int p = q.poll();
			int cs = p >>> 16;
			int ci = p >>> 8 & 0xff;
			int cj = p & 0xff;
			for(int i=0;i<4;i++) {
				int ni = ci + DI[i];
				int nj = cj + DJ[i];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) {
					continue;
				}
				int ns = cs + (m[ni][nj] == '*' ? 1 : -1);
				if (ns > max || ns <= 0 || used[ni][nj][ns]) {
					continue;
				}
				used[ni][nj][ns] = true;
				q.offer(ns << 16 | ni << 8 | nj);
			}
		}
		return used[gi][gj][b];
	}

}
0