結果

問題 No.20 砂漠のオアシス
ユーザー ty70ty70
提出日時 2015-06-18 04:29:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,468 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 95,968 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:32:47
合計ジャッジ時間 6,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,504 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 168 ms
5,504 KB
testcase_06 AC 1,349 ms
6,508 KB
testcase_07 AC 1,209 ms
6,400 KB
testcase_08 AC 723 ms
6,272 KB
testcase_09 AC 1,212 ms
6,400 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 93 ms
5,504 KB
testcase_17 AC 46 ms
5,504 KB
testcase_18 AC 70 ms
5,504 KB
testcase_19 AC 75 ms
5,504 KB
testcase_20 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P,int> PI;

const int MAX_N = 505;

const int dr[] = {-1, 0, 1, 0 };
const int dc[] = { 0, 1, 0,-1 };

int desert[MAX_N][MAX_N];
int visit[MAX_N][MAX_N];

int N, V;
bool bfs (int sr, int sc, int tr, int tc ){
	memset (visit, -1, sizeof (visit ) );

	visit[sr][sc] = 0;
	queue<PI> que;
	que.push (PI( P (sr, sc ), 0 ) );

	while (!que.empty() ){
		PI curr = que.front(); que.pop();
		int cr = curr.first.first;
		int cc = curr.first.second;
		int cv = curr.second;
		rep (k, 4 ){
			int nr = cr + dr[k];
			int nc = cc + dc[k];
			if (nr < 0 || nr >= N || nc < 0 || nc >= N ) continue;
			if (visit[nr][nc] != -1 && visit[nr][nc] <= cv + desert[cr][cc] ) continue;
			
			que.push (PI (P (nr, nc ), cv + desert[cr][cc] ) );
			visit[nr][nc] = cv + desert[cr][cc];
		} // end rep
	} // end while

	return (visit[tr][tc] < V );
}

void disp (void ){
	rep (i, N ){
		rep (j, N ){
			cerr << setw(2) << visit[i][j];
		} // end rep
		cerr << endl;
	} // end rep
	cerr << endl;
}	

int main()
{
	memset (desert, 0, sizeof (desert ) );
	ios_base::sync_with_stdio(0);
	int Ox, Oy; cin >> N >> V >> Ox >> Oy;
	Ox = (Ox ? Ox-1 : Ox );
	Oy = (Oy ? Oy-1 : Oy );

	rep (i, N ) rep (j, N ) cin >> desert[i][j];

	bool res = false;

	// オアシスがなくても辿り付ける?
	res |= bfs (N-1, N-1, 0, 0 );
//	disp ();
	if (!res ){
		// オアシス辿り付ける?
		bool curr = bfs (Oy, Ox, 0, 0 );
//		disp ();
		if (curr ){
			V = 2*(V - visit[0][0] );
//			cerr << "V: " << V << endl;
			res |= bfs (N-1, N-1, Oy, Ox );
//			disp ();
		} // end if
	} // end if

	cout << (res ? "YES" : "NO" ) << endl;

	return 0;
}
0