QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560574#8230. Submissionsshabi666#Compile Error//C++142.0kb2024-09-12 16:39:072024-09-12 16:39:08

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 16:39:08]
  • 评测
  • [2024-09-12 16:39:07]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 1e3 + 5;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};

char grid[N][N];
bool vis[N][N];
int dis[N][N];
map<pair<int, int>, int> idx;

void solve() {
    memset(dis, 0x3f, sizeof dis);

    int n, m, k;
    cin >> n >> m >> k;
    int sx, sy;
    for (int i = 1; i <= k; i++) {
        int x, y;
        cin >> x >> y;
        idx[{x, y}] = i;
        if (i == 1) {
            sx = x;
            sy = y;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> grid[i][j];
        }
    }

    auto invalid = [&](int x, int y) {
        return x < 1 || x > n || y < 1 || y > m;
    }

    priority_queue<tuple<int, int, int, int>> q;
    q.emplace(0, sx, sy, k);
    while (!q.empty()) {
        auto [d, x, y, len] = q.top(); q.pop();
        if (vis[x][y])
            continue;
        for (int i = 0; i < 4; i++) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (invalid(xx, yy) || grid[xx][yy] == '#')
                continue;
            if (idx.count({xx, yy})) {
                int d = idx[{xx, yy}];
                if (dis[xx][yy] > dis[x][y] + len - d + 1) {
                    dis[xx][yy] = dis[x][y] + 1;
                    q.emplace(-dis[xx][yy], xx, yy, max(0ll, len - d));
                }
            }
            else if (dis[xx][yy] > dis[x][y] + 1) {
                dis[xx][yy] = dis[x][y] + 1;
                q.emplace(-dis[xx][yy], xx, yy, max(0ll, len - 1));
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << dis[i][j] << " ";
        }
        cout << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:40:5: error: expected ‘,’ or ‘;’ before ‘priority_queue’
   40 |     priority_queue<tuple<int, int, int, int>> q;
      |     ^~~~~~~~~~~~~~
answer.code:41:5: error: ‘q’ was not declared in this scope
   41 |     q.emplace(0, sx, sy, k);
      |     ^
answer.code:43:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   43 |         auto [d, x, y, len] = q.top(); q.pop();
      |              ^