結果
問題 | No.367 ナイトの転身 |
ユーザー | mamekin |
提出日時 | 2016-04-30 17:06:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 2,077 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 124,264 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 00:22:27 |
合計ジャッジ時間 | 2,329 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 29 ms
5,248 KB |
testcase_11 | AC | 37 ms
5,248 KB |
testcase_12 | AC | 10 ms
5,248 KB |
testcase_13 | AC | 9 ms
5,248 KB |
testcase_14 | AC | 18 ms
5,248 KB |
testcase_15 | AC | 3 ms
5,248 KB |
testcase_16 | AC | 18 ms
5,248 KB |
testcase_17 | AC | 4 ms
5,248 KB |
testcase_18 | AC | 5 ms
5,248 KB |
testcase_19 | AC | 5 ms
5,248 KB |
testcase_20 | AC | 3 ms
5,248 KB |
testcase_21 | AC | 6 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 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_map.h:63, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/map:61, from main.cpp:16: In constructor 'constexpr std::_Tuple_impl<_Idx, _Head>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head>&&) [with long unsigned int _Idx = 2; _Head = int]', inlined from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 1; _Head = int; _Tail = {int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:301:7, inlined from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 0; _Head = int; _Tail = {int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:301:7, inlined from 'constexpr std::tuple< <template-parameter-1-1> >::tuple(std::tuple< <template-parameter-1-1> >&&) [with _Elements = {int, int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:756:17, inlined from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {std::tuple<int, int, int>}; _Tp = std::tuple<int, int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/new_allocator.h:175:4, inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {std::tuple<int, int, int>}; _Tp = std::tuple<int, int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_traits.h:516:17, inlined from 'void std::deque<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::tuple<int, int, int>}; _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]' at /home/linuxbrew/.linuxbrew
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> using namespace std; vector<vector<int> > dy = { { 2 ,2,-2,-2, 1, 1,-1,-1}, { 1, 1,-1,-1} }; vector<vector<int> > dx = { { 1,-1, 1,-1, 2,-2, 2,-2}, { 1,-1, 1,-1} }; int main() { int h, w; cin >> h >> w; vector<string> s(h, string(w, ' ')); int sy, sx, gy, gx; for(int y=0; y<h; ++y){ for(int x=0; x<w; ++x){ cin >> s[y][x]; if(s[y][x] == 'S'){ sy = y; sx = x; } else if(s[y][x] == 'G'){ gy = y; gx = x; } } } vector<vector<vector<bool> > > check(2, vector<vector<bool> >(h, vector<bool>(w, false))); queue<tuple<int, int, int> > q; check[0][sy][sx] = true; q.push(make_tuple(0, sy, sx)); int ans = 0; while(!q.empty()){ int n = q.size(); while(--n >= 0){ int a, y, x; tie(a, y, x) = q.front(); q.pop(); if(y == gy && x == gx){ cout << ans << endl; return 0; } for(unsigned i=0; i<dy[a].size(); ++i){ int y2 = y + dy[a][i]; int x2 = x + dx[a][i]; if(!(0 <= y2 && y2 < h && 0 <= x2 && x2 < w)) continue; int a2; if(s[y2][x2] == 'R') a2 = a ^ 1; else a2 = a; if(!check[a2][y2][x2]){ check[a2][y2][x2] = true; q.push(make_tuple(a2, y2, x2)); } } } ++ ans; } cout << -1 << endl; return 0; }