結果

問題 No.367 ナイトの転身
ユーザー sio_puyosio_puyo
提出日時 2016-04-30 00:51:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 614 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 176,228 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 07:59:24
合計ジャッジ時間 4,778 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,948 KB
testcase_10 AC 401 ms
6,940 KB
testcase_11 AC 614 ms
6,944 KB
testcase_12 AC 259 ms
6,944 KB
testcase_13 AC 240 ms
6,940 KB
testcase_14 AC 238 ms
6,944 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 206 ms
6,940 KB
testcase_17 AC 25 ms
6,940 KB
testcase_18 AC 35 ms
6,944 KB
testcase_19 AC 64 ms
6,940 KB
testcase_20 AC 29 ms
6,944 KB
testcase_21 AC 60 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 6 ms
6,944 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |                ^~~~~~

ソースコード

diff #

#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;

}
0