結果
問題 | No.34 砂漠の行商人 |
ユーザー | uafr_cs |
提出日時 | 2015-09-16 20:56:57 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,810 bytes |
コンパイル時間 | 2,307 ms |
コンパイル使用メモリ | 78,720 KB |
実行使用メモリ | 684,420 KB |
最終ジャッジ日時 | 2024-07-19 06:45:24 |
合計ジャッジ時間 | 18,166 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
50,304 KB |
testcase_01 | AC | 49 ms
50,564 KB |
testcase_02 | AC | 75 ms
38,340 KB |
testcase_03 | AC | 49 ms
37,116 KB |
testcase_04 | AC | 172 ms
47,728 KB |
testcase_05 | AC | 165 ms
47,680 KB |
testcase_06 | AC | 86 ms
39,140 KB |
testcase_07 | AC | 234 ms
49,132 KB |
testcase_08 | AC | 260 ms
50,852 KB |
testcase_09 | AC | 1,178 ms
426,644 KB |
testcase_10 | AC | 598 ms
475,572 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 152 ms
55,760 KB |
testcase_13 | AC | 2,562 ms
245,964 KB |
testcase_14 | AC | 2,005 ms
235,976 KB |
testcase_15 | AC | 158 ms
90,556 KB |
testcase_16 | AC | 374 ms
172,228 KB |
testcase_17 | AC | 132 ms
73,628 KB |
testcase_18 | AC | 130 ms
51,588 KB |
testcase_19 | AC | 840 ms
109,948 KB |
testcase_20 | AC | 1,134 ms
148,668 KB |
testcase_21 | AC | 114 ms
41,788 KB |
testcase_22 | AC | 203 ms
95,768 KB |
testcase_23 | AC | 210 ms
178,284 KB |
testcase_24 | AC | 1,492 ms
354,496 KB |
testcase_25 | AC | 283 ms
56,476 KB |
ソースコード
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; public class Main { public static final int[][] move_dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int V = sc.nextInt(); final int Sx = sc.nextInt() - 1; final int Sy = sc.nextInt() - 1; final int Gx = sc.nextInt() - 1; final int Gy = sc.nextInt() - 1; int[][] damage = new int[N][N]; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ damage[i][j] = sc.nextInt(); } } int[][][] min_steps = new int[N][N][V + 1]; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ Arrays.fill(min_steps[i][j], Integer.MAX_VALUE); } } LinkedList<Integer> x_queue = new LinkedList<Integer>(); LinkedList<Integer> y_queue = new LinkedList<Integer>(); LinkedList<Integer> hp_queue = new LinkedList<Integer>(); min_steps[Sy][Sx][V] = 0; x_queue.add(Sx); y_queue.add(Sy); hp_queue.add(V); while(!hp_queue.isEmpty()){ final int x = x_queue.poll(); final int y = y_queue.poll(); final int hp = hp_queue.poll(); if(x == Gx && y == Gy){ System.out.println(min_steps[y][x][hp]); return; } for(final int[] move : move_dir){ final int nx = x + move[0]; final int ny = y + move[1]; if(nx < 0 || nx >= N || ny < 0 || ny >= N){ continue; } final int next_hp = hp - damage[ny][nx]; if(next_hp <= 0){ continue; } final int next_step = min_steps[y][x][hp] + 1; if(next_step < min_steps[ny][nx][next_hp]){ min_steps[ny][nx][next_hp] = next_step; x_queue.add(nx); y_queue.add(ny); hp_queue.add(next_hp); } } } System.out.println(-1); } public static class Scanner implements Closeable { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public void close() throws IOException { br.close(); } } }