結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
sio_puyo
|
| 提出日時 | 2016-04-30 00:51:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 538 ms / 2,000 ms |
| コード長 | 1,144 bytes |
| コンパイル時間 | 1,354 ms |
| コンパイル使用メモリ | 174,908 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 23:43:10 |
| 合計ジャッジ時間 | 4,010 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:16: warning: ‘answer’ may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | else cout << answer << endl;
| ^~~~~~
ソースコード
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int cost[512][512][2];
int h,w;
vector<string> fi;
int main(void)
{
cin >> h >> w;
REP(i,h) REP(j,w) REP(k,2) cost[i][j][k]=-1048576;
int dx[12]={1,1,-1,-1,1,1,2,2,-1,-1,-2,-2};
int dy[12]={1,-1,-1,1,2,-2,1,-1,2,-2,1,-1};
fi.resize(h);
REP(i,h) cin >> fi[i];
priority_queue<tuple<int,int,int,int> > dijk;
REP(i,h) REP(j,w) if(fi[i][j]=='S') dijk.push(make_tuple(0,i,j,0));
// negcos,x,y,type;
while(!dijk.empty()){
int negc,x,y,t;
tie(negc,x,y,t)=dijk.top();
dijk.pop();
if(x<0||h<=x||y<0||w<=y) continue;
if(cost[x][y][t]>=negc) continue;
cost[x][y][t]=negc;
if(fi[x][y]=='R') t=1-t;
if(t) REP(i,4) dijk.push(make_tuple(negc-1,x+dx[i],y+dy[i],t));
else REP(i,8) dijk.push(make_tuple(negc-1,x+dx[i+4],y+dy[i+4],t));
}
int answer;
REP(i,h) REP(j,w) if(fi[i][j]=='G') answer=-max(cost[i][j][0],cost[i][j][1]);
if(answer>1048000) cout << -1 << endl;
else cout << answer << endl;
return 0;
}
sio_puyo