結果

問題 No.367 ナイトの転身
コンテスト
ユーザー h_noson
提出日時 2016-04-29 23:47:10
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,862 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 317 ms
コンパイル使用メモリ 74,088 KB
最終ジャッジ日時 2026-05-10 04:24:27
合計ジャッジ時間 964 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:25:16: error: 'make_tuple' was not declared in this scope
   25 |         q.push(make_tuple(i,j,true,0));
      |                ^~~~~~~~~~
main.cpp:5:1: note: 'std::make_tuple' is defined in header '<tuple>'; this is probably fixable by adding '#include <tuple>'
    4 | #include <queue>
  +++ |+#include <tuple>
    5 | using namespace std;
main.cpp:29:13: error: 'tie' was not declared in this scope
   29 |             tie(x,y,knight,cnt) = q.front();
      |             ^~~
main.cpp:29:13: note: 'std::tie' is defined in header '<tuple>'; this is probably fixable by adding '#include <tuple>'
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/deque:68,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/queue:68,
                 from main.cpp:4:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_deque.h: In instantiation of 'void std::deque<_Tp, _Alloc>::_M_destroy_data(iterator, iterator, const std::allocator<_CharT>&) [with _Tp = std::tuple<int, int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int, int> >; iterator = std::_Deque_base<std::tuple<int, int, int, int>, std::allocator<std::tuple<int, int, int, int> > >::iterator]':
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_deque.h:1043:24:   required from 'std::deque<_Tp, _Alloc>::~deque() [with _Tp = std::tuple<int, int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int, int> >]'
 1043 |       { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); }
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_queue.h:104:11:   required from here
  104 |     class queue
      |           ^~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_deque.h:2203:14: error: invalid use of incomplete type 'std::deque<std::tuple<int, int, int, int>

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

int main() {
    int i, j, k, l, h, w;
    bool used[2][500][500] {};
    string s[500];
    cin >> h >> w;
    rep (i,h) cin >> s[i];
    rep (i,h) rep (j,w) if (s[i][j] == 'S') {
        queue<tuple<int,int,int,int>> q;
        int d[8] = {2,1,2,-1,-2,1,-2,-1};
        used[1][i][j] = true;
        q.push(make_tuple(i,j,true,0));
        while (!q.empty()) {
            int x, y, cnt;
            bool knight;
            tie(x,y,knight,cnt) = q.front();
            q.pop();
            if (s[x][y] == 'G') {
                cout << cnt << endl;
                return 0;
            }
            knight ^= s[x][y] == 'R';
            if (knight) {
                rep (k,8) {
                    int nx = x+d[k];
                    int ny = y+d[(k+1)%8];
                    if (nx >= 0 && nx < h && ny >= 0 && ny < w && !used[knight][nx][ny]) {
                        used[knight][nx][ny] = true;
                        q.push(make_tuple(nx,ny,knight,cnt+1));
                    }
                }
            }
            else {
                for (k = -1; k <= 1; k+=2) {
                    for (l = -1; l <= 1; l+=2) {
                        int nx = x+k;
                        int ny = y+l;
                        if (nx >= 0 && nx < h && ny >= 0 && ny < w && !used[knight][nx][ny]) {
                            used[knight][nx][ny] = true;
                            q.push(make_tuple(nx,ny,knight,cnt+1));
                        }
                    }
                }
            }
        }
    }
    cout << -1 << endl;
    return 0;
}
0