結果
問題 | No.367 ナイトの転身 |
ユーザー | okaduki |
提出日時 | 2016-04-30 00:10:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 1,995 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 182,116 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-10-11 00:19:37 |
合計ジャッジ時間 | 3,041 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In function 'constexpr const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]', inlined from 'int main()' at main.cpp:87:16: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:235:15: warning: 'gx' may be used uninitialized [-Wmaybe-uninitialized] 235 | if (__b < __a) | ~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:52:7: note: 'gx' was declared here 52 | int gx, gy; | ^~ In function 'constexpr const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]', inlined from 'int main()' at main.cpp:87:16: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:235:15: warning: 'gy' may be used uninitialized [-Wmaybe-uninitialized] 235 | if (__b < __a) | ~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:52:11: note: 'gy' was declared here 52 | int gx, gy; | ^~
ソースコード
#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; }