/ WOJ /

记录详情

Compile Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:36:91: error: wrong number of template arguments (0, should be 1)
   36 |         priority_queue<tuple<ll, int, int, int>, vector<tuple<ll, int, int, int>>, greater<>> pq;
      |                                                                                           ^
In file included from /usr/include/c++/12/string:48,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/istream:38,
                 from /usr/include/c++/12/sstream:38,
                 from /usr/include/c++/12/complex:45,
                 from /usr/include/c++/12/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:54,
                 from /in/foo.cc:1:
/usr/include/c++/12/bits/stl_function.h:393:12: note: provided for 'template<class _Tp> struct std::greater'
  393 |     struct greater : public binary_function<_Tp, _Tp, bool>
      |            ^~~~~~~
/in/foo.cc:36:92: error: template argument 3 is invalid
   36 |         priority_queue<tuple<ll, int, int, int>, vector<tuple<ll, int, int, int>>, greater<>> pq;
      |                                                                                            ^~
/in/foo.cc:39:12: error: request for member 'emplace' in 'pq', which is of non-class type 'int'
   39 |         pq.emplace(0, 0, 0, 0);
      |            ^~~~~~~
/in/foo.cc:43:20: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   43 |         while (!pq.empty()) {
      |                    ^~~~~
/in/foo.cc:44:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   44 |             auto [current_dist, i, j, dir_in] = pq.top();
      |                  ^
/in/foo.cc:44:52: error: request for member 'top' in 'pq', which is of non-class type 'int'
   44 |             auto [current_dist, i, j, dir_in] = pq.top();
      |                                                    ^~~
/in/foo.cc:45:16: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   45 |             pq.pop();
      |                ^~~
/in/foo.cc:71:28: error: request for member 'emplace' in 'pq', which is of non-class type 'int'
   71 |                         pq.emplace(new_dist, ni, nj, dir_out);
      |                            ^~~~~~~

代码

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

const int dirs[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; // 右、下、左、上

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int n, m;
        cin >> n >> m;
        vector<vector<int>> t(n, vector<int>(m));
        vector<vector<int>> d(n, vector<int>(m));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                cin >> t[i][j];
            }
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                cin >> d[i][j];
            }
        }

        if (n == 0 || m == 0) {
            cout << 0 << '\n';
            continue;
        }

        vector<vector<vector<ll>>> dist(n, vector<vector<ll>>(m, vector<ll>(4, LLONG_MAX)));
        priority_queue<tuple<ll, int, int, int>, vector<tuple<ll, int, int, int>>, greater<>> pq;

        dist[0][0][0] = 0;
        pq.emplace(0, 0, 0, 0);

        ll ans = LLONG_MAX;

        while (!pq.empty()) {
            auto [current_dist, i, j, dir_in] = pq.top();
            pq.pop();

            if (current_dist > dist[i][j][dir_in]) {
                continue;
            }

            if (i == n - 1 && j == m - 1) {
                ll cost = t[i][j];
                if (dir_in != 1) {
                    cost += d[i][j];
                }
                ans = min(ans, current_dist + cost);
                continue;
            }

            for (int dir_out = 0; dir_out < 4; ++dir_out) {
                int ni = i + dirs[dir_out][0];
                int nj = j + dirs[dir_out][1];
                if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
                    ll cost = t[i][j];
                    if (dir_in != dir_out) {
                        cost += d[i][j];
                    }
                    ll new_dist = current_dist + cost;
                    if (new_dist < dist[ni][nj][dir_out]) {
                        dist[ni][nj][dir_out] = new_dist;
                        pq.emplace(new_dist, ni, nj, dir_out);
                    }
                }
            }
        }

        cout << ans << '\n';
    }

    return 0;
}

信息

递交者
类型
递交
题目
P1000 云剪贴板
题目数据
下载
语言
C++
递交时间
2025-03-08 15:47:31
评测时间
2025-03-08 15:47:31
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes