結果

問題 No.20 砂漠のオアシス
ユーザー kotatsugame
提出日時 2019-10-14 04:07:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,089 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 80,416 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-21 13:45:49
合計ジャッジ時間 1,907 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main()
      | ^~~~
main.cpp: In function 'int dijkstra(int, int, int, int)':
main.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
   31 | }
      | ^

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int d[200][200];
int N,L[200][200];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int dijkstra(int x,int y,int gx,int gy)
{
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)d[i][j]=1e9;
	d[x][y]=0;
	priority_queue<pair<int,pair<int,int> > >P;
	P.push(make_pair(0,make_pair(x,y)));
	while(!P.empty())
	{
		int c=-P.top().first;
		int nx=P.top().second.first,ny=P.top().second.second;
		P.pop();
		if(d[nx][ny]<c)continue;
		if(nx==gx&&ny==gy)return c;
		for(int r=0;r<4;r++)
		{
			int tx=nx+dx[r],ty=ny+dy[r];
			if(tx>=0&&ty>=0&&tx<N&&ty<N&&d[tx][ty]>c+L[tx][ty])
			{
				d[tx][ty]=c+L[tx][ty];
				P.push(make_pair(-d[tx][ty],make_pair(tx,ty)));
			}
		}
	}
}
main()
{
	int V,OX,OY;
	cin>>N>>V>>OX>>OY;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>L[i][j];
	if(dijkstra(0,0,N-1,N-1)<V)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else if(OX!=0&&OY!=0)
	{
		int T=dijkstra(0,0,OY-1,OX-1);
		if(T<V)
		{
			V=(V-T)*2;
			if(dijkstra(OY-1,OX-1,N-1,N-1)<V)
			{
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
}
0