結果
問題 | No.367 ナイトの転身 |
ユーザー | btk |
提出日時 | 2016-04-29 22:53:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,433 bytes |
コンパイル時間 | 1,907 ms |
コンパイル使用メモリ | 180,692 KB |
実行使用メモリ | 6,528 KB |
最終ジャッジ日時 | 2024-10-11 00:17:15 |
合計ジャッジ時間 | 3,009 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 31 ms
6,528 KB |
testcase_11 | AC | 58 ms
6,528 KB |
testcase_12 | AC | 28 ms
5,248 KB |
testcase_13 | AC | 25 ms
5,248 KB |
testcase_14 | AC | 25 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 23 ms
5,248 KB |
testcase_17 | AC | 5 ms
5,248 KB |
testcase_18 | AC | 6 ms
5,248 KB |
testcase_19 | AC | 8 ms
5,248 KB |
testcase_20 | AC | 4 ms
5,248 KB |
testcase_21 | AC | 9 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:53:50: warning: 'gc' may be used uninitialized [-Wmaybe-uninitialized] 53 | int res = min(NB[0][gr][gc], NB[1][gr][gc]); | ^ main.cpp:23:25: note: 'gc' was declared here 23 | int sr, sc, gr, gc; | ^~ main.cpp:53:46: warning: 'gr' may be used uninitialized [-Wmaybe-uninitialized] 53 | int res = min(NB[0][gr][gc], NB[1][gr][gc]); | ^ main.cpp:23:21: note: 'gr' was declared here 23 | int sr, sc, gr, gc; | ^~ main.cpp:32:18: warning: 'sc' may be used uninitialized [-Wmaybe-uninitialized] 32 | que.push(vector<int>{0, sr, sc}); | ^~~~~~~~~~~~~~~~~~~~~~ main.cpp:23:17: note: 'sc' was declared here 23 | int sr, sc, gr, gc; | ^~ main.cpp:32:18: warning: 'sr' may be used uninitialized [-Wmaybe-uninitialized] 32 | que.push(vector<int>{0, sr, sc}); | ^~~~~~~~~~~~~~~~~~~~~~ main.cpp:23:13: note: 'sr' was declared here 23 | int sr, sc, gr, gc; | ^~
ソースコード
/* * Problem link * */ #include<bits/stdc++.h> using namespace std; bool inner(int v, int lb, int ub) { return lb <= v&&v <=ub; } struct INIT{INIT(){cin.tie(0);ios_base::sync_with_stdio(false);} }init; const int INF = (int)1e7; const int dr[2][8] = { {1,1,-1,-1,2,-2,2,-2},{ 1,1,-1,-1,1,1,-1,-1 } }; const int dc[2][8] = { {2,-2,2,-2,1,1,-1,-1},{ 1,-1,-1,1,1,-1,-1,1 } }; int main() { #ifdef INPUT_FROM_FILE ifstream cin("sample.in"); ofstream cout("sample.out"); #endif int R, C; cin >> R >> C; vector<string> S(R); for (auto& it : S)cin >> it; int sr, sc, gr, gc; for (int r = 0; r < R; r++) for (int c = 0; c < C; c++) if (S[r][c] == 'S')sr = r, sc = c; else if (S[r][c] == 'G')gr = r, gc = c; vector<vector<vector<int>>> NB(2,vector<vector<int>>(R, vector<int>(C, INF))); NB[0][sr][sc] = 0; queue<vector<int>> que; que.push(vector<int>{0, sr, sc}); while (que.empty() == false) { auto v = que.front(); que.pop(); int type = v[0]; int r = v[1]; int c = v[2]; for (int i = 0; i < 8; i++) { int nr = r + dr[type][i]; int nc = c + dc[type][i]; if (inner(nr, 0, R - 1) && inner(nc, 0, C - 1)) { int nt = type ^ (S[nr][nc] == 'R'); if (NB[nt][nr][nc]> NB[type][r][c] + 1) { NB[nt][nr][nc] = NB[type][r][c] + 1; que.push(vector<int>{nt, nr, nc}); } } } } int res = min(NB[0][gr][gc], NB[1][gr][gc]); if (res == INF)res = -1; cout << res << endl; return 0; }