結果

問題 No.34 砂漠の行商人
ユーザー nanophoto12nanophoto12
提出日時 2014-11-09 23:17:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 322 ms / 5,000 ms
コード長 1,498 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 63,496 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-10 18:54:55
合計ジャッジ時間 2,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 322 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,500 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 92 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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--;
	ZERO(HP[0]);
	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(int k = 0;k < 4;k++)
					{
						int nextX = x + dx[k];
						int nextY = y + dy[k];
						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