結果

問題 No.34 砂漠の行商人
ユーザー 沙耶花沙耶花
提出日時 2021-10-21 15:19:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,417 ms / 5,000 ms
コード長 1,175 bytes
コンパイル時間 4,878 ms
コンパイル使用メモリ 268,508 KB
実行使用メモリ 240,472 KB
最終ジャッジ日時 2023-10-21 09:46:25
合計ジャッジ時間 43,133 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,868 KB
testcase_01 AC 3 ms
9,940 KB
testcase_02 AC 102 ms
53,356 KB
testcase_03 AC 14 ms
47,160 KB
testcase_04 AC 710 ms
121,100 KB
testcase_05 AC 883 ms
141,588 KB
testcase_06 AC 462 ms
106,752 KB
testcase_07 AC 1,404 ms
172,336 KB
testcase_08 AC 1,818 ms
201,024 KB
testcase_09 AC 1,591 ms
184,632 KB
testcase_10 AC 2,613 ms
240,464 KB
testcase_11 AC 535 ms
240,464 KB
testcase_12 AC 737 ms
125,196 KB
testcase_13 AC 3,417 ms
240,472 KB
testcase_14 AC 3,127 ms
235,576 KB
testcase_15 AC 775 ms
131,344 KB
testcase_16 AC 735 ms
127,244 KB
testcase_17 AC 1,637 ms
182,584 KB
testcase_18 AC 128 ms
59,568 KB
testcase_19 AC 2,965 ms
228,320 KB
testcase_20 AC 3,091 ms
233,024 KB
testcase_21 AC 125 ms
237,820 KB
testcase_22 AC 2,823 ms
221,540 KB
testcase_23 AC 1,181 ms
153,892 KB
testcase_24 AC 3,165 ms
228,324 KB
testcase_25 AC 1,423 ms
176,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000

int dis[101][101][6000];

int main(){
	
	int n,v,sx,sy,gx,gy;
	cin>>n>>v>>sx>>sy>>gx>>gy;
	gx--;gy--;sx--;sy--;
	swap(sx,sy);
	swap(gx,gy);
	
	vector l(n,vector<int>(n));
	rep(i,n){
		rep(j,n)cin>>l[i][j];
	}
	
	rep(i,n){
		rep(j,n){
			rep(k,6000)dis[i][j][k] = 0;
		}
	}
	
	queue<pair<pair<int,int>,int>> Q;
	Q.emplace(make_pair(sx,sy),0);
	dis[sx][sy][0] = v;
	vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
	while(Q.size()>0){
		int xx = Q.front().first.first, yy = Q.front().first.second,dd = Q.front().second;
		Q.pop();
		if(dd==5999)continue;
		rep(i,4){
			int nx = xx + dx[i];
			int ny = yy + dy[i];
			if(nx<0||nx>=n||ny<0||ny>=n)continue;
			int nd = dd+1;
			if(dis[nx][ny][nd] < dis[xx][yy][dd] - l[nx][ny]){
				dis[nx][ny][nd] = dis[xx][yy][dd] - l[nx][ny];
				Q.emplace(make_pair(nx,ny),nd);
			}
		}
	}
	
	int ans = Inf;
	rep(i,6000){
		if(dis[gx][gy][i] >= 1){
			ans = i;
			break;
		}
	}
	if(ans==Inf)ans = -1;
	cout<<ans<<endl;
	
	return 0;
}
0