結果

問題 No.34 砂漠の行商人
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-11 10:32:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,280 ms / 5,000 ms
コード長 1,198 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 165,012 KB
実行使用メモリ 75,936 KB
最終ジャッジ日時 2023-10-21 23:02:33
合計ジャッジ時間 52,659 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 152 ms
8,060 KB
testcase_03 AC 10 ms
4,432 KB
testcase_04 AC 873 ms
14,292 KB
testcase_05 AC 1,181 ms
16,596 KB
testcase_06 AC 792 ms
23,380 KB
testcase_07 AC 2,015 ms
24,220 KB
testcase_08 AC 2,482 ms
27,272 KB
testcase_09 AC 2,145 ms
25,596 KB
testcase_10 AC 4,280 ms
75,936 KB
testcase_11 AC 1,925 ms
21,388 KB
testcase_12 AC 1,022 ms
21,744 KB
testcase_13 AC 4,009 ms
33,468 KB
testcase_14 AC 3,849 ms
33,152 KB
testcase_15 AC 1,094 ms
15,184 KB
testcase_16 AC 1,000 ms
14,728 KB
testcase_17 AC 2,641 ms
28,072 KB
testcase_18 AC 207 ms
8,032 KB
testcase_19 AC 4,099 ms
34,200 KB
testcase_20 AC 3,889 ms
32,896 KB
testcase_21 AC 123 ms
12,592 KB
testcase_22 AC 3,947 ms
44,072 KB
testcase_23 AC 1,497 ms
18,236 KB
testcase_24 AC 3,768 ms
32,196 KB
testcase_25 AC 2,031 ms
20,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<long long,long long> Pii;
typedef vector<Pii> VPii;


bool done[100][100][1802];
int L[100][100];
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

struct NODE{
	int x,y,c,h;
};
bool operator < (const NODE &a,const NODE &b){
	return a.h < b.h;
}

int main(){
	int N,V,Sx,Sy,Gx,Gy;
	cin >> N >> V >> Sx >> Sy >> Gx >> Gy;
	Sx--,Sy--;
	Gx--,Gy--;
	rep(i,N) rep(j,N) cin >> L[i][j];
	
	priority_queue<NODE> Q;
	Q.push({Sx,Sy,0,V});
	unsigned int ans = -1;
	while( Q.size() ){
		auto q = Q.top(); Q.pop();
		if( q.h <= 0 ) continue;
		if( q.c > 1800 ) continue;
		if( done[q.y][q.x][q.c] ) continue;
		else done[q.y][q.x][q.c] = true;
		if( q.y == Gy && q.x == Gx ){
			ans = min(ans,(unsigned)q.c);
			continue;
		}
		for(int i = 0 ; i < 4 ; i++){
			int tx = q.x + dx[i];
			int ty = q.y + dy[i];
			if( tx < 0 || ty < 0 || ty >= N || tx >= N ) continue;
			Q.push({tx,ty,q.c+1,q.h-L[ty][tx]});
		}
	}
	cout << (int) ans << endl;
	
}
0