結果
問題 | No.20 砂漠のオアシス |
ユーザー |
|
提出日時 | 2014-11-19 21:13:10 |
言語 | Java (openjdk 23) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,266 bytes |
コンパイル時間 | 4,047 ms |
コンパイル使用メモリ | 77,656 KB |
実行使用メモリ | 59,352 KB |
最終ジャッジ日時 | 2024-10-13 04:59:32 |
合計ジャッジ時間 | 11,756 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 WA * 2 |
ソースコード
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); } } } }