結果
問題 | No.34 砂漠の行商人 |
ユーザー | kou6839 |
提出日時 | 2015-02-20 16:22:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,757 bytes |
コンパイル時間 | 3,451 ms |
コンパイル使用メモリ | 75,024 KB |
実行使用メモリ | 64,584 KB |
最終ジャッジ日時 | 2023-09-06 02:33:05 |
合計ジャッジ時間 | 10,700 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 117 ms
56,092 KB |
testcase_01 | WA | - |
testcase_02 | AC | 149 ms
56,392 KB |
testcase_03 | AC | 143 ms
56,160 KB |
testcase_04 | AC | 196 ms
58,816 KB |
testcase_05 | AC | 220 ms
59,556 KB |
testcase_06 | AC | 202 ms
57,204 KB |
testcase_07 | WA | - |
testcase_08 | AC | 249 ms
60,836 KB |
testcase_09 | AC | 247 ms
61,256 KB |
testcase_10 | AC | 251 ms
60,008 KB |
testcase_11 | AC | 260 ms
59,792 KB |
testcase_12 | AC | 190 ms
58,992 KB |
testcase_13 | AC | 275 ms
61,312 KB |
testcase_14 | AC | 282 ms
61,388 KB |
testcase_15 | AC | 193 ms
58,592 KB |
testcase_16 | AC | 198 ms
59,076 KB |
testcase_17 | AC | 203 ms
59,312 KB |
testcase_18 | AC | 178 ms
56,372 KB |
testcase_19 | AC | 262 ms
63,240 KB |
testcase_20 | AC | 257 ms
61,316 KB |
testcase_21 | WA | - |
testcase_22 | AC | 227 ms
59,556 KB |
testcase_23 | AC | 203 ms
59,376 KB |
testcase_24 | AC | 275 ms
63,124 KB |
testcase_25 | AC | 222 ms
59,708 KB |
ソースコード
import java.math.*; import java.util.*; public class Main { class pair{ int num; int cost; pair(int num,int cost){ this.num=num; this.cost=cost; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int v = sc.nextInt(); int sx = sc.nextInt()-1; int sy=sc.nextInt()-1; int gx=sc.nextInt()-1; int gy=sc.nextInt()-1; int[][] map = new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ map[i][j]=sc.nextInt(); } } int[] dx = {1,0,-1,0}; int[] dy = {0,1,0,-1}; int[][] totalcost = new int[n][n]; for(int i=0;i<n;i++) Arrays.fill(totalcost[i], 1000000); Queue<Integer> queuex = new LinkedList<Integer>(); Queue<Integer> queuey = new LinkedList<Integer>(); Queue<Integer> hosuu = new LinkedList<Integer>(); totalcost[sy][sx]=0; queuex.offer(sx); queuey.offer(sy); hosuu.offer(0); while(!queuex.isEmpty()){ int nx = queuex.poll(); int ny = queuey.poll(); int nh = hosuu.poll(); if(nx==gx && ny == gy){ System.out.println(nh); return; } for(int i=0;i<4;i++){ if(nx+dx[i]>=0 && nx+dx[i]<n && ny+dy[i]>=0 && ny+dy[i]<n &&totalcost[ny][nx]+map[ny+dy[i]][nx+dx[i]]<v&& totalcost[ny][nx]+map[ny+dy[i]][nx+dx[i]]<totalcost[ny+dy[i]][nx+dx[i]]){ queuex.offer(nx+dx[i]); queuey.offer(ny+dy[i]); hosuu.offer(nh+1); totalcost[ny+dy[i]][nx+dx[i]]=totalcost[ny][nx]+map[ny+dy[i]][nx+dx[i]]; } } } System.err.println(-1); } }