結果

問題 No.424 立体迷路
ユーザー tossytossy
提出日時 2016-09-22 22:42:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 1,077 ms
コンパイル使用メモリ 97,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:44:34
合計ジャッジ時間 2,117 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600
typedef pair<int, int> P;

int main(){
  int h,w,sx,sy,gx,gy;
  cin>>h>>w>>sx>>sy>>gx>>gy;

  vector<vector<int> > f(h, vector<int>(w));
  vector<vector<bool> > visited(h, vector<bool>(w,false));

  rep(i,h){
    string s;
    cin>>s;
    rep(j,w){
      f[i][j] = s[j]-'0';
    }
  }

  const int dx[] = {0,0,-1,1}, dy[] = {1,-1,0,0};
  queue<P> q;
  q.push(mp(sx-1,sy-1));
  visited[sx-1][sy-1]=true;
  gx--;gy--;

  while(!q.empty()){
    P p=q.front(); q.pop();
    int x=p.fi, y=p.se;

    if(x==gx && y==gy){
      cout<<"YES"<<endl;
      return 0;
    }

    rep(i,4){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx>=0 && nx<h && ny>=0 && ny<w && visited[nx][ny]==false && abs(f[x][y]-f[nx][ny])<=1){
        visited[nx][ny]=true;
        q.push(mp(nx,ny));
      }
    }

    rep(i,4){
      int nx=x+2*dx[i],ny=y+2*dy[i];
      if(nx>=0 && nx<h && ny>=0 && ny<w && visited[nx][ny]==false && f[x][y]==f[nx][ny] && f[x+dx[i]][y+dy[i]]<f[x][y]){
        visited[nx][ny]=true;
        q.push(mp(nx,ny));
      }
    }
  }

  cout<<"NO"<<endl;

  return 0;
}
0