結果

問題 No.20 砂漠のオアシス
ユーザー TwizzTwizz
提出日時 2017-05-22 23:25:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 160,204 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 07:07:57
合計ジャッジ時間 21,271 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 21 ms
6,944 KB
testcase_04 AC 13 ms
6,940 KB
testcase_05 AC 2,615 ms
6,940 KB
testcase_06 AC 4,437 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2,219 ms
6,940 KB
testcase_09 AC 4,416 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 11 ms
6,944 KB
testcase_13 AC 15 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 104 ms
6,940 KB
testcase_18 WA -
testcase_19 AC 218 ms
6,944 KB
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void dijkstra(int, int)’:
main.cpp:20:27: warning: overflow in conversion from ‘ll’ {aka ‘long long int’} to ‘int’ changes value from ‘10000000000’ to ‘1410065408’ [-Woverflow]
   20 |                 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[x][y] = 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[a][b])) { a = i; b = j; }
		}
		if (a == -1 && b == -1)break;
		used[a][b] = true;

		REP(i, 4) {
			if (a + dx[i] >= n || a + dx[i] < 0 || b + dy[i] >= n || b + dy[i] < 0)continue;
			d[a + dx[i]][b + dy[i]] = min(d[a + dx[i]][b + dy[i]], d[a][b] + l[a + dx[i]][b + dy[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];
	if (cost >= v) { print("NO"); return 0; }
	dijkstra(ox-1, oy-1);
	if (d[n-1][n-1] + cost <= (v - cost) * 2) { print("YES"); return 0; }
	print("NO");
	return 0;
}
0