QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#535044#9224. Express EvictiongzchenbenCompile Error//C++143.3kb2024-08-27 18:52:512024-08-27 18:52:52

Judging History

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

  • [2024-08-27 18:52:52]
  • 评测
  • [2024-08-27 18:52:51]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int n, m;
int a[55][55];
vector<pair<int, int>> ed[20005]; // to,val

int id(int x, int y, int flag) { // 0 : straight 1 : corner  0->1
    if (x < 0 || x > n || y < 0 || y > m) return -1;
    else return 4 * (x * (m + 1) + y) + flag;
}

vector<int> resolve(int t) {
    return { (t / 4) / (m + 1),(t / 4) % (m + 1), t % 4 };
}

void adde(int ux, int uy, int uflag, int vx, int vy, int vflag, int val) {
    ed[id(ux, uy, uflag)].push_back({ id(vx,vy,vflag), val });
    // printf("Add edge : (%d, %d, %d) -> (%d, %d, %d) : val = %d\n", ux, uy, uflag, vx, vy, vflag, val);
}

int dis[20005], From[20005];
bool vis[20005];
priority_queue<pair<int, int>> Q; // -dis, pos

void dijkstra() {
    for (int i = 0;i <= n;i++) {
        for (int j = 0;j <= m;j++) {
            dis[id(i, j, 0)] = 1e9;
            dis[id(i, j, 1)] = 1e9;
            dis[id(i, j, 2)] = 1e9;
            dis[id(i, j, 3)] = 1e9;
        }
    }

    dis[id(0, 0, 0)] = 0;
    Q.push({ 0, id(0, 0, 0) });

    dis[id(0, 0, 1)] = 0;
    Q.push({ 0, id(0, 0, 1) });

    while (!Q.empty()) {
        int cur = Q.top().second;
        Q.pop();
        if (vis[cur]) continue;
        vis[cur] = true;
        for (auto& p : ed[cur]) {
            if (dis[p.first] > dis[cur] + p.second) {
                dis[p.first] = dis[cur] + p.second;
                From[p.first] = cur;
                Q.push({ -dis[p.first], p.first });
            }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1;i <= n;i++) {
        for (int j = 1;j <= m;j++) {
            char tmp;
            scanf(" %c", &tmp);
            if (tmp == '#') a[i][j] = 1;
        }
    }

    for (int i = 0;i <= n;i++) {
        for (int j = 0;j < m;j++) {
            int cnt = a[i][j + 1] + a[i + 1][j + 1];
            adde(i, j, 0, i, j + 1, 0, cnt);
            adde(i, j + 1, 2, i, j, 2, cnt);
        }
    }


    for (int i = 0;i <= m;i++) {
        for (int j = 0;j < n;j++) {
            int cnt = a[j + 1][i] + a[j + 1][i + 1];
            adde(j, i, 1, j + 1, i, 1, cnt);
            adde(j + 1, i, 3, j, i, 3, cnt);
        }
    }

    // R = 0, D = 1, L = 2, U = 3 
    for (int i = 0;i <= n;i++) {
        for (int j = 0;j <= m;j++) {
            adde(i, j, 0, i, j, 1, a[i][j + 1] - a[i + 1][j]); adde(i, j, 3, i, j, 2, a[i][j + 1] - a[i + 1][j]);
            adde(i, j, 1, i, j, 2, a[i + 1][j + 1] - a[i][j]); adde(i, j, 0, i, j, 3, a[i + 1][j + 1] - a[i][j]);
            adde(i, j, 2, i, j, 3, a[i + 1][j] - a[i][j + 1]); adde(i, j, 1, i, j, 0, a[i + 1][j] - a[i][j + 1]);
            adde(i, j, 3, i, j, 0, a[i][j] - a[i + 1][j + 1]); adde(i, j, 2, i, j, 1, a[i][j] - a[i + 1][j + 1]);
        }
    }

    dijkstra();
    printf("%d\n", min(dis[id(n, m, 0)], dis[id(n, m, 1)]));

    int curx = n, cury = m, curf = dis[id(n, m, 0)] < dis[id(n, m, 1)] ? 0 : 1;
    vector<vector<int>> route;
    while (curx != 0 || cury != 0 || curf >= 2) {
        vector<int> pre = resolve(From[id(curx, cury, curf)]);
        // printf("Find prev : (%d, %d, %d), edge-val = %d\n", pre[0], pre[1], pre[2],
        dis[id(curx, cury, curf)] - dis[id(pre[0], pre[1], pre[2])]);
        curx = pre[0], cury = pre[1], curf = pre[2];
    }
}

Details

answer.code: In function ‘int main()’:
answer.code:104:68: error: expected ‘;’ before ‘)’ token
  104 |         dis[id(curx, cury, curf)] - dis[id(pre[0], pre[1], pre[2])]);
      |                                                                    ^
      |                                                                    ;
answer.code:60:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
answer.code:64:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |             scanf(" %c", &tmp);
      |             ~~~~~^~~~~~~~~~~~~