結果

問題 No.34 砂漠の行商人
ユーザー ttkkggwwttkkggww
提出日時 2022-03-30 02:16:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,698 ms / 5,000 ms
コード長 947 bytes
コンパイル時間 4,424 ms
コンパイル使用メモリ 255,344 KB
実行使用メモリ 394,368 KB
最終ジャッジ日時 2024-04-26 10:46:32
合計ジャッジ時間 31,086 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,944 KB
testcase_01 AC 56 ms
54,912 KB
testcase_02 AC 180 ms
122,368 KB
testcase_03 AC 160 ms
114,304 KB
testcase_04 AC 568 ms
236,672 KB
testcase_05 AC 733 ms
267,904 KB
testcase_06 AC 465 ms
212,864 KB
testcase_07 AC 1,003 ms
319,232 KB
testcase_08 AC 1,297 ms
366,720 KB
testcase_09 AC 1,106 ms
339,200 KB
testcase_10 AC 1,623 ms
394,112 KB
testcase_11 AC 1,649 ms
394,112 KB
testcase_12 AC 603 ms
240,512 KB
testcase_13 AC 1,698 ms
394,112 KB
testcase_14 AC 1,689 ms
394,240 KB
testcase_15 AC 657 ms
252,160 KB
testcase_16 AC 592 ms
244,224 KB
testcase_17 AC 1,051 ms
335,616 KB
testcase_18 AC 204 ms
134,144 KB
testcase_19 AC 1,510 ms
394,112 KB
testcase_20 AC 1,663 ms
394,240 KB
testcase_21 AC 1,632 ms
394,112 KB
testcase_22 AC 1,503 ms
394,112 KB
testcase_23 AC 827 ms
287,872 KB
testcase_24 AC 1,583 ms
394,368 KB
testcase_25 AC 1,047 ms
327,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n,v,sx,sy,tx,ty;
vector<vector<int>> L;

int dp[10001][100][100];
int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};

void solve(){
	dp[0][sx][sy] = v;
	for(int i = 0;i<10000;i++){
		for(int j = 0 ;j<n;j++){
			for(int k = 0;k<n;k++){
				for(int l = 0;l<4;l++){
					int nj = j+dx[l];
					int nk = k+dy[l];
					if(nj<0||nj>=n||nk<0||nk>=n)continue;
					dp[i+1][nj][nk] = max(dp[i+1][nj][nk],dp[i][j][k]-L[nj][nk]);
				}
			}
		}
	}
	for(int i = 0;i<10000;i++){
		if(dp[i][tx][ty]){
			cout<<i<<endl;
			return;
		}
	}
	cout<<-1<<endl;

}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> v >> sx >> sy >> tx >> ty;
	L = vector<vector<int>>(n,vector<int>(n));
	swap(sx,sy);
	swap(tx,ty);
	sx--;
	sy--;
	tx--;
	ty--;
	for(int i = 0 ;i< n;i++){
		for(int j = 0;j<n;j++){
			cin >> L[i][j];
		}
	}
	solve();
}
0