結果
問題 | No.367 ナイトの転身 |
ユーザー | yuppe19 😺 |
提出日時 | 2016-06-11 16:58:12 |
言語 | C++11 (gcc 13.3.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,440 bytes |
コンパイル時間 | 570 ms |
コンパイル使用メモリ | 70,112 KB |
最終ジャッジ日時 | 2024-11-14 19:45:15 |
合計ジャッジ時間 | 971 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int nya(std::queue<std::tuple<int, int, bool, int> >)’: main.cpp:16:36: error: ‘tie’ was not declared in this scope 16 | int r, c, cnt; bool is_bishop; tie(r, c, is_bishop, cnt) = que.front(); que.pop(); | ^~~ main.cpp:4:1: note: ‘std::tie’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’? 3 | #include <queue> +++ |+#include <tuple> 4 | using namespace std; In file included from /usr/include/c++/11/deque:67, from /usr/include/c++/11/queue:60, from main.cpp:3: /usr/include/c++/11/bits/stl_deque.h: In instantiation of ‘void std::deque<_Tp, _Alloc>::pop_front() [with _Tp = std::tuple<int, int, bool, int>; _Alloc = std::allocator<std::tuple<int, int, bool, int> >]’: /usr/include/c++/11/bits/stl_queue.h:301:13: required from ‘void std::queue<_Tp, _Sequence>::pop() [with _Tp = std::tuple<int, int, bool, int>; _Sequence = std::deque<std::tuple<int, int, bool, int>, std::allocator<std::tuple<int, int, bool, int> > >]’ main.cpp:16:84: required from here /usr/include/c++/11/bits/stl_deque.h:1536:47: error: invalid use of incomplete type ‘class std::tuple<int, int, bool, int>’ 1536 | != this->_M_impl._M_start._M_last - 1) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/11/bits/move.h:57, from /usr/include/c++/11/bits/exception_ptr.h:43, from /usr/include/c++/11/exception:153, from /usr/include/c++/11/ios:39, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from main.cpp:1: /usr/include/c++/11/type_traits:45:11: note: declaration of ‘class std::tuple<int, int, bool, int>’ 45 | class tuple; | ^~~~~ In file included from /usr/include/c++/11/deque:67, from /usr/include/c++/11/queue:6
ソースコード
#include <iostream> #include <algorithm> #include <queue> using namespace std; const int inf = 987654321; int gr, gc; int R, C; vector<string> G; vector<vector<vector<bool>>> seen; const vector<vector<int>> dr = {{2, 2, 1, 1, -1, -1, -2, -2}, {1, 1, -1, -1}}, dc = {{1, -1, 2, -2, 2, -2, 1, -1}, {1, -1, 1, -1}}; int nya(queue<tuple<int, int, bool, int>> que) { while(!que.empty()) { int r, c, cnt; bool is_bishop; tie(r, c, is_bishop, cnt) = que.front(); que.pop(); if(seen[is_bishop][r][c]) { continue; } seen[is_bishop][r][c] = true; if(r == gr && c == gc) { return cnt; } for(int i=0, n=dr[is_bishop].size(); i<n; ++i) { int nr = r + dr[is_bishop][i], nc = c + dc[is_bishop][i]; if(nr < 0 || R <= nr || nc < 0 || C <= nc) { continue; } que.emplace(nr, nc, is_bishop^G[nr][nc]=='R', cnt+1); } } return inf; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> R >> C; G.assign(R, ""); for(int r=0; r<R; ++r) { cin >> G[r]; } int sr, sc; for(int r=0; r<R; ++r) { for(int c=0; c<C; ++c) { if(G[r][c] == 'S') { sr = r; sc = c; } if(G[r][c] == 'G') { gr = r; gc = c; } } } seen.assign(2, vector<vector<bool>>(R, vector<bool>(C, false))); queue<tuple<int, int, bool, int>> que; que.emplace(sr, sc, false, 0); int res = nya(que); if(res == inf) { res = -1; } cout << res << '\n'; return 0; }