結果

問題 No.424 立体迷路
ユーザー maimai
提出日時 2016-09-22 22:58:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,799 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 159,480 KB
最終ジャッジ日時 2023-08-11 02:48:54
合計ジャッジ時間 1,906 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:35:5: エラー: ‘gets’ was not declared in this scope; did you mean ‘getw’?
   35 |     gets(maze[0]);//dammy;
      |     ^~~~
      |     getw

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007

#define TIME chrono::system_clock::now
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

char maze[100][100];

int height,width;
int sx,sy,gx,gy;

int main(){
    int i,j,k,l;
    
    cin>>height>>width;
    
    cin >>sy>>sx>>gy>>gx; // (゚д゚)
    sx--;sy--;gx--;gy--;
    
    gets(maze[0]);//dammy;
    for (i=0;i<height;i++){
        gets(maze[i]);
    }
    
    queue<vector<int>> q;
    q.push(vector<int>{sy,sx});
    
    int x,y,hi;
    while(!q.empty()){
        vector<int> &v = q.front();
        x=v[1];y=v[0];hi=maze[y][x];
        q.pop();
        
        //printf("%d %d %c\n",x,y,maze[y][x]);
        
        maze[y][x]='g';
        if (y==gy && x==gx){
            cout<<"YES"<<endl;
            return 0;
        }
        
        if (0<x && maze[y][x-1]!='g' && abs(maze[y][x-1]-hi)<=1){
            q.push(vector<int>{y,x-1});
        }
        if (0<y && maze[y-1][x]!='g' && abs(maze[y-1][x]-hi)<=1){
            q.push(vector<int>{y-1,x});
        }
        if (x<width-1 && maze[y][x+1]!='g' && abs(maze[y][x+1]-hi)<=1){
            q.push(vector<int>{y,x+1});
        }
        if (y<height-1 && maze[y+1][x]!='g' && abs(maze[y+1][x]-hi)<=1){
            q.push(vector<int>{y+1,x});
        }
        
        if (1<x && maze[y][x-2]!='g' && maze[y][x-2]==hi && maze[y][x-1]<hi){
            q.push(vector<int>{y,x-2});
        }
        if (1<y && maze[y-2][x]!='g' && maze[y-2][x]==hi && maze[y-1][x]<hi){
            q.push(vector<int>{y-2,x});
        }
        if (x<width-2 && maze[y][x+2]!='g' && maze[y][x+2]==hi && maze[y][x+1]<hi){
            q.push(vector<int>{y,x+2});
        }
        if (y<height-2 && maze[y+2][x]!='g' && maze[y+2][x]==hi && maze[y+1][x]<hi){
            q.push(vector<int>{y+2,x});
        }
    }
    
    // for (y=0;y<height;y++){
    //     for (x=0;x<width;x++){
    //         putchar(maze[y][x]);
    //     }
    //     cout<<endl;
    // }

    cout<<"NO"<<endl;

    return 0;
}
0