結果

問題 No.20 砂漠のオアシス
ユーザー kano_townkano_town
提出日時 2014-11-19 21:13:10
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,266 bytes
コンパイル時間 8,122 ms
コンパイル使用メモリ 79,156 KB
実行使用メモリ 52,560 KB
最終ジャッジ日時 2023-08-03 07:22:14
合計ジャッジ時間 13,027 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
39,228 KB
testcase_01 AC 121 ms
39,732 KB
testcase_02 AC 124 ms
39,780 KB
testcase_03 AC 193 ms
42,892 KB
testcase_04 AC 228 ms
42,740 KB
testcase_05 AC 336 ms
46,932 KB
testcase_06 AC 360 ms
46,948 KB
testcase_07 AC 1,308 ms
47,368 KB
testcase_08 AC 539 ms
52,560 KB
testcase_09 AC 890 ms
46,980 KB
testcase_10 AC 108 ms
39,828 KB
testcase_11 AC 114 ms
39,356 KB
testcase_12 AC 187 ms
41,932 KB
testcase_13 AC 202 ms
41,884 KB
testcase_14 AC 318 ms
44,936 KB
testcase_15 AC 304 ms
44,172 KB
testcase_16 AC 409 ms
45,948 KB
testcase_17 AC 313 ms
45,460 KB
testcase_18 WA -
testcase_19 AC 346 ms
45,724 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder20 {

	int N, V, Ox, Oy;
	int[][] L;
	int[][][] dp;
	int[] dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
	String res = "NO";

	public static void main(String[] args) {
		Yukicoder20 yuki = new Yukicoder20();
	}

	public Yukicoder20() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		V = sc.nextInt();
		Ox = sc.nextInt();
		Oy = sc.nextInt();
		L = new int[N][N];
		dp = new int[N][N][2];

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				L[j][i] = sc.nextInt();
				dp[i][j][0] = -1;
				dp[i][j][1] = -1;
			}
		}

		search(0, 0, V - L[0][0], 0);

		System.out.println(res);
	}

	public void search(int nowX, int nowY, int nowV, int oasis) {
		int check = oasis;

		if (nowV <= 0) return;
		if (nowX == Ox - 1 && nowY == Oy - 1 && oasis == 0) {
			nowV *= 2;
			check = 1;
		}
		if (nowV <= dp[nowX][nowY][oasis]) return;
		if (nowX == N - 1 && nowY == N - 1) res = "YES";
		
		dp[nowX][nowY][check] = nowV;

		for (int i = 0; i < 4; i++) {
			int nextX = nowX + dx[i];
			int nextY = nowY + dy[i];
			if (nextX >= 0 && nextX < N && nextY >= 0 && nextY < N) {
				search(nextX, nextY, nowV - L[nextX][nextY], check);
			}
		}
	}
}
0