結果

問題 No.20 砂漠のオアシス
ユーザー IL_mstaIL_msta
提出日時 2015-07-15 20:42:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 2,932 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 94,148 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 07:42:14
合計ジャッジ時間 1,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 23 ms
4,376 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 20 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 4 ms
4,384 KB
testcase_18 AC 5 ms
4,384 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:122:7: warning: ‘py’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    ny = py + dy[i];
    ~~~^~~~~~~~~~~~
main.cpp:123:7: warning: ‘px’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    nx = px + dx[i];
    ~~~^~~~~~~~~~~~

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
const int V = 160000,INF = 1<<28;
int dist[200][200];
bool use[200][200];
int dist2[200][200];
bool use2[200][200];

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(10);//
	int N,V,Ox,Oy;
	cin>>N>>V>>Ox>>Oy;
	--Ox;
	--Oy;
	int L[200][200];
	rep(i,N)rep(j,N){
		cin>>L[i][j];//y,x
	}
	int dx[4] = { 1, 0,-1, 0};
	int dy[4] = { 0, 1, 0,-1};
	int px,py,nx,ny,atV;

	rep(i,200)rep(j,200){
		dist[i][j] = INF;
		dist2[i][j] = INF;
	}
	
	//priority_queue<PII, vector<PII>,greater<PII> > q;
	priority_queue<PII, vector<PII>,greater<PII> > q[5];
	PII temp;

	//q.push( PII(0,0) );
	q[0].push( PII(0,0) );
	
	while( !q[0].empty() || !q[1].empty() || !q[2].empty() || !q[3].empty() || !q[4].empty() )
	//while( !q.empty() )
	{
		rep(i,5){
			if( q[i].empty() == true) continue;
			temp = q[i].top();q[i].pop();
			py = (temp.second/N);
			px = (temp.second%N);
			break;
		}
		if( use[py][px] == true) continue;
		use[py][px] = true;
		dist[py][px] = temp.first;
		if(temp.first >= V) break;
		if(use[N-1][N-1] == true && (Ox==-1 || use[Oy][Ox]==true)) break;
		rep(i,4){
			ny = py + dy[i];
			nx = px + dx[i];
			if(0 <= ny && ny < N && 0 <= nx && nx < N && use[ny][nx] == false){
				atV = temp.first + L[ny][nx];
				q[atV/128].push( PII( atV, ny*N+nx) );
			}
		}
	}

	if(dist[N-1][N-1] < V){
		P("YES");
		return 0;
	}

	if( (Ox != -1 || Oy != -1) && dist[Oy][Ox] < V)
	{
	
	//rep(i,N)rep(j,N)use[i][j] = false;
	//priority_queue<PII, vector<PII>,greater<PII> > q2[5];
	priority_queue<PII, vector<PII>,greater<PII> > q2[5];
	q2[0].push( PII( 0, Oy*N+Ox) );
	//while( !q2.empty() )
	while( !q2[0].empty() || !q2[1].empty() || !q2[2].empty() || !q2[3].empty() || !q2[4].empty() )
	{
		rep(i,5){
			if( q2[i].empty() == true) continue;
			temp = q2[i].top();q2[i].pop();
			py = (temp.second/N);
			px = (temp.second%N);
			break;
		}
		if( use2[py][px] == true) continue;
		use2[py][px] = true;
		dist2[py][px] = temp.first;
		if( temp.first >= (V-dist[Oy][Ox])*2 ){
			break;
		}
		if(use2[N-1][N-1]==true){
			break;
		}
		rep(i,4){
			ny = py + dy[i];
			nx = px + dx[i];
			if(0 <= ny && ny < N && 0 <= nx && nx < N && use2[ny][nx] == false){
				atV = temp.first + L[ny][nx];
				q2[atV/200].push( PII( atV, ny*N+nx) );
			}
		}
	}
		if( dist[Oy][Ox] < V && dist2[N-1][N-1] < (V-dist[Oy][Ox])*2 ){
			P("YES");
			return 0;
		}
	}

	P("NO");
    return 0;
}
0