結果
問題 |
No.1572 XI
|
ユーザー |
![]() |
提出日時 | 2021-06-27 14:24:24 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,416 bytes |
コンパイル時間 | 28,227 ms |
コンパイル使用メモリ | 279,512 KB |
最終ジャッジ日時 | 2025-01-22 14:20:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 TLE * 17 MLE * 2 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector<vector<Edge>>; using pli=pair<ll,int>; template<class T> bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int h,w,sy,sx,gy,gx; cin>>h>>w>>sy>>sx>>gy>>gx; sy--,sx--,gy--,gx--; vector<string> A(h); rep(i,h) cin>>A[i]; Graph G(6*h*w); rep(i,h){ rep(j,w){ if(A[i][j]=='#') continue; int t=i*w+j; if(j!=w-1 && A[i][j+1]=='.'){ G[t].push_back(Edge(t+1+h*w,1)); G[t+h*w].push_back(Edge(t+1+5*h*w,1)); G[t+2*h*w].push_back(Edge(t+1+2*h*w,1)); G[t+3*h*w].push_back(Edge(t+1,1)); G[t+4*h*w].push_back(Edge(t+1+4*h*w,1)); G[t+5*h*w].push_back(Edge(t+1+3*h*w,1)); G[t+1+h*w].push_back(Edge(t,1)); G[t+1+5*h*w].push_back(Edge(t+h*w,1)); G[t+1+2*h*w].push_back(Edge(t+2*h*w,1)); G[t+1].push_back(Edge(t+3*h*w,1)); G[t+1+4*h*w].push_back(Edge(t+4*h*w,1)); G[t+1+3*h*w].push_back(Edge(t+5*h*w,1)); } if(i!=h-1 && A[i+1][j]=='.'){ G[t].push_back(Edge(t+w+4*h*w,1)); G[t+h*w].push_back(Edge(t+w+h*w,1)); G[t+2*h*w].push_back(Edge(t+w,1)); G[t+3*h*w].push_back(Edge(t+w+3*h*w,1)); G[t+4*h*w].push_back(Edge(t+w+5*h*w,1)); G[t+5*h*w].push_back(Edge(t+w+2*h*w,1)); G[t+w+4*h*w].push_back(Edge(t,1)); G[t+w+h*w].push_back(Edge(t+h*w,1)); G[t+w].push_back(Edge(t+2*h*w,1)); G[t+w+3*h*w].push_back(Edge(t+3*h*w,1)); G[t+w+5*h*w].push_back(Edge(t+4*h*w,1)); G[t+w+2*h*w].push_back(Edge(t+5*h*w,1)); } } } vector<ll> dist(6*h*w,INF); int s=sy*w+sx; dist[s]=0; priority_queue<pli,vector<pli>,greater<pli>> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } if(dist[gy*w+gx]==INF) cout<<-1<<endl; else cout<<dist[gy*w+gx]<<endl; return 0; }