結果

問題 No.20 砂漠のオアシス
ユーザー TwizzTwizz
提出日時 2017-05-22 23:56:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,172 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 144,876 KB
実行使用メモリ 7,788 KB
最終ジャッジ日時 2023-08-03 08:20:13
合計ジャッジ時間 8,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 22 ms
4,384 KB
testcase_04 AC 14 ms
4,388 KB
testcase_05 TLE -
testcase_06 AC 4,778 ms
4,384 KB
testcase_07 AC 4,841 ms
4,384 KB
testcase_08 AC 4,857 ms
4,384 KB
testcase_09 AC 4,855 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 WA -
testcase_13 AC 17 ms
4,380 KB
testcase_14 AC 54 ms
4,384 KB
testcase_15 AC 29 ms
4,380 KB
testcase_16 AC 225 ms
4,384 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 6 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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[j][i] && ((a == -1 && b == -1) || d[j][i] < 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