結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,768 KB
testcase_01 AC 2 ms
5,768 KB
testcase_02 AC 2 ms
5,772 KB
testcase_03 AC 3 ms
5,768 KB
testcase_04 AC 2 ms
5,780 KB
testcase_05 WA -
testcase_06 AC 3 ms
5,780 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,772 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
5,768 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 64 ms
28,956 KB
testcase_17 AC 97 ms
28,944 KB
testcase_18 AC 63 ms
28,612 KB
testcase_19 AC 99 ms
28,980 KB
testcase_20 AC 63 ms
28,936 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 119 ms
40,500 KB
testcase_27 AC 194 ms
53,420 KB
testcase_28 AC 83 ms
28,844 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 204 ms
28,780 KB
testcase_34 AC 192 ms
28,764 KB
testcase_35 AC 207 ms
28,788 KB
testcase_36 AC 182 ms
28,792 KB
testcase_37 AC 176 ms
28,764 KB
testcase_38 AC 169 ms
28,760 KB
testcase_39 AC 190 ms
28,788 KB
testcase_40 AC 176 ms
28,752 KB
testcase_41 AC 171 ms
28,768 KB
testcase_42 AC 171 ms
28,776 KB
testcase_43 AC 43 ms
28,840 KB
testcase_44 AC 56 ms
28,824 KB
testcase_45 AC 61 ms
28,884 KB
testcase_46 AC 68 ms
28,844 KB
testcase_47 AC 46 ms
28,824 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,576 KB
testcase_60 AC 3 ms
5,792 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<<28;
	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