結果

問題 No.20 砂漠のオアシス
ユーザー 👑 kmjpkmjp
提出日時 2014-11-01 11:36:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,520 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 165,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:17:51
合計ジャッジ時間 1,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 14 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 14 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,V,OX,OY;
int L[201][201];
int H[201][201][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>V>>OX>>OY;
	OX--,OY--;
	FOR(y,N) FOR(x,N) cin>>L[y][x];
	MINUS(H);
	H[0][0][1]=V;
	priority_queue<pair<int,int> > Q;
	Q.push(make_pair(V,1000000));
	while(Q.size()) {
		int k=Q.top().second;
		Q.pop();
		int cx=k%1000,cy=k/1000%1000,cz=k/1000000;
		
		FOR(i,4) {
			int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
			int tx=cx+dx[i],ty=cy+dy[i];
			if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
			x=H[cy][cx][cz]-L[ty][tx];
			if(x<=0) continue;
			if(H[ty][tx][cz]<x) {
				H[ty][tx][cz]=x;
				Q.push(make_pair(x,cz*1000000+ty*1000+tx));
			}
			if(ty==OY && tx==OX && cz && H[ty][tx][0]<x*2) {
				H[ty][tx][0]=x*2;
				Q.push(make_pair(x*2,ty*1000+tx));
			}
		}
	}
	
	if(H[N-1][N-1][0]>=0 || H[N-1][N-1][1]>=0) _P("YES\n");
	else _P("NO\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0