結果

問題 No.34 砂漠の行商人
ユーザー hogeover30hogeover30
提出日時 2015-03-02 04:55:55
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,014 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 62,032 KB
最終ジャッジ日時 2024-11-14 19:00:34
合計ジャッジ時間 1,085 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:13: error: ‘tie’ was not declared in this scope
   21 |             tie(t, p, y, x)=q.front(); q.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>::_M_destroy_data(std::deque<_Tp, _Alloc>::iterator, std::deque<_Tp, _Alloc>::iterator, const std::allocator<_CharT>&) [with _Tp = std::tuple<int, int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int, int> >; std::deque<_Tp, _Alloc>::iterator = std::_Deque_base<std::tuple<int, int, int, int>, std::allocator<std::tuple<int, int, int, int> > >::iterator]’:
/usr/include/c++/11/bits/stl_deque.h:1007: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> >]’
/usr/include/c++/11/bits/stl_queue.h:96:11:   required from here
/usr/include/c++/11/bits/stl_deque.h:2048:14: error: invalid use of incomplete type ‘std::deque<std::tuple<int, int, int, int>, std::allocator<std::tuple<int, int, int, int> > >::value_type’ {aka ‘class std::tuple<int, int, int, int>’}
 2048 |         if (!__has_trivial_destructor(value_type))
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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/t

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int dx[]={-1, 0, 1, 0}, dy[]={0, -1, 0, 1};
int main()
{
    int n, v, sx, sy, gx, gy;
    while (cin>>n>>v>>sx>>sy>>gx>>gy) {
        vector<vector<int>> L(n, vector<int>(n));
        for(auto& l: L) for(int& w: l) cin>>w;

        queue<tuple<int, int, int, int>> q;
        vector<vector<int>> a(n, vector<int>(n, v));
        --sx, --sy, --gx, --gy;
        q.emplace(0, 0, sy, sx);
        a[sy][sx]=L[sy][sx];
        int res=-1;
        while (q.size()) {
            int t, p, y, x;
            tie(t, p, y, x)=q.front(); q.pop();
            if (x==gx and y==gy) { res=t; break; }
            for(int i=0;i<4;++i) {
                int nx=x+dx[i], ny=y+dy[i];
                if (nx<0 or nx>=n or ny<0 or ny>=n) continue;
                if (p+L[ny][nx]>=a[ny][nx]) continue;
                a[ny][nx]=p+L[ny][nx];
                q.emplace(t+1, p+L[ny][nx], ny, nx);
            }
        }
        cout<<res<<endl;
    }
}

0