結果

問題 No.367 ナイトの転身
ユーザー mamekinmamekin
提出日時 2016-04-30 17:06:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 2,077 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 123,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 07:43:25
合計ジャッジ時間 2,439 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 26 ms
5,376 KB
testcase_11 AC 35 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:60:13: warning: 'gy' may be used uninitialized [-Wmaybe-uninitialized]
   60 |             if(y == gy && x == gx){
      |             ^~
main.cpp:33:17: note: 'gy' was declared here
   33 |     int sy, sx, gy, gx;
      |                 ^~
main.cpp:60:24: warning: 'gx' may be used uninitialized [-Wmaybe-uninitialized]
   60 |             if(y == gy && x == gx){
      |                ~~~~~~~~^~~~~~~~~~
main.cpp:33:21: note: 'gx' was declared here
   33 |     int sy, sx, gy, gx;
      |                     ^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/stl_map.h:63,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/map:63,
                 from main.cpp:16:
In constructor '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}]',
    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/13.2.0/include/c++/13/tuple:302: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/13.2.0/include/c++/13/tuple:903: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/13.2.0/include/c++/13/bits/new_allocator.h:187: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/lin

ソースコード

diff #

#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;
}
0