結果

問題 No.1638 Robot Maze
ユーザー kotatsugamekotatsugame
提出日時 2021-08-06 21:30:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 78,600 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 02:48:16
合計ジャッジ時間 2,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int H,W,U,D,R,L,P;
long K;
int sx,sy,gx,gy;
string S[100];
long dp[100][100];
main()
{
	cin>>H>>W>>U>>D>>R>>L>>K>>P>>sx>>sy>>gx>>gy;
	int dx[4]={0,1,0,-1};
	int dy[4]={1,0,-1,0};
	int dc[4]={R,D,L,U};
	sx--,sy--,gx--,gy--;
	for(int i=0;i<H;i++)cin>>S[i];
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)dp[i][j]=K+1;
	dp[sx][sy]=0;
	priority_queue<pair<long,pair<int,int> > >Q;
	Q.push(make_pair(0,make_pair(sx,sy)));
	while(!Q.empty())
	{
		long c=-Q.top().first;
		int x=Q.top().second.first,y=Q.top().second.second;
		Q.pop();
		if(dp[x][y]<c)continue;
		for(int r=0;r<4;r++)
		{
			int tx=x+dx[r],ty=y+dy[r];
			if(tx<0||ty<0||tx>=H||ty>=W||S[tx][ty]=='#')continue;
			long nc=c+dc[r];
			if(S[tx][ty]=='@')nc+=P;
			if(dp[tx][ty]>nc)
			{
				dp[tx][ty]=nc;
				Q.push(make_pair(-nc,make_pair(tx,ty)));
			}
		}
	}
	cout<<(dp[gx][gy]>K?"No":"Yes")<<endl;
}
0