結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
|
提出日時 | 2016-12-07 14:46:13 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,152 bytes |
コンパイル時間 | 746 ms |
コンパイル使用メモリ | 110,980 KB |
実行使用メモリ | 539,876 KB |
最終ジャッジ日時 | 2024-06-12 05:22:53 |
合計ジャッジ時間 | 43,794 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 2 MLE * 8 |
ソースコード
import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; import std.container; import std.numeric; import core.bitop; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto V = s[1]; auto Sc = s[2]-1; auto Sr = s[3]-1; auto Gc = s[4]-1; auto Gr = s[5]-1; auto B = iota(N).map!(_ => readln.split.map!(to!int).array).array; auto dp = new int[][][](10000, N, N); int[] dr = [0, 0, -1, 1]; int[] dc = [-1, 1, 0, 0]; int INF = 10^^9; foreach (k; 0..10000) foreach (i; 0..N) foreach (j; 0..N) dp[k][i][j] = (i == Sr && j == Sc) ? 0 : INF; foreach (k; 1..10000) foreach (i; 0..N) foreach (j; 0..N) { if (abs(Sr-i) + abs(Sc-j) > k) continue; foreach (d; 0..4) { auto nr = i + dr[d]; auto nc = j + dc[d]; if (nr >= 0 && nr < N && nc >= 0 && nc < N) dp[k][i][j] = min(dp[k][i][j], dp[k-1][nr][nc]+B[i][j]); } } foreach (k; 0..10000) if (dp[k][Gr][Gc] < V) { k.writeln; break; } }