結果

問題 No.367 ナイトの転身
ユーザー okadukiokaduki
提出日時 2016-04-30 00:10:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,995 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 180,036 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2023-08-01 08:11:05
合計ジャッジ時間 3,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,428 KB
testcase_01 AC 3 ms
5,468 KB
testcase_02 AC 3 ms
5,384 KB
testcase_03 AC 3 ms
5,380 KB
testcase_04 AC 3 ms
5,428 KB
testcase_05 AC 3 ms
5,480 KB
testcase_06 AC 3 ms
5,400 KB
testcase_07 AC 3 ms
5,456 KB
testcase_08 AC 3 ms
5,480 KB
testcase_09 AC 3 ms
5,536 KB
testcase_10 AC 18 ms
5,888 KB
testcase_11 AC 24 ms
5,740 KB
testcase_12 AC 22 ms
5,588 KB
testcase_13 AC 14 ms
5,536 KB
testcase_14 AC 19 ms
5,532 KB
testcase_15 AC 4 ms
5,420 KB
testcase_16 AC 19 ms
5,520 KB
testcase_17 AC 5 ms
5,428 KB
testcase_18 AC 6 ms
5,704 KB
testcase_19 AC 7 ms
5,424 KB
testcase_20 AC 4 ms
5,460 KB
testcase_21 AC 8 ms
5,428 KB
testcase_22 AC 3 ms
5,428 KB
testcase_23 AC 4 ms
5,388 KB
testcase_24 AC 3 ms
5,496 KB
testcase_25 AC 3 ms
5,436 KB
testcase_26 AC 3 ms
5,432 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/string:50,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/locale_classes.h:40,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/ios_base.h:41,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ios:42,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:1:
関数 ‘constexpr const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]’ 内,
    inlined from ‘int main()’ at main.cpp:87:16:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:235:15: 警告: ‘gx’ may be used uninitialized [-Wmaybe-uninitialized]
  235 |       if (__b < __a)
      |           ~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:52:7: 備考: ‘gx’ はここで定義されています
   52 |   int gx, gy;
      |       ^~
関数 ‘constexpr const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]’ 内,
    inlined from ‘int main()’ at main.cpp:87:16:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:235:15: 警告: ‘gy’ may be used uninitialized [-Wmaybe-uninitialized]
  235 |       if (__b < __a)
      |           ~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:52:11: 備考: ‘gy’ はここで定義されています
   52 |   int gx, gy;
      |           ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#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)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

VVI dx, dy;
int dp[510][510][2];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  dx.push_back({1,2,2,1,-1,-2,-2,-1});
  dx.push_back({1,1,-1,-1});
  dy.push_back({-2,-1,1,2,2,1,-1,-2});
  dy.push_back({-1,1,1,-1});

  int H, W; cin >> H >> W;
  VS vs(H);
  REP(i,H) cin >> vs[i];
  fill((int*)dp, (int*)dp+510*510*2, INF);

  queue<tuple<int,int,int>> q;
  int gx, gy;
  REP(y,H) REP(x,W)
	if(vs[y][x] == 'S'){
	  dp[y][x][0] = 0;
	  q.push(make_tuple(x,y,0));
	}
	else if(vs[y][x] == 'G')
	  gx = x, gy = y;

  while(!q.empty()){
	int x, y, t;
	tie(x,y,t) = q.front(); q.pop();
	REP(i,SZ(dx[t])){
	  int tx = x + dx[t][i];
	  int ty = y + dy[t][i];
	  if(0 <= tx && tx < W && 0 <= ty && ty < H){
		int nt = (vs[ty][tx] == 'R'? 1-t: t);
		if(dp[ty][tx][nt] == INF){
		  dp[ty][tx][nt] = dp[y][x][t] + 1;
		  q.push(make_tuple(tx,ty,nt));
		}
	  }
	}
  }
  /*
  REP(y,H){
	REP(x,W) cout << dp[y][x][0] << " ";
	cout << endl;
  }
  cout<<endl;
  REP(y,H){
	REP(x,W) cout << dp[y][x][1] << " ";
	cout << endl;
  }
  */
  int tmp = min(dp[gy][gx][0], dp[gy][gx][1]);
  cout << (tmp == INF? -1: tmp) << endl;
    
  return 0;
}
0