結果
| 問題 |
No.34 砂漠の行商人
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-11-09 22:57:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,467 bytes |
| コンパイル時間 | 577 ms |
| コンパイル使用メモリ | 64,136 KB |
| 実行使用メモリ | 17,096 KB |
| 最終ジャッジ日時 | 2024-12-31 14:02:02 |
| 合計ジャッジ時間 | 157,999 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 TLE * 25 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <memory.h>
using namespace std;
typedef signed long long ll;
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
int N,V,SX,SY,GX,GY;
int Cost[101][101];
int HP[2][101][101];
void solve()
{
int i,j,k,l,r,x,y; string s;
cin>>N>>V>>SX>>SY>>GX>>GY;
FOR(y,N)
{
FOR(x,N)
{
cin>>Cost[y][x];
}
}
SX--,SY--,GX--,GY--;
HP[0][SY][SX] = V;
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
for(int i = 0; i < 10001;i++)
{
int current = i % 2;
int next = (i+1) % 2;
ZERO(HP[next]);
FOR(y, N)
{
FOR(x, N)
{
if(HP[current][y][x] > 0)
{
FOR(i,4)
{
int nextX = x + dx[i];
int nextY = y + dy[i];
if(nextX < 0 || nextY < 0 || nextX >=N || nextY >= N)
{
continue;
}
int nextHP = HP[current][y][x] - Cost[nextY][nextX];
if(nextHP <= 0)
{
continue;
}
HP[next][nextY][nextX] = max(HP[next][nextY][nextX], nextHP);
}
}
}
}
if(HP[next][GY][GX] > 0)
{
printf("%d\n", i+1);
return;
}
}
printf("-1\n");
return;
}
int main()
{
solve();
return 0;
}
nanophoto12