結果
問題 |
No.2096 Rage With Our Friends
|
ユーザー |
![]() |
提出日時 | 2022-10-07 22:13:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,986 bytes |
コンパイル時間 | 4,322 ms |
コンパイル使用メモリ | 256,988 KB |
最終ジャッジ日時 | 2025-02-07 23:29:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 WA * 8 TLE * 3 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 long long d[2005][2005]; int main(){ int N,M; cin>>N>>M; int sx,sy,gx,gy; cin>>sx>>sy>>gx>>gy; sx--,sy--,gx--,gy--; vector<string> s(N); rep(i,N)cin>>s[i]; rep(i,N){ rep(j,M){ d[i][j] = Inf64; } } using P = pair<long long,pair<int,int>>; priority_queue<P,vector<P>,greater<P>> Q; Q.emplace(0,make_pair(sx,sy)); d[sx][sy] = 0; while(Q.size()>0){ long long D = Q.top().first; int x = Q.top().second.first; int y = Q.top().second.second; Q.pop(); if(D!=d[x][y])continue; if(s[x][y]=='.'){ if(y!=0){ int xx = x+1,yy = y-1; while(xx>=N || s[xx][yy]=='#')xx--; if(s[xx][yy]=='.'){ long long DD = D; if(d[xx][yy]>DD){ d[xx][yy] = DD; Q.emplace(DD,make_pair(xx,yy)); } } } if(y!=M-1){ int xx = x+1,yy = y+1; while(xx>=N || s[xx][yy]=='#')xx--; if(s[xx][yy]=='.'){ long long DD = D; if(d[xx][yy]>DD){ d[xx][yy] = DD; Q.emplace(DD,make_pair(xx,yy)); } } } for(int k=-2;k<=2;k+=2){ int xx = 1 + x/2,yy = y+k; if(y<0||y>=M)continue; long long DD = D; if(d[xx][yy]>DD){ d[xx][yy] = DD; Q.emplace(DD,make_pair(xx,yy)); } } for(int k=-2;k<=2;k+=2){ int xx = min(N-1,1 + x),yy = y+k; if(y<0||y>=M)continue; long long DD = D+1; if(d[xx][yy]>DD){ d[xx][yy] = DD; Q.emplace(DD,make_pair(xx,yy)); } } } if(x!=0){ int xx = x-1,yy = y; long long DD = D; if(d[xx][yy]>DD){ d[xx][yy] = DD; Q.emplace(DD,make_pair(xx,yy)); } } } /* rep(i,N){ rep(j,M){ cout<<d[i][j]<<','; } cout<<endl; } */ long long ans = d[gx][gy]; if(ans==Inf64)ans = -1; cout<<ans<<endl; return 0; }