結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
![]() |
提出日時 | 2016-05-08 08:52:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,225 ms / 5,000 ms |
コード長 | 955 bytes |
コンパイル時間 | 515 ms |
コンパイル使用メモリ | 57,468 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 10:31:51 |
合計ジャッジ時間 | 3,421 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <algorithm> #include <iostream> using namespace std; const int DX[] = {1, 0, -1, 0}; const int DY[] = {0, 1, 0, -1}; int N, V, SX, SY, GX, GY; int L[100][100]; int dp[2][100][100]; int cur = 0, nex = 1; int main() { cin >> N >> V >> SX >> SY >> GX >> GY; SX--; SY--; GX--; GY--; for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { cin >> L[x][y]; } } dp[cur][SX][SY] = V; for (int i = 0; i < 10000; i++) { for (int x = 0; x < N; x++) { for (int y = 0; y < N; y++) { dp[nex][x][y] = 0; } } for (int x = 0; x < N; x++) { for (int y = 0; y < N; y++) { for (int d = 0; d < 4; d++) { int xx = x + DX[d], yy = y + DY[d]; if (0 <= xx && xx < N && 0 <= yy && yy < N) { dp[nex][xx][yy] = max(dp[nex][xx][yy], dp[cur][x][y] - L[xx][yy]); } } } } if (dp[nex][GX][GY] > 0) { cout << (i + 1) << endl; return 0; } cur ^= 1; nex ^= 1; } cout << -1 << endl; return 0; }