結果

問題 No.367 ナイトの転身
ユーザー itezpaceitezpace
提出日時 2016-04-30 12:22:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 174,792 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 08:06:09
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,948 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 348 ms
6,940 KB
testcase_11 AC 538 ms
6,940 KB
testcase_12 AC 226 ms
6,944 KB
testcase_13 AC 208 ms
6,940 KB
testcase_14 AC 209 ms
6,944 KB
testcase_15 AC 9 ms
6,940 KB
testcase_16 AC 185 ms
6,940 KB
testcase_17 AC 22 ms
6,940 KB
testcase_18 AC 32 ms
6,940 KB
testcase_19 AC 58 ms
6,940 KB
testcase_20 AC 27 ms
6,940 KB
testcase_21 AC 55 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 5 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int f[512][512][2];
int h, w, c, x, y, t, a;

vector<string> s;
priority_queue<tuple<int,int,int,int>> q;

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


int main(void)
{
  cin >> h >> w;

  REP(i,h) REP(j,w) REP(k,2) f[i][j][k]=-1048576;

  s.resize(h);

  REP(i,h) cin >> s[i];

  REP(i,h) REP(j,w) if(s[i][j]== 'S') q.push(make_tuple(0,i,j,0));

  while(!q.empty()){
    tie(c,x,y,t)=q.top();
    q.pop();

    if(x<0||h<=x||y<0||w<=y) continue;
    if(f[x][y][t]>=c) continue;

    f[x][y][t]=c;

    if(s[x][y]== 'R') t=1-t;
    if(t) REP(i,4) q.push(make_tuple(c-1,x+dx[i],y+dy[i],t));
    else REP(i,8) q.push(make_tuple(c-1,x+dx[i+4],y+dy[i+4],t));
  }

  REP(i,h) REP(j,w) if(s[i][j]== 'G') a=-max(f[i][j][0],f[i][j][1]);

  if(a>1048000) cout << -1 << endl;
  else cout << a << endl;

  return 0;
}
0