結果

問題 No.1323 うしらずSwap
ユーザー kotatsugamekotatsugame
提出日時 2020-12-20 23:17:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 76,508 KB
実行使用メモリ 13,208 KB
最終ジャッジ日時 2023-10-21 11:11:46
合計ジャッジ時間 5,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 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 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 50 ms
13,180 KB
testcase_17 AC 58 ms
13,184 KB
testcase_18 AC 49 ms
13,196 KB
testcase_19 AC 51 ms
13,196 KB
testcase_20 AC 49 ms
13,180 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 52 ms
13,196 KB
testcase_27 AC 56 ms
13,184 KB
testcase_28 AC 54 ms
13,192 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 121 ms
13,148 KB
testcase_34 AC 112 ms
13,160 KB
testcase_35 AC 102 ms
13,196 KB
testcase_36 AC 93 ms
13,204 KB
testcase_37 AC 92 ms
13,196 KB
testcase_38 AC 76 ms
13,152 KB
testcase_39 AC 75 ms
13,160 KB
testcase_40 AC 79 ms
13,192 KB
testcase_41 AC 78 ms
13,208 KB
testcase_42 AC 71 ms
13,196 KB
testcase_43 AC 44 ms
13,180 KB
testcase_44 AC 48 ms
13,180 KB
testcase_45 AC 50 ms
13,200 KB
testcase_46 AC 47 ms
13,180 KB
testcase_47 AC 45 ms
13,180 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int H,W,sx,sy,gx,gy;
string s[1333];
int dist[1333][1333];
int d[5]={0,1,0,-1};
main()
{
	cin>>H>>W>>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++)dist[i][j]=1e9;
	sx--,sy--;
	gx--,gy--;
	dist[sx][sy]=0;
	queue<pair<int,int> >P;
	P.push(make_pair(sx,sy));
	while(!P.empty())
	{
		int x=P.front().first,y=P.front().second;
		P.pop();
		for(int r=0;r<4;r++)
		{
			int tx=x+d[r],ty=y+d[r+1];
			if(s[tx][ty]=='#'||dist[tx][ty]<=dist[x][y]+1)continue;
			dist[tx][ty]=dist[x][y]+1;
			P.push(make_pair(tx,ty));
		}
	}
	if(dist[gx][gy]==(int)1e9)
	{
		cout<<-1<<endl;
		return 0;
	}
	bool fn=false,two=false;
	int x=gx,y=gy;
	while(x!=sx||y!=sy)
	{
		int nx=-1,ny=-1;
		int cnt=0;
		for(int r=0;r<4;r++)
		{
			int tx=x+d[r],ty=y+d[r+1];
			if(s[tx][ty]=='#')continue;
			if(dist[tx][ty]==dist[x][y]-1)
			{
				if(nx<0)nx=tx,ny=ty;
				else two=true;
			}
			cnt++;
		}
		if((x!=gx||y!=gy)&&cnt>=3)fn=true;
		x=nx;
		y=ny;
	}
	if(two)cout<<dist[gx][gy]*2<<endl;
	else if(fn)cout<<dist[gx][gy]*2+2<<endl;
	else cout<<-1<<endl;
}
0