結果

問題 No.424 立体迷路
ユーザー CleyLCleyL
提出日時 2020-03-05 21:56:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 75,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 03:18:27
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
using namespace std;
struct dta{
  int x,y;
};
using ll = long long;
using P = pair<int,int>;
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
char mp[50][50];
bool lck[50][50];
int main(){
  int h,w;cin>>h>>w;
  int sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;sx--;sy--;gx--;gy--;
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      cin>>mp[i][j];
    }
  }
  queue<dta> a;
  a.push({sx,sy});
  lck[sx][sy] = true;
  while(!a.empty()){
    dta z = a.front();a.pop();
    if(z.x == gx && z.y == gy){
      cout << "YES" << endl;
      return 0;
    }
    //隣り合った高さのdistanceが1以下だったら通れる
    for(int i = 0; 4 > i; i++){
      if(0 > z.x+ar4[i].first || z.x+ar4[i].first >= h || 0 > z.y+ar4[i].second || z.y+ar4[i].second >= w)continue;
      if(!lck[z.x+ar4[i].first][z.y+ar4[i].second] && abs(mp[z.x][z.y]-mp[z.x+ar4[i].first][z.y+ar4[i].second]) < 2){
        lck[z.x+ar4[i].first][z.y+ar4[i].second] = true;
        a.push({z.x+ar4[i].first,z.y+ar4[i].second});
      }
    }
    //同じ高さの2つ先のdistanceが0以下だったら通れる
    for(int i = 0; 4 > i; i++){
      if(0 > z.x+ar4[i].first || z.x+ar4[i].first >= h || 0 > z.y+ar4[i].second || z.y+ar4[i].second >= w)continue;
      if(!lck[z.x+ar4[i].first*2][z.y+ar4[i].second*2] && abs(mp[z.x][z.y]-mp[z.x+ar4[i].first*2][z.y+ar4[i].second*2]) < 1 && mp[z.x][z.y] > mp[z.x+ar4[i].first][z.y+ar4[i].second]){
        lck[z.x+ar4[i].first*2][z.y+ar4[i].second*2] = true;
        a.push({z.x+ar4[i].first*2,z.y+ar4[i].second*2});
      }
    }
  }
  cout << "NO" << endl;
}
0