結果

問題 No.367 ナイトの転身
ユーザー t98slidert98slider
提出日時 2023-03-23 15:55:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 188,924 KB
実行使用メモリ 5,904 KB
最終ジャッジ日時 2023-10-18 19:33:45
合計ジャッジ時間 3,245 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 18 ms
5,892 KB
testcase_11 AC 24 ms
5,904 KB
testcase_12 AC 14 ms
4,540 KB
testcase_13 AC 12 ms
4,528 KB
testcase_14 AC 13 ms
4,488 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 12 ms
4,396 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/functional:54,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:71,
                 from main.cpp:1:
In constructor 'constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(_UHead&&) [with _UHead = int&; long unsigned int _Idx = 1; _Head = int]',
    inlined from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(_UHead&&, _UTail&& ...) [with _UHead = int&; _UTail = {int}; <template-parameter-2-3> = void; long unsigned int _Idx = 1; _Head = int; _Tail = {int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:292:38,
    inlined from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(_UHead&&, _UTail&& ...) [with _UHead = int&; _UTail = {int&, int}; <template-parameter-2-3> = void; long unsigned int _Idx = 0; _Head = int; _Tail = {int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:292:38,
    inlined from 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int&, int&, int}; bool _Valid = true; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = true; _Elements = {int, int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/tuple:744:54,
    inlined from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::tuple<int, int, int>; _Args = {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 = {int&, int&, int}; _Tp = std::tuple<int, int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_trait

ソースコード

diff #

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, sy, sx, gy, gx;
    cin >> h >> w;
    vector<string> A(h);
    for(int y = 0; y < h; y++){
        cin >> A[y];
        for(int x = 0; x < w; x++){
            if(A[y][x] == 'S') sy = y, sx = x;
            if(A[y][x] == 'G') gy = y, gx = x;
        }
    }
    vector<vector<pair<int,int>>> dir = {
        {{-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, 1}, {2, -1}, {-2, -1}, {-2, 1}},
        {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}
    };
    queue<tuple<int,int,int>> nxt;
    vector<vector<array<int,2>>> dp(h, vector<array<int,2>>(w, array<int,2>({1 << 30, 1 << 30})));
    dp[sy][sx][0] = 0;
    nxt.emplace(sy, sx, 0);
    while(!nxt.empty()){
        int y, x, s, dy, dx, ny, nx, ns;
        tie(y, x, s) = nxt.front();
        nxt.pop();
        for(auto &&p : dir[s]){
            tie(dy, dx) = p;
            ny = y + dy;
            nx = x + dx;
            if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            ns = s ^ (A[ny][nx] == 'R');
            if(dp[y][x][s] + 1 >= dp[ny][nx][ns]) continue;
            dp[ny][nx][ns] = dp[y][x][s] + 1;
            nxt.emplace(ny, nx, ns);
        }
    }
    int ans = min(dp[gy][gx][0], dp[gy][gx][1]);
    if(ans == (1 << 30)) ans = -1;
    cout << ans << '\n';
}
0