結果

問題 No.20 砂漠のオアシス
ユーザー TwizzTwizz
提出日時 2017-05-22 23:50:24
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,172 bytes
コンパイル時間 1,276 ms
コンパイル使用メモリ 144,884 KB
実行使用メモリ 11,912 KB
最終ジャッジ日時 2023-08-03 08:19:32
合計ジャッジ時間 13,805 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void dijkstra(int, int)’:
main.cpp:20:13: warning: overflow in conversion from ‘ll’ {aka ‘long long int’} to ‘int’ changes value from ‘10000000000’ to ‘1410065408’ [-Woverflow]
   d[i][j] = mod;
             ^~~

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;

int n, v, ox, oy;
int l[202][202] = {};
int d[202][202] = {};
bool used[202][202] = {};
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void dijkstra(int x,int y) {
	REP(i, n)REP(j, n) {
		d[i][j] = mod;
		used[i][j] = false;
	}
	d[y][x] = 0;

	while (true) {
		int a = -1, b = -1;
		REP(i,n)REP(j,n){
			if (!used[i][j] && ((a == -1 && b == -1) || d[i][j] < d[b][a])) { a = i; b = j; }
		}
		if (a == -1 && b == -1)break;
		used[b][a] = true;

		REP(i, 4) {
			if (a + dx[i] >= n || a + dx[i] < 0 || b + dy[i] >= n || b + dy[i] < 0)continue;
			d[b + dy[i]][a + dx[i]] = min(d[b + dy[i]][a + dx[i]], d[b][a] + l[b + dy[i]][a + dx[i]]);
		}
	}
}

int main() {
	cin >> n >> v >> ox >> oy;
	REP(i, n)REP(j, n) { cin >> l[i][j]; }
	dijkstra(0, 0);
	if (d[n-1][n-1] < v) { print("YES"); return 0; }
	int cost = d[ox-1][oy-1];
	dijkstra(ox-1, oy-1);
	if (d[n-1][n-1] < (v - cost) * 2) { print("YES"); return 0; }
	print("NO");
	return 0;
}
0