結果

問題 No.367 ナイトの転身
ユーザー kotatsugamekotatsugame
提出日時 2020-02-11 23:53:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 76,896 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 21:30:17
合計ジャッジ時間 2,080 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 22 ms
6,676 KB
testcase_11 AC 28 ms
6,676 KB
testcase_12 AC 7 ms
6,676 KB
testcase_13 AC 7 ms
6,676 KB
testcase_14 AC 14 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 15 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 6 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int H,W;
string s[500];
int d[500][500][2];
int dx[2][8]={
	{1,2,2,1,-1,-2,-2,-1},
	{1,1,-1,-1}
};
int dy[2][8]={
	{2,1,-1,-2,-2,-1,1,2},
	{1,-1,-1,1}
};
main()
{
	cin>>H>>W;
	queue<pair<pair<int,int>,bool> >Q;
	for(int i=0;i<H;i++)
	{
		cin>>s[i];
		for(int j=0;j<W;j++)
		{
			d[i][j][0]=d[i][j][1]=1e9;
			if(s[i][j]=='S')
			{
				Q.push(make_pair(make_pair(i,j),false));
				d[i][j][0]=0;
			}
		}
	}
	while(!Q.empty())
	{
		int x=Q.front().first.first,y=Q.front().first.second;
		bool w=Q.front().second;
		Q.pop();
		int now=d[x][y][w];
		if(s[x][y]=='G')
		{
			cout<<now<<endl;
			return 0;
		}
		for(int r=0;r<(w?4:8);r++)
		{
			int tx=x+dx[w][r];
			int ty=y+dy[w][r];
			if(0<=tx&&tx<H&&0<=ty&&ty<W)
			{
				bool nw=s[tx][ty]=='R'?!w:w;
				if(d[tx][ty][nw]>now+1)
				{
					d[tx][ty][nw]=now+1;
					Q.push(make_pair(make_pair(tx,ty),nw));
				}
			}
		}
	}
	cout<<-1<<endl;
}
0