結果

問題 No.1323 うしらずSwap
ユーザー 👑 kmjpkmjp
提出日時 2020-12-20 00:21:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,941 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 215,228 KB
実行使用メモリ 53,472 KB
最終ジャッジ日時 2023-10-21 09:48:50
合計ジャッジ時間 8,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,756 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,760 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,768 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,760 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 65 ms
28,944 KB
testcase_17 AC 98 ms
28,932 KB
testcase_18 AC 65 ms
28,600 KB
testcase_19 AC 100 ms
28,968 KB
testcase_20 AC 64 ms
28,924 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 82 ms
28,832 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 206 ms
28,768 KB
testcase_34 AC 194 ms
28,752 KB
testcase_35 AC 204 ms
28,776 KB
testcase_36 AC 181 ms
28,780 KB
testcase_37 AC 177 ms
28,752 KB
testcase_38 AC 171 ms
28,748 KB
testcase_39 AC 188 ms
28,776 KB
testcase_40 AC 175 ms
28,740 KB
testcase_41 AC 174 ms
28,756 KB
testcase_42 AC 169 ms
28,764 KB
testcase_43 AC 42 ms
28,828 KB
testcase_44 AC 56 ms
28,812 KB
testcase_45 AC 62 ms
28,872 KB
testcase_46 AC 68 ms
28,832 KB
testcase_47 AC 46 ms
28,812 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 AC 7 ms
26,564 KB
testcase_60 AC 2 ms
5,780 KB
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W;
int SR,SC,GR,GC;
string S[2020];

int D[2][2020][2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>SR>>SC>>GR>>GC;
	SR--,SC--,GR--,GC--;
	FOR(y,H) cin>>S[y];
	FOR(y,H) FOR(x,W) D[0][y][x]=D[1][y][x]=1<<28;
	D[0][SR][SC]=D[1][GR][GC]=0;
	queue<int> Q;
	Q.push(SR*10000+SC);
	Q.push(100000000+GR*10000+GC);
	int dd[4]={1,0,-1,0};
	while(Q.size()) {
		int id=Q.front()/100000000;
		int cy=Q.front()/10000%10000;
		int cx=Q.front()%10000;
		Q.pop();
		FOR(i,4) {
			int ty=cy+dd[i];
			int tx=cx+dd[i^1];
			if(ty<0||ty>=H||tx<0||tx>=W) continue;
			if(S[ty][tx]=='#') continue;
			if(chmin(D[id][ty][tx],D[id][cy][cx]+1)) {
				Q.push(id*100000000+ty*10000+tx);
			}
		}
	}
	int d=D[0][GR][GC];
	int ma=1<<30;
	map<int,int> M;
	FOR(y,H) FOR(x,W) if(S[y][x]=='.') {
		
		int num=0;
		FOR(i,4) {
			int ty=y+dd[i];
			int tx=x+dd[i^1];
			if(ty<0||ty>=H||tx<0||tx>=W) continue;
			if(S[ty][tx]=='.') num++;
		}
		if(D[0][y][x]+D[1][y][x]==d) {
			M[D[0][y][x]]++;
			if(M[D[0][y][x]]==2) ma=min(ma,d*2);
			if(num>=3) ma=min(ma,d*2+2);
		}
		if(num>=3) ma=min(ma,d*2+4);
	}
	if(ma==1<<28) ma=-1;
	cout<<ma<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0