結果

問題 No.1572 XI
ユーザー 👑 potato167potato167
提出日時 2021-06-27 13:45:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 2,158 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 214,760 KB
実行使用メモリ 30,980 KB
最終ジャッジ日時 2023-09-07 17:41:50
合計ジャッジ時間 8,081 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 45 ms
9,132 KB
testcase_05 AC 103 ms
16,608 KB
testcase_06 AC 128 ms
19,468 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 108 ms
17,224 KB
testcase_09 AC 51 ms
9,864 KB
testcase_10 AC 83 ms
14,000 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 38 ms
7,936 KB
testcase_13 AC 10 ms
4,460 KB
testcase_14 AC 39 ms
8,280 KB
testcase_15 AC 9 ms
4,656 KB
testcase_16 AC 31 ms
7,232 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 47 ms
9,164 KB
testcase_19 AC 112 ms
17,668 KB
testcase_20 AC 73 ms
12,484 KB
testcase_21 AC 132 ms
20,100 KB
testcase_22 AC 103 ms
16,228 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 195 ms
28,600 KB
testcase_35 AC 192 ms
28,104 KB
testcase_36 AC 197 ms
28,668 KB
testcase_37 AC 204 ms
29,640 KB
testcase_38 AC 202 ms
29,144 KB
testcase_39 AC 203 ms
29,416 KB
testcase_40 AC 188 ms
27,376 KB
testcase_41 AC 197 ms
28,664 KB
testcase_42 AC 202 ms
29,008 KB
testcase_43 AC 198 ms
28,508 KB
testcase_44 AC 214 ms
30,980 KB
testcase_45 AC 214 ms
30,772 KB
testcase_46 AC 217 ms
30,968 KB
testcase_47 AC 20 ms
30,908 KB
testcase_48 AC 215 ms
30,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}



//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	int H,W;
	cin>>H>>W;
	int s1,s2,g1,g2;
	cin>>s1>>s2>>g1>>g2;
	s1--,s2--,g1--,g2--;
	int s=s1*W+s2,g=g1*W+g2;
	int p[H][W];
	int dp[H][W][6];
	rep(i,H) rep(j,W){
		char a;
		cin>>a;
		if(a=='.') p[i][j]=1;
		else p[i][j]=0;
		rep(k,6) dp[i][j][k]=Q;
	}
	dp[s1][s2][0]=0;
	queue<tuple<int,int,int>> q;
	q.push({s1,s2,0});
	vector<vector<tuple<int,int,int>>> diff={
		{{1,0,1},{-1,0,3},{0,1,4},{0,-1,2}},
		{{1,0,5},{-1,0,0},{0,1,1},{0,-1,1}},
		{{1,0,2},{-1,0,2},{0,1,0},{0,-1,5}},
		{{1,0,0},{-1,0,5},{0,1,3},{0,-1,3}},
		{{1,0,4},{-1,0,4},{0,1,5},{0,-1,0}},
		{{1,0,3},{-1,0,1},{0,1,2},{0,-1,4}}
	};
	while (!q.empty())
	{
		int x,y,t;
		tie(x,y,t)=q.front();
		int L=dp[x][y][t];
		L++;
		q.pop();
		rep(i,4){
			int a,b,c;
			tie(a,b,c)=diff[t][i];
			int u=a+x,v=b+y;
			if(u==-1||u==H||v==-1||v==W||p[u][v]==0) continue;
			if(dp[u][v][c]==Q){
				dp[u][v][c]=L;
				q.push({u,v,c});
			}
		}
	}
	/*rep(i,H){
		rep(j,W) cout<<dp[i][j][0]<<" ";
		cout<<endl;
	}*/
	if(dp[g1][g2][0]==Q) cout<<"-1\n";
	else cout<<dp[g1][g2][0]<<"\n";
}

0