QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534882#9224. Express EvictiongzchenbenWA 1ms4112kbC++141.7kb2024-08-27 17:10:182024-08-27 17:10:19

Judging History

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

  • [2024-08-27 17:10:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4112kb
  • [2024-08-27 17:10:18]
  • 提交

answer

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

int id(int x, int y) {
    return x * (m + 1) + y + 1;
}

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)] = 1e9;
        }
    }
    dis[id(0, 0)] = 0;
    Q.push({ 0, id(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++) {
            scanf(" %c", &s[i][j]);
        }
    }

    for (int i = 0;i <= n;i++) {
        for (int j = 0;j < m;j++) {
            ed[id(i, j)].push_back({ id(i,j + 1), (int)(s[i][j + 1] == '#') + (int)(s[i + 1][j + 1] == '#') });
            ed[id(i, j + 1)].push_back({ id(i,j), (int)(s[i][j + 1] == '#') + (int)(s[i + 1][j + 1] == '#') });
        }
    }

    for (int i = 0;i < n;i++) {
        for (int j = 0;j <= m;j++) {
            ed[id(i, j)].push_back({ id(i + 1,j), (int)(s[i + 1][j] == '#') + (int)(s[i + 1][j + 1] == '#') });
            ed[id(i + 1, j)].push_back({ id(i,j), (int)(s[i + 1][j] == '#') + (int)(s[i + 1][j + 1] == '#') });
        }
    }

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4036kb

input:

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

output:

11

result:

ok 1 number(s): "11"

Test #3:

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

input:

35 35
....###########...#########........
##..#######################..#####.
....#######################..#####.
...#.....##################..#####.
.##......##################.....##.
.##..##..#############.....#....##.
.....##..#############......##..##.
....#....#############..##..##..##.
####.....

output:

2

result:

wrong answer 1st numbers differ - expected: '16', found: '2'