結果

問題 No.34 砂漠の行商人
ユーザー nanophoto12nanophoto12
提出日時 2014-11-09 22:57:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,467 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 63,968 KB
実行使用メモリ 7,948 KB
最終ジャッジ日時 2023-08-30 02:49:36
合計ジャッジ時間 13,013 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0