結果

問題 No.367 ナイトの転身
ユーザー maimai
提出日時 2016-07-15 21:42:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,557 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 156,216 KB
最終ジャッジ日時 2024-04-23 01:58:31
合計ジャッジ時間 1,803 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:41:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
   41 |         gets(maze[i]);
      |         ^~~~
      |         getw

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

#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

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

#define qmax 10000
int _qu[qmax][4];
int _quf=0,_qub=0;

int w,h;
char maze[505][505];
int dp[505][505][2];

int movePatternX[2][9]={{-2,-2,-1,-1, 1, 1, 2, 2,0},{-1,-1, 1, 1, 0, 0, 0, 0,0}};
int movePatternY[2][9]={{-1, 1,-2, 2,-2, 2,-1, 1,0},{-1, 1,-1, 1, 0, 0, 0, 0,0}};

inline bool inmap(int x,int y){
    return 0<=x && x<w && 0<=y && y<h;
}

int main(){
    int i,j,k,l;
    int m,n;
    
    int sx=-1,sy;
    
    cin>>h>>w;cin.ignore();
    
    for (i=0;i<h;i++){
        gets(maze[i]);
        if (sx<0)
            for (j=0;j<w;j++){
                if (maze[i][j]=='S'){
                    sx=j;sy=i;
                    break;
                }
            }
    }
    
    //queue<vector<int>> q;
    //q.push(vector<int>{0,sx,sy,0});
    _qu[_quf][1]=sx;
    _qu[_quf][2]=sy;
    _quf++;
    
    dp[sx][sy][0]=1;
    
    int x,y,cnt,job,tx,ty;int ddd=0;
    while (_qub!=_quf){
        //const vector<int> &qfront = q.front();
        //cnt=qfront[0]+1;x=qfront[1];y=qfront[2];job=qfront[3];
        //q.pop();
        cnt=_qu[_qub][0]+1;x=_qu[_qub][1];y=_qu[_qub][2];job=_qu[_qub][3];
        _qub=(++_qub)>=qmax ? 0 : _qub;
        
        if (maze[y][x]=='G'){
            cout<<(cnt-1)<<endl;
            return 0;
        }
        if (maze[y][x]=='R') job=!job;
        
        for (i=0;movePatternX[job][i]!=0;i++){
            tx=x+movePatternX[job][i];
            ty=y+movePatternY[job][i];
            if (inmap(tx,ty) && !dp[tx][ty][job]){
                dp[tx][ty][job]=1;
                //q.push(vector<int>{cnt,tx,ty,job});
                _qu[_quf][0]=cnt;
                _qu[_quf][1]=tx;
                _qu[_quf][2]=ty;
                _qu[_quf][3]=job;
                _quf=(++_quf)>=qmax ? 0 : _quf;
            }
        }
    }

    cout<<-1<<endl;

    return 0;
}
0