結果
| 問題 | No.367 ナイトの転身 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-15 21:31:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,132 bytes |
| 記録 | |
| コンパイル時間 | 1,549 ms |
| コンパイル使用メモリ | 162,760 KB |
| 最終ジャッジ日時 | 2024-11-14 19:46:53 |
| 合計ジャッジ時間 | 1,944 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:37:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
37 | gets(maze[i]);
| ^~~~
| getw
ソースコード
#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;}
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});
dp[sx][sy][0]=1;
int x,y,cnt,job,tx,ty;int ddd=0;
while (!q.empty()){
const vector<int> &qfront = q.front();
cnt=qfront[0]+1;x=qfront[1];y=qfront[2];job=qfront[3];
q.pop();
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});
}
}
}
cout<<-1<<endl;
return 0;
}