結果
問題 |
No.1323 うしらずSwap
|
ユーザー |
👑 ![]() |
提出日時 | 2020-12-20 17:41:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,064 bytes |
コンパイル時間 | 1,996 ms |
コンパイル使用メモリ | 199,064 KB |
最終ジャッジ日時 | 2025-01-17 04:53:13 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 WA * 29 |
ソースコード
//#include<atcoder/all> //using namespace atcoder; #include<bits/stdc++.h> using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int H,W; int Ay,Ax,By,Bx; bool block[3<<9][3<<9]; int D[3<<9][3<<9][2]; int P[3<<9][3<<9][2]; int dx[4][2]={{-1,0},{0,-1},{1,0},{0,1}}; struct QueueNode{ int x,y,t; }; int main(){ cin>>H>>W>>Ay>>Ax>>By>>Bx; Ay--; Ax--; By--; Bx--; rep(y,H) rep(x,W) rep(t,2){ D[x][y][t]=-1; P[x][y][t]=-1; } rep(y,H) rep(x,W){ char c; cin>>c; block[x][y]=(c=='#'); } queue<QueueNode> Q; D[Ax][Ay][0]=0; Q.push({Ax,Ay,0}); while(Q.size()){ auto q = Q.front(); Q.pop(); rep(i,4){ auto nx=q; nx.x+=dx[i][0]; nx.y+=dx[i][1]; if(block[nx.x][nx.y]) continue; while(nx.t<2) if(D[nx.x][nx.y][nx.t]!=-1) nx.t++; else break; if(nx.t==2) continue; if(P[q.x][q.y][q.t]==(i^2)) continue; D[nx.x][nx.y][nx.t]=D[q.x][q.y][q.t]+1; P[nx.x][nx.y][nx.t]=i; Q.push(nx); } } if(D[Bx][By][1]==-1) cout<<-1<<endl; else cout<<(D[Bx][By][0]+D[Bx][By][1])<<endl; return 0; }