結果

問題 No.20 砂漠のオアシス
ユーザー kano_townkano_town
提出日時 2014-11-19 21:13:10
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,266 bytes
コンパイル時間 3,711 ms
コンパイル使用メモリ 77,576 KB
実行使用メモリ 59,112 KB
最終ジャッジ日時 2024-04-21 06:20:17
合計ジャッジ時間 12,637 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
54,236 KB
testcase_01 AC 154 ms
53,808 KB
testcase_02 AC 156 ms
53,804 KB
testcase_03 AC 223 ms
56,440 KB
testcase_04 AC 262 ms
57,492 KB
testcase_05 AC 373 ms
58,880 KB
testcase_06 AC 458 ms
58,972 KB
testcase_07 AC 1,501 ms
58,868 KB
testcase_08 AC 632 ms
59,112 KB
testcase_09 AC 1,022 ms
59,040 KB
testcase_10 AC 141 ms
53,704 KB
testcase_11 AC 138 ms
54,092 KB
testcase_12 AC 210 ms
56,460 KB
testcase_13 AC 230 ms
56,600 KB
testcase_14 AC 360 ms
58,576 KB
testcase_15 AC 266 ms
57,712 KB
testcase_16 AC 412 ms
58,492 KB
testcase_17 AC 331 ms
58,528 KB
testcase_18 WA -
testcase_19 AC 354 ms
58,748 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