QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534948#9224. Express EvictiongzchenbenWA 1ms4592kbC++142.5kb2024-08-27 17:50:322024-08-27 17:50:33

Judging History

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

  • [2024-08-27 17:50:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4592kb
  • [2024-08-27 17:50:32]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int n, m;
int a[55][55];
vector<pair<int, int>> ed[10005]; // 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 2 * (x * (m + 1) + y) + flag;
}

int dis[10005];
bool vis[10005];
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(0, 0, 0)] = 0;
    Q.push({ 0, id(0, 0, 0) });
    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;
                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 = 0;
            for (int k = j + 1;k <= m;k++) {
                cnt += a[i][k] + a[i + 1][k];
                ed[id(i, j, 0)].push_back({ id(i,k,1), cnt });
                ed[id(i, k, 0)].push_back({ id(i,j,1), cnt });
            }
        }
    }

    for (int i = 0;i <= m;i++) {
        for (int j = 0;j < n;j++) {
            int cnt = 0;
            for (int k = j + 1;k <= n;k++) {
                cnt += a[k][i] + a[k][i + 1];
                ed[id(j, i, 0)].push_back({ id(k,i,1), cnt });
                ed[id(k, i, 0)].push_back({ id(j,i,1), cnt });
            }
        }
    }

    int dx[5] = { 0,1,0,-1,0 }, dy[5] = { 1,0,-1,0,1 };
    for (int i = 0;i <= n;i++) {
        for (int j = 0;j <= m;j++) {
            ed[id(i, j, 0)].push_back({ id(i,j,1), 0 });

            int cnt = a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i + 1][j + 1];
            for (int d = 0;d < 4;d++) {
                if (id(i + dx[d], j + dy[d], 1) == -1 || id(i + dx[d + 1], j + dy[d + 1], 1) == -1) continue;
                ed[id(i + dx[d], j + dy[d], 1)].push_back({ id(i + dx[d + 1], j + dy[d + 1], 0), cnt });
            }
        }
    }


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4020kb

input:

4 6
.##...
.#....
##....
....#.

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 4592kb

input:

20 30
...###########################
#..###########################
...###########################
...###########################
.#############################
...###########################
...###########################
#..###########################
...###########################
..#...............

output:

10

result:

wrong answer 1st numbers differ - expected: '11', found: '10'