結果
| 問題 |
No.2096 Rage With Our Friends
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-10-07 22:19:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,091 bytes |
| コンパイル時間 | 4,252 ms |
| コンパイル使用メモリ | 257,952 KB |
| 最終ジャッジ日時 | 2025-02-07 23:32:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 8 |
ソースコード
#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;
}
}
vector pre(N+1,vector<int>(M,0));
for(int i=1;i<N+1;i++){
rep(j,M){
if(i==N||s[i][j]=='#')pre[i][j] = pre[i-1][j];
else pre[i][j] = i;
}
}
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 = 0,yy = y-1;
xx = pre[x+1][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 = 0,yy = y+1;
xx = pre[x+1][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(yy<0||yy>=M)continue;
xx = pre[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 = min(N-1,1 + x),yy = y+k;
if(yy<0||yy>=M)continue;
xx = pre[xx][yy];
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;
}
沙耶花