結果

問題 No.20 砂漠のオアシス
ユーザー kotatsugamekotatsugame
提出日時 2019-10-14 04:07:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,089 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 78,992 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 11:16:34
合計ジャッジ時間 1,789 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 19 ms
4,380 KB
testcase_07 AC 19 ms
4,380 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 20 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   32 | main()
      | ^~~~
main.cpp: 関数 ‘int dijkstra(int, int, int, int)’ 内:
main.cpp:31:1: 警告: 制御が非 void 関数の終りに到達しました [-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